rishiraj
Junior Member level 1
- Joined
- Dec 25, 2012
- Messages
- 15
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,393
Hi,
I am trying to interface the HC-05 module with a bootloaded PIC1826K22. I connected USART1 with the module and USART2 is connected to my laptop via USART to Serial converter IC. Below is my code.
The problem is, I get garbage value in return when I type the AT command in hterm with CR-LN. My USART1 is configured at 38400 baud rate (defualt for HC05) and USART2 at 9600.
My HC-05 is working fine and it is indeed in 38400 baud rate because I checked the same in Arduino and it worked fine. In Arduino. Kindly throw some light
I am trying to interface the HC-05 module with a bootloaded PIC1826K22. I connected USART1 with the module and USART2 is connected to my laptop via USART to Serial converter IC. Below is my code.
The problem is, I get garbage value in return when I type the AT command in hterm with CR-LN. My USART1 is configured at 38400 baud rate (defualt for HC05) and USART2 at 9600.
My HC-05 is working fine and it is indeed in 38400 baud rate because I checked the same in Arduino and it worked fine. In Arduino. Kindly throw some light
Code:
#include <stdio.h>
#include <stdlib.h>
#include <p18f26k22.h>
#include "oscillator.h"
void main(void)
{
set_freq(f8Mhz);
//########### EUART 1 CONFIG #########
TXSTA1bits.TXEN=1; //Transmitter Enabled
TXSTA1bits.SYNC=0; //Asynchronous Mode
TXSTA1bits.BRGH=1; //x16 Multiplier in Use
BAUDCON1bits.BRG16=0; // Set Low BRG16
SPBRG1=12; //Set the multiplier for 38400 baudrate
RCSTA1bits.CREN=1; //Serial Port Enabled
RCSTA1bits.SPEN=1; //Serial Port Enabled
ANSELCbits.ANSC6=0; //Disbale Analog
ANSELCbits.ANSC7=0; //Disbale Analog
TRISCbits.TRISC7=1; //For EUART1 (NOTE THIS !!!!) RX
TRISCbits.TRISC6=1; //For EUART1 TX
//########### EUART 2 CONFIG #########
TXSTA2bits.TXEN=1; //Transmitter Enabled
TXSTA2bits.SYNC=0; //Asynchronous Mode
TXSTA2bits.BRGH=1; //x16 Multiplier in Use
BAUDCON2bits.BRG16=0; // Set Low BRG16
SPBRG2=51; //Set the multiplier for 9600 baudrate
RCSTA2bits.CREN=1; //Serial Port Enabled
RCSTA2bits.SPEN=1; //Serial Port Enabled
TRISBbits.TRISB7=1; //For EUART2 (NOTE THIS !!!!) RX
TRISBbits.TRISB6=1; //For EUART2 TX
while(1)
{
if(PIR3bits.RC2IF)
{
TXREG1=RCREG2;
PIR3bits.RC2IF=0;
}
if(PIR1bits.RC1IF)
{
TXREG2=RCREG1;
PIR1bits.RC1IF=0;
}
}
}