This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430F5255: Problem in using BG Lib with MSP430

Part Number: MSP430F5255

Tool/software: Code Composer Studio

Hi Guys,

I am integrating BLE121LR from SiLabs to MSP430 using BG Lib. Till now I worked on BLE121LR using BG Script, but for programming flexibility, we shifted to use BG Lib. For this, we included the BG Lib in our MSP code, but as the BG Lib supports only GCC compiler we shifted to MSP430 GCC compiler from native TIs MSP430 compiler. 

After including the library, we are able to do scanning and getting the response from the BLE Module. But when we are trying to connect using an address, by passing it to the related function, we are not getting the same address we are passing. We are getting the address as all FF FF FF FF FF FF which is not correct. We contacted Si Labs regarding this and they are saying their libraries are perfect. 

So I am attaching my code also with this, Please give me a solution. 

BLE MSP GCC trials.rar

  • Hi Santhosh,

    I'm unfamiliar with BG Lib so I'll be learning as I'm helping you. I downloaded your code and the first thing I noticed was that it's difficult to follow. There isn't much commenting and there are large portions of commented out code that make things confusing. Instead of trying to debug your entire code set, can you rework the code to a simplified version that only contains the bare minimum to reproduce the issue?

    Also, can you direct me to the portion in the code where the issue appears to be originating from?

    Best regards,
    Caleb Overbay
  • Hi Caleb Overbay,

    Thank you so much for responding. With this post, I am attaching 2 files. One is my code BLE MSP GCC trials 2 which is now under development, and the other is scan_example which is the example code to use BG Lib provided by SiLabs(Bluegiga). 

    Coming to my code, I need to develop MSP as a host controller for my BLE Module. Here my application is to develop a BLE Master. For this I need to follow below flow

    1. Discover BLE Slave devices. 

    This is done by ble_cmd_gap_discover(gap_discover_generic);


    2. Collect BLE Scan Responses.

    Here scanning response will be generated based on the BLE Slave advertisement packet. Here we need to find out to which particular device we need to connect (by storing and comparing the known MAC address.)

    I am getting this in ble_evt_gap_scan_response(const struct ble_msg_gap_scan_response_evt_t *msg) in commands.h file. When I get the response of the slave device I need, 

    3. Connect to Slave Device.

    This can be achieved using ble_cmd_gap_connect_direct(&connect_addr, gap_address_type_public, 32, 48, 100, 0);  command. Using the APIs and Library, I am able to send all other commands properly but for this command, the address I am passing in this command is not reflecting in the output data or data going to BLE module. I verified this by connecting the MSP UART to my PC Serial Console. 

    As only Rx,Tx pins are connected between BLE module and MSP, I am using PACKET MODE (Length byte followed by data) to communicate with BLE. 

    Once please go through the both codes, I removed all the unnecessary code and commented well to give you a clear picture of my code. I hope you understand my problem. My code is faiing only when using particular command in which I need to pass MAC address of the BLE module. This command finally calls ble_send_message() in cmd_def.c file. This function generates or builds up the related API basing on the arguments msgid defined in cmd_def.h. 

    BLE MSP GCC trials 2.rarHTMcollector.rar

  • Hi Santhosh,

    Thank you for cleaning things up and helping to guide me.

    SANTHOSH KUMAR NALLAMALLA said:
    Using the APIs and Library, I am able to send all other commands properly but for this command, the address I am passing in this command is not reflecting in the output data or data going to BLE module. I verified this by connecting the MSP UART to my PC Serial Console. 

    Can you provide detail on what data you expect to be sent from the MSP430 and what data you are actually observing?

    Best regards, 

    Caleb Overbay

  • Hi Caleb Overbay,

    Sorry for the late response...

    The expected data is 

    13 00 0F 06 03 DD 16 44 D8 65 AB 48 B3 00 00 04 00 00 00 DA

    But the data I am receiving is

    13 00 0F 06 03 FF FF FF FF FF FF 48 B3 00 00 04 00 00 00 DA.

    Mac address of BLE device is not reflecting. The 1st byte is length byte. Next 4 are Header for command. Next 6 bytes are BLE Address. Please find the attached image for the details of the command I am using.  

  • Hi Santhosh, 

    I just want to confirm that the data you showed in your previous post is being sent from the MSP430 and not received?

    After looking through the code I didn't see many changes from the first project you sent me. It's still very hard to follow, uncommented, and there are large portions of commented out code. My best guess here is that you are passing the connect_addr parameter incorrectly to the ble_cmd_gap_connect_direct command. I can't be sure of this though because this command has no explanation of it's parameters and neither does the ble_send_message command.

    Overall, the code is too disorganized to follow logically. There are functions being implemented in .h files and commands being defined as other commands. It's extremely difficult to digest. I would suggest working on cleaning up this code and you'll most likely solve the issue. 

    Best regards, 
    Caleb Overbay

  • Hello Santhosh,

    I'm pretty sure that the rest of the protocol PDU is also malformed / invalid. One example:

    Byte 10 of the PDU contains the addr_type. According to your code you're using a public Bluetooth address. Looking to the specs this means byte 10 should have the value 0x00, but your expected value is 0x48?!

    My best guess would be that bglib is compiled with the wrong hardware settings.

    Best regards

    Christoph

  • Hi Christoph,

    Yes I too noticed that. But this problem is only coming with ble_cmd_gap_connect_direct () this command. Rest other commands are working. I mean I checked ble_cmd_system_hello(), ble_cmd_gap_discover(gap_discover_generic). These both are working but these two didnt have more parameters like ble_cmd_gap_connect_direct().

    The main problem I am getting is parameters passing only. And instead of passing connect_addr, I tried to pass the direct character array buffer temp_add1 also. But still I am getting the problem.

    In the BG Lib from Si Labs, they defined as below in cmd_def.h

    #define ble_cmd_gap_connect_direct(connect_addr,addr_type,conn_interval_min,conn_interval_max,timeout,latency) ble_send_message (ble_cmd_gap_connect_direct_idx,connect_addr,addr_type,conn_interval_min,conn_interval_max,timeout,latency)

    And ble_send_message () is defined in cmd_def.c as below,

    void ble_send_message(uint8 msgid,...)
    {
    uint32 i;
    uint32 u32;
    uint16 u16;
    uint8 u8;

    struct ble_cmd_packet packet;
    uint8 *b=(uint8 *)&packet.payload;

    uint8 *hw;
    uint8 *data_ptr=0;
    uint16 data_len=0;
    va_list va;
    va_start(va,msgid);

    i=apis[msgid].params;
    packet.header=apis[msgid].hdr;
    while(i)
    {

    switch(i&0xF)
    {

    case 7:/*int32*/
    case 6:/*uint32*/
    u32=va_arg(va,uint32);
    *b++=u32&0xff;u32>>=8;
    *b++=u32&0xff;u32>>=8;
    *b++=u32&0xff;u32>>=8;
    *b++=u32&0xff;
    break;
    case 5:/*int16*/
    case 4:/*uint16*/
    u16=va_arg(va,unsigned);
    *b++=u16&0xff;u16>>=8;
    *b++=u16&0xff;
    break;
    case 3:/*int8*/
    case 2:/*uint8*/
    u8=va_arg(va,int);
    *b++=u8&0xff;
    break;

    case 9:/*string*/
    case 8:/*uint8 array*/
    data_len=va_arg(va,int);
    *b++=data_len;

    u16=data_len+packet.header.lolen;
    packet.header.lolen=u16&0xff;
    packet.header.type_hilen|=u16>>8;

    data_ptr=va_arg(va,uint8*);
    break;
    case 10:/*hwaddr*/
    hw=va_arg(va,uint8*);

    *b++=*hw++;
    *b++=*hw++;
    *b++=*hw++;
    *b++=*hw++;
    *b++=*hw++;
    *b++=*hw++;

    break;
    case 11:/*uint16 array*/
    data_len=va_arg(va,int);
    *b++=data_len&0xff;
    *b++=data_len>>8;

    u16=data_len+packet.header.lolen;
    packet.header.lolen=u16&0xff;
    packet.header.type_hilen|=u16>>8;

    data_ptr=va_arg(va,uint8*);
    break;
    }
    i=i>>4;
    }
    va_end(va);
    if(bglib_output)bglib_output(sizeof(struct ble_header)+apis[msgid].hdr.lolen,(uint8*)&packet,data_len,(uint8*)data_ptr);
    }


    I contacted Si Labs that whether they gave proper Library or not, but they are saying that these are working libraries. And these were tested for Desktop application.
  • Hi Christoph,

    We got where the bug is. Actually, we are facing problems due to data types. 

    In the given Library from Si Labs, data types are defined as below

    typedef unsigned char uint8;
    typedef unsigned short uint16;
    typedef signed short int16;
    typedef unsigned long uint32;
    typedef signed char int8;

    Can you please make sure that these data types are correct for MSP430 using MSP430-GCC compiler or not. 

    Thank you...

    Best regards

    Santhosh

  • Hi Santhosh,

    SANTHOSH KUMAR NALLAMALLA said:

    In the given Library from Si Labs, data types are defined as below

    typedef unsigned char uint8;
    typedef unsigned short uint16;
    typedef signed short int16;
    typedef unsigned long uint32;
    typedef signed char int8;

    those typedefs look quite similar to what gcc/libc typedefs in its standard header stdint.h

    sourceforge.net/.../stdint.h

    best regards

    Christoph

**Attention** This is a public forum