1

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;
                        }

                             }
                                  }
                                         }
Fawaz
  • 1,253
  • 2
  • 11
  • 9

2 Answers2

0

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.

embeddedstack
  • 362
  • 1
  • 13
  • Thank you for your reply. I am using microC compiler. This language is microC for PIC. My baud rate as you can see in the code is 9600. That same baud rate works also on Arduino. I tried higher but it also didnt work. From your experience, the mistake seems in the UART initialization or what? – Fawaz Dec 18 '17 at 03:40
  • First you must examine what receiving data? You watch variable "receive". Also , where is your uart settings ? i can see only one function to init. Maybe you can configure your clock settings. – embeddedstack Dec 18 '17 at 10:44
0

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!

Fawaz
  • 21
  • 5