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.

Communicate with CC2540 USB dongle with serial terminal program(tera term)

Other Parts Discussed in Thread: CC2540

Hey guys,

So far I've been testing my BLE project by using Btool to control the USB dongle(loaded with CC2540_USB dongle_HostTestReleaseAll.hex). As I understand it, loading the  USB dongle with the hostTestRelease file lets you control the dongle through a virtual COM port. So, I'd like to move away from Btool and write a labview vi to control it.

Before I do that though, I wanted to test it by trying to control it through a serial terminal program like tera term. So I open tera term and it recognizes the CC2540 as a COM port(COM port 3 on my PC). I setup the the serial port with the same parameters Btool uses. Now, I try to send it "01 00 FE 26 08 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00"  which is the Gap_Device Init code that Btool first sends when you open it. But there is no response. Can anybody tell me why I'm not able to read anything back? Is it the string format? Do I need to send it an ASCII string? Will I need to include a new line terminate character? 

I would really appreciate any help or suggestions.

regards,

V

  • Hi Vivek, you have several similar examples at the top rows of the forum, in the linux examples.

    Can you give them a try and let us know?

    Thanks! :)

  • I'm trying to do the same. I want to develop my own application on MATLAB to communicate with the usb dongle through HCI commands via a serial connection. Before doing that I tried using Realterm to send any command but I couldnt enter anything in the terminal. I've looked at the provided examples including those developed in  Linux but couldn't find any clue why I dont get a response from the dongle. The only two applications that work are BTool and BleHealthDemo (which is based on BTool) . I looked at the BleHealthDemo code but didnt get any helpful hint.

    I feel there is something has to be done to initialise the connection to the usb dongle under Windows 7. I looked at the JavaSimplePeripheral code and it seems it doesnt work on Windows 7. I wonder if anyone has managed to communicate with the dongle using applications other than BTool.

    Regards

    Ehad

  • Simple - just send "binary" bytes that correspond to a command that should have a response. Take the read board address command which is exactly 4 binary bytes but shown as hex: 0x01 0x09 0x10 0x00

    Then you will recieve the 13 binary bytes of response.

    I use Br@y Terminal to open port at 115200,8,N,1 & no flow control and can talk to this .hex image:

    C:\Texas Instruments\BLE-CC254x-1.2.1 - Copy\Accessories\HexFiles\CC2540_USBdongle_HostTestRelease_All.hex

     

  • Thanks a lot, it's working now. I had to send and receive the data as ASCII characters in MATLAB.  Here is a sample code for testing the serial communication with the USB dongle:

    -------------------------------------------------------------------------------

    clear
    clc
    try
    fclose(INSTRFIND);%closes all current ports
    catch
    end
    s = serial('COM2');
    set(s,'BaudRate',115200,'Timeout',0.2,'FlowControl','none','Parity','none');

    fopen(s);

    GAP_initialise=['01';'00';'FE';'26';'08';'03';'00';'00';'00';'00';'00';'00';'00'
    '00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00'
    '00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'01'
    '00';'00';'00'];
    dec=hex2dec(GAP_initialise);
    fwrite(s,char(dec)');
    [A,count] = fread(s,30);
    h=dec2hex(A);
    h_disp='';
    for i=1:length(h)
    h_disp=[h_disp h(i,:) ' '];
    end
    h_disp

    ---------------------------------------------------------------------------

  • Br@y Terminal has an great macro functionality - at the bottom left corner of the gui, press the 'Set Macros' button and for macro one, M1, enter the hex of the message you want to send. So to read the board address:

    $01$09$10$00

    Then just press M1 to send the binary 4 bytes.

  • Hi Vivek

    did you suceed in Labview?

    Best regards, Gernot

  • Dear Ehad, 

    I have taken the MATLAB code you have provide here and I did extend it to acquire the time parameters, scan for sensors and establish connection.

    However, when I try to establish a connection link I get an error that indicates that ' bleNotReady".

    The following code was sent to the module:

    GAP_EstablishLinkRequest= ['01'; '09'; 'FE'; '09'; '00'; '00'; '00'; '1A'; 'EB'; 'A1'; 'E5'; 'C5'; '78']; %for OLP425i
    TxText=['01 09 FE 09 00 00 00 1A EB A1 E5 C5 78'];
    %GAP_EstablishLinkRequest= ['01'; '09'; 'FE'; '09'; '00'; '00'; '00'; '53'; '19'; 'A0'; 'E5'; 'C5'; '78']; %for ketfob
    %TxText=['01 09 FE 09 00 00 00 53 19 A0 E5 C5 78'];
    dec=hex2dec(GAP_EstablishLinkRequest);
    fwrite(serConn, char(dec)');
    display('Establish Link Request')
    display(['Tx: ' TxText])

    [R,count] = fread(serConn);

    h=dec2hex(R); %convert received data from decimal to hex
    RxText=''; %define an empty string array
    for i=1:length(h)
    RxText=[RxText h(i,:) ' ']; %load the array with to received string
    end
    display(['Rx: ' RxText])

    and I get the following packet:

    Rx: 04 FF 06 7F 06 10 09 FE 00 

    where the 6th packet indicates the status (0x00 =success and my case 0x10=bleNotReady) according to table Host Error Code (pp.153) in the TI_BLE_Vendor_Specific_HCI_Guide.pdf.

    I think there is an extra parameter I have to set in the MATLAB serial setting because using in X_CTU software I can connect with the sensor successfully.

    Do you have any idea what is wrong with my code or module.

    Regards,

    Asiya

  • Hi Asiya,

    I haven't tried sending a link request. What I did is that I set the portable BLE node to continuously advertise and the BLE dongle on my PC is continuously scanning. What I noticed in your code you haven't initialised the GAP. Here is the part of the code I used to initialise the GAP. Once you do that, try to run your code and see how it goes.

    GAP_initialise=['01';'00';'FE';'26';'08';'03';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'01';'00';'00';'00'];

    GAP_DeviceDiscoveryRequest=['01';'04';'FE';'03';'03';'01';'00'];

    dec=hex2dec(GAP_initialise);
    fwrite(s,char(dec)');
    disp('Device initialsation')
    [A,count] = fread(s);
    h=dec2hex(A);

    Kind Regards

    Ehad

  • Hi Ehad,
    Thanks for your fast reponse.
    I did show you the last part of the code.
    But actually I did initialize the GAP using the code provided by you
    and the folowing lines shows the packest I sent and rececived through MATLAB:

    GAP_DeviceInit
    Tx: 01 00 FE 26 08 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00
    Rx: 04 FF 06 7F 06 00 00 FE 00
    Rx: 04 FF 2C 00 06 00 FC DA 09 AF 59 90 1B 00 04 4C 10 E4 75 76 4B FB A4 23 82 9A D8 AD 69 92 3E FB A1 23 82 3A 58 AF 91 32 BD 2F 97 1A DD C5 09
    GAP_GetParam
    Tx: 01 31 FE 01 15
    Tx: 01 31 FE 01 16
    Tx: 01 31 FE 01 1A
    Tx: 01 31 FE 01 19
    Rx: 04 FF 08 7F 06 00 31 FE 02 50 00
    Rx: 04 FF 08 7F 06 00 31 FE 02 50 00
    Rx: 04 FF 08 7F 06 00 31 FE 02 00 00
    Rx: 04 FF 08 7F 06 00 31 FE 02 D0 07
    Send Discovery Request
    Tx: 01 04 FE 03 03 01 00
    Rx: 04 FF 06 7F 06 00 04 FE 00
    Rx: 04 FF 10 0D 06 00 00 00 1A EB A1 E5 C5 78 C9 03 02 01 06
    Rx: 04 FF 1A 0D 06 00 04 00 1A EB A1 E5 C5 78 CA 0D 0C 09 4F 4C 50 34 32 35 2D 45 42 31 41
    Warning: The specified amount of data was not returned within the Timeout period.
    Rx:
    Establish Link Request
    Tx: 01 09 FE 09 00 00 00 1A EB A1 E5 C5 78
    Rx: 04 FF 06 7F 06 10 09 FE 00

    It is clear that the GAP was intialised and there is a response similar to the ones I get from Btool.
    However, the connection request failed.

    I thought that you have done the connection link.

    Regards,
    Asiya

  • Asia,

    This is pretty late, but in case someone else runs into the same problem as you...

    You stated that you get:

    Establish Link Request
    Tx: 01 09 FE 09 00 00 00 1A EB A1 E5 C5 78
    Rx: 04 FF 06 7F 06 10 09 FE 00

    The "10" in your RX means "bleNotReady." This is probably due to the fact that you did not cancel discovery (opcode 0xFE05)

    Also, if you know the device address, I would suggest setting addrTypePeer to 1 (ADDRTYPE_STATIC). So your Establish Link Request should look like: 01 09 FE 09 00 00 01 1A EB A1 E5 C5 78