Blueooth HC06 Interfacing with PIC18F

157 Views Asked by At

I am currently learning the PIC. I am using PIC18F46K22. I want to send commands from my phone to the PIC using Bluetooth HC06 Module. On Arduino, everything works fine. However, when i switch to PIC, it isnt working. It is connecting but the Rx and Tx dont perform. After comparing with the arduino code, the only problem i see is the blueooth initialization. I have connected the Tx and Rx pins of bluetooth to Rx and Tx of the PIC, respectively. All the websites i read are the same, and i already tried them so i am clueless what to do. Please, any help in what is the probelm is much much appreciated. This is my code:

char receive;
     void main(){

           TRISA=0x00;
           ANSELA=0;
           PORTA.F0=0;
           UART1_Init(9600);
           Delay_ms(100);

          while(1){

          if (UART1_Data_Ready()) {
             receive = UART1_Read();
                 if (receive=='1')   {
                  PORTA.F0=1;
                 }
                 else{
                 PORTA.F0=0;
                        }

                             }
                                  }
                                         }
2

There are 2 best solutions below

2
On

First,you didnt say what compiler you are using? Did u make debug your code ? Maybe your clock settings are wrong. And it is due to set wrong baudrate. Check your initializing for uart.

1
On

You have a very simple mistake, and that should be the problem. PORTC is by default initialized as an analog Port. Therefore, Tx and Rx pins do no perform their function. In order to disable PORTC as analog (configure as digital), with PIC18F46K22, the function would be ANSELC=0; Hope that helps!