I am trying to connect my HC-05 bluetooth module with PIC16F877A. I know we have to use USART to talk with bluetooth module. So I started with USART of PIC by reading its datasheet.

I am using MPLABX IDE with XC8 compiler and i am not interested in using any libraries.

Code:
  • // CONFIG#pragma config FOSC = HS
  • // Oscillator Selection bits (HS oscillator)#pragma config WDTE = OFF
  • // Watchdog Timer Enable bit (WDT disabled)#pragma config PWRTE = ON
  • // Power-up Timer Enable bit (PWRT enabled)#pragma config BOREN = ON
  • // Brown-out Reset Enable bit (BOR enabled)#pragma config LVP = OFF
  • // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
  • #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
  • #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control
  • )#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
  • // #pragma config statements should precede project file includes.// Use project enums instead of #define for ON and OFF.
  • #define _XTAL_FREQ 20000000
  • #include<xc.h>
  • void main(void){
  • unsignedint i;
  • TRISA=0xff;
  • //UART
  • TRISC=0X00;
  • TXSTA=0X20;// TX RS232 settings
  • RCSTA=0X80;// RX RS232 Settings
  • SPBRG=31;// Baud rate is set based on Crystal clock
  • TXSTAbits.TXEN=1;// Enable RS232 transmissionRCSTAbits.SPEN=1;// Enable RS232 reception
  • while(1){
  • TXREG=65;
  • __delay_ms(200);
  • }}


I used the above code to send a char 'A' from PIC to USART and was successful in reading it using my serial monitor on PC (with RS232).

Now form what I understood, if I replace the RS232 with my bluetooth module I should get the same char 'A' transmitted to my mobile phone.

I am using Bluetooth Terminal android app to check the reception of data. But the after the app connects to the module it just shows a blank screen. I dont receive anything.

What could be the reason please help me!!!!!!.

Things that I tried :


  1. There is no problem with the baud-rate, both my Rs232 and HC-05 works at 9600. I have ensured the same using my arduino and HC-05.
  2. there is no logic level problem I have used a potential divider to shift 5V to 3.3V.

I am quite new here so forgive me if my question is not that appropriate.


I am trying to connect my HC-05 bluetooth module with PIC16F877A. I know we have to use USART to talk with bluetooth module. So I started with USART of PIC by reading its datasheet.

I am using MPLABX IDE with XC8 compiler and i am not interested in using any libraries.