Announcement

Collapse
No announcement yet.

RN4020 Bluetooth Module, unable to send serial commands to module via Diablo16

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • RN4020 Bluetooth Module, unable to send serial commands to module via Diablo16

    Hello,

    I have moved my Bluetooth module recently, from being controlled via an Atmel mcu to being controlled via the Diablo16, this would save me an in between step.

    Anyways I have moved/ re wrote the code to work for the 4Dsystem mcu (Diablo16) and I have no luck getting the serial commands to work properly. I am already using a serial communication between the Diablo16 and and the Atmel mcu, but can't get the diablo16 to control the BT through serial.

    Below is a sample of the commands that I am sending, also the serial set up and serial functions.



    /////////////////////////////SETUP//////////////////////////////////////////////

    pin_Set(PIN_OUT,PA1); // pin Wake_HW BT
    pin_Set(PIN_OUT,PA3); //CMD/M BT
    pin_Set(PIN_OUT,PA10); // Wake_SW BT
    pin_Set(PIN_OUT,PA11); // BT connected BT
    pin_Set(PIN_OUT,PA14); // RTS_BT BT=
    pin_Set(PIN_OUT,PA15); // CTS_BT BT

    COM2_TX_pin(PA9); //Serial TX1 bt
    COM2_RX_pin(PA8); //Serial RX1 bt

    com_SetBaud(COM2, 11520); //SET baud rate FOR COM2
    com2_Init(Com_buffer2, 100, 0); //setup buffer
    com2_Reset(); //reset com2



    ///////////////////////////Serial Functions & BT Set up////////////////////////////////////


    func sendStringBluetooth(var btString)

    to(BT_Buffer); putstr(btString);
    putstr(BT_Buffer);

    var p, a;
    p := str_Ptr(BT_Buffer);

    for(i := 0; i < 100; i++) //loop to write every character to var
    a := (str_GetByte(p + i));
    sendCharBluetooth(a);
    next

    endfunc


    func sendCharBluetooth(var btChar)

    serout2(btChar);
    pause(10);

    endfunc


    func BTFactoryReset()
    pin_HI(PA10);

    for(i := 0; i < 3; i++)
    pin_HI(PA1);
    pause(100);
    pin_LO(PA1);
    pause(100);
    next

    pin_HI(PA1);
    pause(100);
    pin_LO(PA1);

    endfunc


    func BTWake()

    pin_HI(PA1);
    pin_HI(PA10);
    pause(100);
    pin_LO(PA1);

    endfunc

    /////////////////////////////////Command Functions///////////////////////////


    func bluetoothTest()

    to(BT_Command); putstr("+\r\n");
    sendStringBluetooth(BT_Command);
    pause(500);

    to(BT_Command); putstr("SF,1\r\n");
    sendStringBluetooth(BT_Command);
    pause(500);

    to(BT_Command); putstr("SS,C0000000\r\n");
    sendStringBluetooth(BT_Command);
    pause(500);

    to(BT_Command); putstr("SR,92000000\r\n");
    sendStringBluetooth(BT_Command);
    pause(500);

    to(BT_Command); putstr("SN,TestName\r\n");
    sendStringBluetooth(BT_Command);
    pause(500);

    to(BT_Command); putstr("R,1\r\n");
    sendStringBluetooth(BT_Command);
    pause(500);


    endfunc


    /////////////////////////Application//////////////////////////////////////////


    BTWake();
    pause(500);
    BTFactoryReset();
    pause(500);
    bluetoothTest();



    The way I am currently testing to see if the commands got through is to search for the device with an app from microchip and see if the given name comes up (TestName) or simply RN####, I don't know if this is the best way but what I am doing.

    Would appreciate any help from the community, let me know if anything is unclear or if you need more details.

    Thanks,

    Navid

  • #2
    Hi Navid,

    Welcome to the Forum!

    I tried replicating your code and observed that the condition in the “for loop” is configured to check if the value of variable “i” is less than 100. Since the actual length of the command string varies, it is more appropriate to limit the number of bytes being written based on the length of string stored in the buffer. Otherwise, you will be sending unwanted data to the Bluetooth module.

    Below is the information received by the Bluetooth module taken using a USB to UART, connected to the configured RX and TX (PA8 and PA9):

    If the condition in the “for loop” is (i < 100):

    Code:
    .tName
    .....................................< ..R,1
    .tName
    .......K.........~.> ......^...0.+
    .
    .tName
    .....................................< ..+
    .
    .tName
    .......K...........> ......^...0.SF,1
    .Name
    .....................................< ..SF,1
    .Name
    .......K...........> ......^...0.SS,C0000000
    .....................................< ..SS,C0000000
    00.....K...........> ......^...0.SR,920000
    .....................................< ..SR,92000000
    .......K.........<.> ......^...0.SN,TestName
    .....................................< ..SN,TestName
    ,1....RK.........].> ......^...0.
    .tName
    Though if the condition is set to this (i < strlen(BT_Buffer)):

    Code:
    SS,C0000000
    SR,92000000
    SN,TestName
    R,1
    +
    SF,1
    SS,C0000000   
    SR,92000000
    SN,TestName
    R,1
    +
    SF,1
    SS,C0000000
    SR,92000000
    SN,TestName
    R,1
    Alternatively, you can easily send all the characters from the string using:
    Code:
    to(COM2);  putstr(BT_Buffer);
    instead of looping through all characters.

    BR,
    Pearl
    Pearl

    Comment


    • #3
      Hi Pearl,

      That has fixed the problem! I should have made that dynamic but I didn't think that would be the issue, since it was printing exactly what I wanted to the display. I though there was something wrong with the way I was using the serial functions.

      Anyways, you have fixed the issue, thanks again for your help!

      Navid,

      Comment


      • #4
        Glad to help Navid. If you have further questions, don't hesitate to ask.

        Best Regards,
        Pearl
        Pearl

        Comment

        Working...
        X