bmuigai
Newbie level 5
Hi everyone,
I am trying to make an interface between an android phone and microcontroller using the HC-06 Bluetooth module. I started this morning by trying it out on arduino uno and as there are many tutorials on the internet about the same, I managed in perhaps the first hour to send characters from my phone.
But am a fan of PIC microcontrollers and so I decided to go for the major adventure of the day. As it however turns out about 12 hours later, its turning into a nightmare. I can pair with my phone and initialize the UART communication without problems. when I start typing, I can also tell that there is signal being detected by my PIC. But there seems to be no data transfer except for an error. What could be wrong with my code.
I'm using MikroC and Mplab with PICKIT3 and Blueterm2 in android phone
I am trying to make an interface between an android phone and microcontroller using the HC-06 Bluetooth module. I started this morning by trying it out on arduino uno and as there are many tutorials on the internet about the same, I managed in perhaps the first hour to send characters from my phone.
But am a fan of PIC microcontrollers and so I decided to go for the major adventure of the day. As it however turns out about 12 hours later, its turning into a nightmare. I can pair with my phone and initialize the UART communication without problems. when I start typing, I can also tell that there is signal being detected by my PIC. But there seems to be no data transfer except for an error. What could be wrong with my code.
I'm using MikroC and Mplab with PICKIT3 and Blueterm2 in android phone
Code:
unsigned short counter=0;
void interrupt() {
if (INTCON.TMR0IF) {
if (counter >= 20) {
Soft_UART_Break();
counter = 0; // reset counter
}
else
counter++; // increment counter
INTCON.TMR0IF = 0; // Clear Timer0 overflow interrupt flag
}
}
void main(){
unsigned char error, datain, byte_read=0, i, k=100, j=9, l=200;
TRISB.F3=0;
TRISA=0;
PORTB=0;
PORTA=0;
ANSEL=0;
CMCON=7;
OSCCON=0B01001100;
OPTION_REG = 0x04; // TMR0 prescaler set to 1:32
TMR0=0;
INTCON.TMR0IE = 0; // Enable Timer0 overflow interrupt
for(i=0; i<3; i++){
PORTA=255;
Delay_ms(100);
PORTA=0;
Delay_ms(100);
}
error = Soft_UART_Init(&PORTB, 4, 5, 9600, 0);
Eeprom_Write(0x00, error);
if (error > 0) {
Eeprom_Write(0x01, error);
delay_ms(10);
/*PORTA=error; Delay_ms(30);
PORTA=0; Delay_ms(30);*/
while(1); // Stop program
}
Delay_ms(100);
while(1) { // Endless loop
INTCON.GIE = 1; // Global interrupt enable
INTCON.TMR0IE = 1; // Enable Timer0 overflow interrupt
byte_read = Soft_UART_Read(&error); // Read byte, then test error flag
INTCON.GIE = 0; // Global interrupt disable
INTCON.TMR0IE = 0; // Disable Timer0 overflow interrupt
if(error==0){
Eeprom_Write(j, byte_read); //save data in Eeprom
j+=1; if(j>200) j=9;
PORTA=3; Delay_ms(30);
Eeprom_Write(0x04, j); ////save number of characters in Eeprom
PORTA=0; Delay_ms(30);
PORTA = byte_read;
//Eeprom_Write(j, byte_read);
}
else Eeprom_Write(0x05, error); //save error message in Eeprom
}
}