Maker Pro
Maker Pro

Interfacing bluetooth module with microcontroller

Rahul Sreekumar

May 14, 2014
4
Joined
May 14, 2014
Messages
4
I am trying to interface blue link bluetooth module with pic16f887. I am using an android application called 'Android Hyperterminal'. When i receive the data, the 1st letter is replaced by the second letter.
ie, if I send 'HELLO', I will get 'EELLO'. Please help me.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,719
Joined
Nov 17, 2011
Messages
13,719
I assume the bluetooth module is linked to the PIC via UART?
This sounds like a software issue with reading the buffer of the UART. Show us the relevant code section.
 

Rahul Sreekumar

May 14, 2014
4
Joined
May 14, 2014
Messages
4
I assume the bluetooth module is linked to the PIC via UART?
This sounds like a software issue with reading the buffer of the UART. Show us the relevant code section.


The module is linked to PIC via UART. Baud rate is 9600. I doubt that some characters which cannot be seen may be received.(egs: like \r or \n). I am attaching the c file to this.
Thanks for your reply....
 

Attachments

  • main.txt
    3.8 KB · Views: 303

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,719
Joined
Nov 17, 2011
Messages
13,719
I don't know whether this is the source of the problem you have, but these code lines (that you use several times in similar form) are suspicious:
Code:
for(char i=0;i<7;i++)
        {
            buf[i]=GetByte_TimeOut();
            if(buf[i]=='K' && buf[i-1]=='O')
                return;
        }
For i=0 the expression buf[i-1]=='O' evaluates to buf[-1]=='O' which will point anywhere into memory, but most probably not where you expect.
 

Rahul Sreekumar

May 14, 2014
4
Joined
May 14, 2014
Messages
4
I don't know whether this is the source of the problem you have, but these code lines (that you use several times in similar form) are suspicious:
Code:
for(char i=0;i<7;i++)
        {
            buf[i]=GetByte_TimeOut();
            if(buf[i]=='K' && buf[i-1]=='O')
                return;
        }
For i=0 the expression buf[i-1]=='O' evaluates to buf[-1]=='O' which will point anywhere into memory, but most probably not where you expect.




Thanks.. But that loop works fine.. I had used such loops several times. The data sent using android hyperterminal is received in the interrupt service routine. But, I don't understand the problem in that. May be some unseen characters are received. can you please sent me the format in which the message sent by mobile phone is received by the bluetooth module.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,719
Joined
Nov 17, 2011
Messages
13,719
May be some unseen characters are received
In your main loop you have
Code:
            for(char i=0;i<31;i++)
            {
                lcd_goto(i);
                lcd_putch(message[i]);
            }
Here you output any character regardless of its value. I don't know what your LCD does when receiving e.g. a CR of LF via lcd_putc. Or any other non-printable character. You could add a check to verify that message is a valid character, e.g. in the range 0-9, a-z, A-Z.

can you please sent me the format in which the message sent by mobile phone is received by the bluetooth module.
No, sorry, I don't have that information.
 
Top