aviksingha
Newbie level 1
- Joined
- Sep 16, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 25
https://www.edaboard.com/threads/143406/................... I have almost the same project as the mentioned one......& i too have the similar problem but found no solution...
My project is described below...
PIC 16F84A interface with bluetooth bee HC-06(iteadstudio.com)
Hello, I am an engineering student working on a project based on Remote car control using bluetooth for wireless communication. Below, I have described the project contents and its working in precise.
My project consists of 2 parts; the transmitter side consists of PC or LAPTOP along with a Bluetooth DONGLE and the receiver side consists of a Bluetooth UART MODULE, Microcontroller and car stuffs. So, the aim of my project is to nevigate through PC using Hyperterminal and transmit it wirelessly to the receiver Bluetooth UART module to drive the motors through microcontroller(PIC16F84A).
However i m having few doubts based on it as follows:-
1) I have seen the features of the above mentioned Bluetooth MODULE but would like to clarify whether it can be compatible with PIC16F84A microcontroller which i 'll be using as Host to control this module so as to detect remote devices and to receive data.
2) Can i directly interface my PIC to this Bluetooth MODULE at the receiver side?
3) Can i create or establish connectivity with the transmitter side USB Dongle from this receiver side Bluetooth MODULE via. PIC..?
4) Can i get an example of a command to be sent in C language via PIC to control this Bluetooth MODULE?
Thanks in advance............
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 char uart_rd; void main() { TRISA=0X00; TRISD=0X00; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize while(1){ if (UART1_Data_Ready()) { // If data is received, PORTD=0XFF; uart_rd = UART1_Read(); // read the received data, if(uart_rd=='1'){ PORTA=0X05; delay_ms(5000); PORTD=0X0F; delay_ms(1000); } else if(uart_rd=='2'){ PORTA=0X0C; delay_ms(5000); PORTD=0X0F; delay_ms(1000); } else if(uart_rd=='3'){ PORTA=0X24; delay_ms(5000); PORTD=0X0F; delay_ms(1000); } else if(uart_rd=='4'){ PORTA=0X06; delay_ms(5000); PORTD=0X0F; delay_ms(1000); } } else {PORTA=0X00;} } }
hello,
is HC06 a slave ?
What application *.apk do you use on your android phone..
did you gives authorization to connect with Android device?
do you have a time-out for discovering your Android ?
same ID code "1234" by default ?
same UART speed as HC06..
You can test also with PC + BT dongle
and Bluesoleil application
wich can show all BT device around the pC
attach one to the PC
active PORTA virual COM1 to the attached device, to dialogue with a classic terminal
like COMx.
I try to send the data it does not transmit...
#define CLS 12
#define CR 13
#define LF 10
#define BS 8
#define TAB 9
#define MAXLEN 32
volatile char buffer[MAXLEN];
volatile int Index1, CptErr,i1;
volatile struct chbits { // 8 flags
unsigned FrameErr:1;
unsigned Store:1;
unsigned Elligible:1;
unsigned Togle:1;
unsigned Second;
unsigned See:1;
unsigned Full:1;
unsigned Lcd:1;
}Drapeaux ;
void interrupt()
{
unsigned char c1;
if ((RCIE_bit) && (RCIF_bit))
{
if (RCSTA.OERR==1) // voir parag 16.1.26 p273
{
RCSTA.CREN = 0 ;
c1 = RCREG;
RCSTA.CREN = 1 ;
CptErr++;
}
if(RCSTA.FERR==1 )
{
RCSTA.SPEN = 0 ;
RCSTA.SPEN= 1 ;
CptErr++;
c1 = RCREG;
}
c1 = RCREG;
if ((c1==CR) || (i1>=MAXLEN))
{
Drapeaux.Full=1;
//PIE1.RCIE=0 ; //interdit IT Reception UART
buffer[i1]=0;
Index1=i1;
i1=0;
c1=0;
}
else
{
buffer[i1]=c1;
Index1=i1;
i1++;
}
RCIF_bit=0 ;
}
}
in the main ----------------
... init UART and others...
// arme UART en reception
RCIF_bit=0;
RCIE_bit=1;
Drapeaux.Full=0;
T0IE_bit=1; // arme Timer0 interrupt
PEIE_bit=1;
GIE_bit=1;
do
{
... some treatments or
Delay_ms(500);
if (Drapeaux.Full==1)
{
// commande des leds D0,D1,D2,D3 sur le portD
if ((buffer[0]=='D')&& ((isalnum(buffer[1]) && (isalnum(buffer[2]) && (strlen(buffer)==3)))))
{
dummy=buffer[1]-48;
if (buffer[2]=='1') PORTD= PORTD | (1<<dummy );
if (buffer[2]=='0') PORTD= PORTD & (0xFF-(1<<dummy));
}
buffer[0]=0;
Drapeaux.Full=0;
i1=0;Index1=0;
}
... other .......
} while(1);
.....
void main() {
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
UART1_Write_Text("Start");
while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
UART1_Write(UART1_Read()); // and send data via UART
}
}
}
the function UART1_Init(9600); does this job for you !,
Query-1:
Code:void main() { UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize UART1_Write_Text("Start"); [COLOR=#FF0000] UART1_Write(13); [/COLOR] // Carriage return is maybe needed by Android application [COLOR=#FF0000]UART1_Write(10);[/COLOR] // Line feed [COLOR=#FF0000]delay_ms(200);[/COLOR] // some delai to get the response while (1) { // Endless loop if (UART1_Data_Ready()) { // If data is received, UART1_Write(UART1_Read()); // and send data via UART } } }
it is better to use interrupt and a buffer to get the answer wich can have more than 1 character!
arm a led status to detect receipt error from uart like
RCSTA.OERR or RCSTA.FERR
Query-2: I have another question why don't I have to configure the RX and TX pin
/*
nota: 23-06-2014
Il est IMPERATIF d'utiliser la syntaxe
UART1_Write_Text((const char *)"AT+NAMEHC06-7D69"); //98:D3:31:B1:7D:69
au lieu de
UART1_Write_Text("AT+NAMEHC06-7D69");
sous peine de se retrouver avec le message
Not enough RAM 'Address' __Lib_EEPROM.c
BlueSoelil HC06-7D69 appairé avec PC, vu comme PORTA serial COM8..OK
usage interface RS232-2T ....OK
03-05-2014
modif Hardware sur le module BT HC06 bleu
soudé fil sur Pin13 Reset
ac:Reset_Pin_HC06
Apres la mise sous tension RESET=1 RESET=0 et RESET=1
le HC06 clignote maintenant à chaque fois ...
28 avril 2014 ... MikroC Pro version Enregistre !!! no more limit
P12F1840_16MHz_2014.cfgsch
last update 03/05/2014
Hardware
12F1840 BT pin 6 N.C.
pin 1 VDD Alim +3.3 ATTENTION !!!!!!!!!!!!!! --------------------BT pin 5 3,3V
pin 2 RA5 -- output ----> HC06 RESET fil soudé direct sur --------BT coté composant pin 11
pin 3 RA4 <--- AN3 Analog input <-- capteur Temper LM335
pin 4 RA3/MCLR/VPP -- ICSP Reset R=5.6K de rappel au +3,3V
pin 5 RA2 <--- RX soft uart 1200 EDFInfo
pin 6 RA1 ICSP Clock & input RX <------TX bluetooth = emission BT pin 3 TX
pin 7 RAO ICSPDAT & output TX ------> RX bluetooth = reception BT pin 2 RX
pin 8 VSS alim 0V ----------------------------------------------- BT pin 4 OV
BT pin 1 N.C.
from version : 12F1840_Teleinfo_8Mhz_121229.c
------------------------------------
Mesure temperature Ambiante du garage LM335 2370mV at 0°C
Dialogue bluetooth RN41
Config vue par Pickit2 3FE4 1613
via Edit Project
CONFIG1 :$8007 : 0x3FE4
CONFIG2 :$8008 : 0x1613
clock 16 Mhz en mode interne INTOSC
Test ADC avec ref 2,048 ..OK
Lecture msg en EEPROM pour afichage
Projet : 12F1840_teleinfo_UART_BT_RN41_2014.mcppi
SW: mikroC PRO for PIC V 6.0
MCU : PIC12F1840 ehanced type
Directory : C:\_MickroC\_MesProjets_MickroC\_12F1840
Source : 12F1840_Teleinfo_1200_UART_19200_16Mhz_140503.c
EEPROM : 12F1840_Teleinfo_8Mhz_121105.ihex ou .eed
Programmateur tools : PicKit2 V2.61 (choose 1,8V family!)
config bits: P18F1840_teleinfo.cfgsch
CONFIG1 :$8007 : 0x0984
CONFIG2 :$8008 : 0x3413
config vu par Pickit2 : 0984 3413 <- OK
VDD : 5,0V ( from 2,3 to 5,5V)
horloge : interne à 16 MHz ... pas de quartz
Librairies utilisees :
- built_in.h
- UART
- C_String
- Conversions
- ADC
device ID = 01 1011 100
Calibrations words 8009h & 800Ah
hex file au format : INHX32 LSB puis MSB
pinout : ac:_12F1840_Pinout
ac:Datasheet
docu :
docu: ac:Interrupts_12F1840
*/
#include "built_in.h" /* for Hi Lo ..etc*/
#define TAB 9
#define CLS 12
#define CR 13
#define LF 10
#define STX 2
#define ETX 3
#define POWER_SUPPLY_3_3V
#define FOSC 16.0 // MHz
#define BAUD 19200 // UART
#define Reset_BT_HC06 LATA5_bit // RA5 direct sur circuit imprimé RESET HC06
//with define 63 bytes RAM remaining (26%) sinon
//error Not enough RAM 'Address' __Lib_EEPROM.c
#define With_Cast_for_TEXTE
const code char mesg0[]="Mikroc pro 6.01 03/05/2014\n\r";
// timer0
const unsigned char NbCycles_1bit = 204; // timer0 8 bits 3328S avec prescaler=1/64 16Mhz
const unsigned char NbCycles_1_demi_bit=230; // 1664 cycles
unsigned int NbCycles_T1; //65535-3035=62500 @16Mhz et prescaler=8 => 62500*8*0.25=125 mS
volatile char buffer[64]; // besoin de 165 car !
char Texte[32];
unsigned short error;
volatile unsigned int CptErr;
volatile unsigned int Count1;
volatile unsigned int i1;
volatile int Flag_Timer1;
volatile int Flag_Timer0;
volatile int Flag_Buffer;
volatile int Index,Index1;
volatile unsigned char c1;
unsigned int i,j,k;
unsigned long clk;
unsigned int M;
char *txt;
char BT_state;
//char response_rcvd;
//char responseID, response = 0;
int Edge_Detect;
void strConstRamCpy(char *dest, const char *source);
void CRLF(void);
void interrupt(void) ;
void Init_Timer0(void);
void Read_Msg_Eeprom(unsigned char depuis);
void Init_Timer1_125mS (void); //125mS
void Init_BT_HC06_direct(void);
void Get_Answer(void);
void interrupt(void) org 0x04
{
if ((RCIE_bit==1) &&(RCIF_bit==1))
{
// traitement separe des erreurs de COM
if (RCSTA.OERR==1) // voir parag 16.1.26 p273
{
RCSTA.CREN = 0 ;
RCSTA.CREN = 1 ;
CptErr++;
}
if(RCSTA.FERR==1 )
{
RCSTA.SPEN = 0 ;
RCSTA.SPEN= 1 ;
CptErr++;
}
c1 = RCREG;
if (c1==CR)
{
Flag_Buffer=1;
//PIE1.RCIE=0 ; //interdit IT Reception UART
buffer[i1]=0;
Index1=i1;
i1=0;
c1=0;
}
else
{
buffer[i1]=c1;
i1++;
Index1=i1;
}
PIR1.RCIF=0 ;
}
if( IOCIE_bit && IOCAF2_bit)
{
Edge_Detect=1;
IOCAF2_bit=0;
IOCIE_bit=0;
}
// ------ timer 1 ----------------
if( TMR1IF_bit==1)
{ // Test "Peripheral Interrupt Request Register 1" for Timer1 Flag
TMR1H= Hi (NbCycles_T1);
TMR1L= Lo (NbCycles_T1);
Count1++;
if (Count1>7) // 8x125 ms= 1 seconde et init timer1 à 3035 et prescaler=1/8
{
Count1=0;
Flag_Timer1=1;
}
PIR1.TMR1IF=0;
}
}
void Get_Answer()
{
Delay_ms(1500);
if (i1>0) // test sur index car pas de CR sur reponse HC06
{ buffer[i1+1]=0; // limite largeur affichage du nokia=14cars
if((buffer[0]='O') && (buffer[1]='K')) k++;
//UART2_Write_Text(buffer);
}
//else
// {
//UART2_Write('A'); UART1_Write('T');
// }
Delay_ms(100);
buffer[0]=0;
i1=0; c1=0;
RCIF_bit=0;
Index1=0;
}
void Init_BT_HC06_direct() // en aveugle,sans test reponse
{
// BT device adresses:
// 00:15:83:2B:6D:87 MyPC OWNPF
// D8:95:2F:3F:F7:10 Archos43 Android apk
UART1_Write('A'); UART1_Write('T');
Get_Answer(); //OK
UART1_Write_Text((const char *)"AT+NAMEHC06-7D69"); //98:D3:31:B1:7D:69
Get_Answer(); //OKsetname
UART1_Write_Text((const char *)"AT+PIN1234");
Get_Answer(); //OK19200
UART1_Write_Text((const char *)"AT+BAUD5");
Get_Answer(); //OK19200
UART1_Write_Text((const char *)"AT+VERSION");
Get_Answer(); //OKlinvorV1.80
}
// --- Copie le texte depuis ROM vers RAM
void strConstRamCpy(char *dest, const char *source) {
while(*source) *dest++ = *source++ ;
*dest = 0 ; // terminateur
}
void CRLF()
{
UART1_Write(CR);
UART1_Write(LF);
}
void Read_Msg_Eeprom(unsigned char debut)
{ int i1 ,i;
i1=debut;
do
{
i = EEPROM_Read(i1);
if ( i==0) break;
if ( i1>254) break;
UART1_Write(i);
Delay_ms(5);
i1++;
}
while (i!=0) ;
}
void Init_Timer1_125mS() //0.992sec
{
T1CON=0;
// T1CON=0b00110000;
TMR1CS0_bit=0; // FOSC internal / 4
TMR1CS1_bit=0;
T1CKPS1_bit=1; //prescal select=11 => 1/8
T1CKPS0_bit=1;
T1GCON=0;
NbCycles_T1= 3035 ;
TMR1H= Hi (NbCycles_T1);
TMR1L= Lo (NbCycles_T1);
Count1=0;
Flag_Timer1=0;
PIR1.TMR1IF=0; // Reset Timer1 Flag
PIE1.TMR1IE=1; //Enable interrupt TMR1
TMR1ON_bit=1;
}
void Separateur(void)
{
UART1_Write(32); UART1_Write(';'); UART1_Write(32);
}
void Temperature_Module()
{
// voir datasheet DS41441B-page 125 fig 15.1
}
void main()
{
// voir page 61
// 0=4xPLL OFF, 1111=IOFS=16Mhz 0=0 00=SCS=config via Conf1 word FOSC<2:0>
// 0=4xPLL OFF, 1110=IOFS=8Mhz 0=0 00=SCS=config via Conf1 word FOSC<2:0>
OSCCON=0b01111010; // choix 16Mhz internal osc
ANSELA=0; // no analog
ANSELA.ANSA4=1; // RA4= Analog input
TRISA= 0b00011111; // RA0,1,2,3,4 as input RA5 as output
WPUA=0b00111111; // weak pull up on RX & TX et RA2
CM1CON0=0; // disable comparators
CM1CON1=0;
CCP1CON=0; // indispensable pour UART sur RA0
Reset_BT_HC06=1;
APFCON=0;
APFCON.P1BSEL=1; // pour deconnecter de RA0 mais connecte sur RA4 ???!!
APFCON.RXDTSEL=0; // RX sur RA1
APFCON.TXCKSEL=0; // TX sur RA0
// because power supplu is only 3,3V
FVRCON.FVREN=0; // disable fixed voltage reference (voir page 124)
FVRCON.TSEN=0; // temperature enable=0;
FVRCON.TSRNG=1; // temperature range high car VDD>3,6V
FVRCON.CDAFVR1=0; // Comparator & DAC OFF
FVRCON.CDAFVR0=0;
FVRCON.ADFVR1=0; // ref is OFF in case of LM335 2730mV art 0°C
FVRCON.ADFVR0=0;
RCSTA=0;
RCSTA.CREN=1; //enable receiver
RCSTA.SPEN=1; // serial port Pins Enable
RCSTA.SREN=1; // single bit receive
c1 = RCREG; // RAZ errors
INTCON=0;
PIR1=0;
PIR2=0;
INTCON.PEIE=0; // disable IT des peripherique voir fig 8.1 p 77
INTCON.GIE=0;
txt=&Texte[0];
UART1_Init(19200);
// vide tampon fifo
while(PIR1.RCIF==1)
{
c1 = RCREG;
}
UART_Set_Active(&UART1_Read, &UART1_Write, &UART1_Data_Ready, &UART1_Tx_Idle); // set UART1 active
UART1_Write(CLS);
Delay_ms(1000);
Flag_Buffer=0;
Index=0;
txt=&Texte[0];
strConstRamCpy(txt, mesg0);
UART1_Write_Text(txt);
Delay_ms(1000);
Read_Msg_Eeprom(0x0000); txt=&Texte[0]; Delay_ms(1000);
Read_Msg_Eeprom(0x00E0); txt=&Texte[0]; Delay_ms(1000);
CRLF();
Read_Msg_Eeprom(0x0020);
j=Clock_MHz();
WordToStr(j,txt); UART_Write_Text(txt); CRLF();
ADC_Init();
ADCON1.ADPREF1= 0; // Vref sur VDD si alim 3,3V
ADCON1.ADPREF0= 0;
Read_Msg_Eeprom(0x0040); CRLF();
j=0;
k=0;
//CptOV=0;
//CptFE=0;
CptErr=0;
Flag_Buffer=0;
Flag_Timer0=0;
Read_Msg_Eeprom(0x00A0); CRLF();
PIE1.RCIE=1;
PIE1.TMR1IE=0; // Enable interrupt on PR1=TMR1
INTCON.PEIE=1; // autorise IT des peripherique voir fig 8.1 p 77
INTCON.GIE=1; // Enable all interrupts (timer1 & UART)
i1=0;
buffer[0]=0;
Index1=0;
PIE1.TMR1IE=0; //disable interrupt TMR1
Reset_BT_HC06=1;
Delay_ms(1000);
Reset_BT_HC06=0;
Delay_ms(1000);
Reset_BT_HC06=1;
Delay_ms(1000);
k=0;
Init_BT_HC06_direct() ;
CRLF();
if (k>=4)
{
UART1_Write_Text((const char *)" Init OK k=");
}
else
{
UART1_Write_Text((const char *)" Bad Init k=");
}
WordToStr(k, txt) ;
UART1_Write_Text(txt);
CRLF();
while(1)
{
j=0;
Index=0;
Index1=0;
i1=0;
Read_Msg_Eeprom(0x0030); CRLF();
Init_Timer1_125mS (); //init pour 1 sec et lance timer1
Flag_Buffer=0;
Index=0;
M=ADC_Get_Sample(3); // lecture AN3 sur RA4
Read_Msg_Eeprom(0x0050);
UART1_Write(TAB);
WordToStr(M, txt) ;
UART1_Write_Text(txt);
CRLF();
while (Flag_Timer1==0);
} // while (1)
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?