Connect with us

Interfacing bluetooth module with microcontroller

Discussion in 'Microcontrollers, Programming and IoT' started by Rahul Sreekumar, May 18, 2014.

  1. Rahul Sreekumar

    Rahul Sreekumar

    4
    0
    May 14, 2014
    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.
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    8,694
    1,692
    Nov 17, 2011
    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.
     
  3. Rahul Sreekumar

    Rahul Sreekumar

    4
    0
    May 14, 2014

    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....
     

    Attached Files:

  4. Harald Kapp

    Harald Kapp Moderator Moderator

    8,694
    1,692
    Nov 17, 2011
    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.
     
  5. Rahul Sreekumar

    Rahul Sreekumar

    4
    0
    May 14, 2014



    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.
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    8,694
    1,692
    Nov 17, 2011
    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.

    No, sorry, I don't have that information.
     
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.