Junk AT Response. HC-05 Bluetooth M. with PIC1826K22

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
rishiraj
Posts: 2
Joined: Fri May 02, 2014 9:08 am

Junk AT Response. HC-05 Bluetooth M. with PIC1826K22

Post by rishiraj » Fri May 02, 2014 9:29 am

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

Code: Select all

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

User avatar
phalanx
Non-SFE Guru
Posts: 1992
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Junk AT Response. HC-05 Bluetooth M. with PIC1826K22

Post by phalanx » Tue May 20, 2014 6:37 am

My first question would be: All your baud rate generation values are based on a certain processor execution speed. Are you positive your PIC is running at that speed?

If you are certain everything clocked properly, I would start debugging by outputting canned data to your PC and bluetooth module to see if any data can be transmitted properly.

-Bill

Post Reply