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.

RTOS/CC2640: UART Packet Parsing Issues

Part Number: CC2640
Other Parts Discussed in Thread: CC2540, , SYSBIOS

Tool/software: TI-RTOS

Hey there,

I am developing a custom Observer project which communicates with a Master over UART, however I have been having a lot of trouble properly parsing packets with the included UART driver.  The Master's packet structure consists of a header byte (0x0D), followed by two opcode bytes, followed by two length bytes, followed by the payload.  What I want to do is wait for a header byte and then read the two opcode bytes and two length bytes and then parse the payload based on that.  However, the UART driver only enables RX while in UART_read(), so when I call UART_read() for one byte (header byte), RX gets turned off once that byte is read into the buffer which causes me to lose sync with the Master.  I have tried using the NPI Transport Layer APIs (http://processors.wiki.ti.com/index.php/Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project

This project is aiming to replace an identical application which functions on the CC2540 with the old BLE stack.  The CC2540 project used the HAL UART driver in this way without causing problems.  Is there a way to use the HAL UART driver on the CC2640.  Alternatively, is there a method to read the UART byte-by-byte with no issues?  Thank you.

Regards,

Nick

  • Hi Nick,

    There is an UART Echo example included with the SDK - which does exactly what you think it would, it simply takes a byte received and transmits it back. This could be a good starting point - you can find the code in the resource explorer with CCS, or navigate and open the IAR projects for:

    UART Driver: <SDK>\examples\rtos\CC2640R2_LAUNCHXL\drivers
    More Complex UART Code: <SDK>\examples\rtos\CC2640R2_LAUNCHXL\sysbios
    Even more Complex, you can take a look at our Serial over BLE examples on the github: github.com/.../ble_examples

    The paths might be different depending on which SDK you have installed, but generally speaking they will be included in the installation of TI RTOS or the simplelink SDK.

    Regards,
    Rebel
  • Hi Nick Elsmore,

    Why do you lose sync with Master? You can do it:
    Solution 1: If you know the packet length exactly. You can use uart callback with the packet length.

    Solution 2: If you can't know the packet length exactly. You can use a circular buffer
    - Config a serial task for Uart read for one byte. Then this task go to sleep and wait for wake up by uart callback
    - Uart callback is appeared. Store rx data to the circular buffer. Wake up the serial task.
    - After wake up, the serial task will be check data in the circular buffer to process.
    - After process, the serial task will config the uart read for one byte. Then this task go to sleep and wait for wake up by uart callback
  • Thank you for the replies Rebel and Vy.  Turns out the issue (and a lot of other confusing ones) was caused by a missing component on our custom hardware forgotten by the manufacturer.  Everything is functional now using NPI transport layer.

  • Awesome! Thanks for reporting back - which manufacturer? (so other users can find this maybe?)

    Regards,
    Rebel
  • I often have to face this :). So I usually do with the development kit to make sure everything. It will help to find the cause easier