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.

HostTestRelease using SPI - how is it even possible?

Other Parts Discussed in Thread: CC2541, CC2540

I can build the HostTestRelease project from BLE 1.4, and I can set HAL_UART_SPI=1 in the preprocessor defines in order to use P0_2 as MISO and P0_3 as MOSI. And I can build this for a CC2541 key fob.

That's all fine, but I fail to understand how the HCI protocol can be run over SPI. The HCI protocol relies on the slave returning events to the host. Over a UART interface, which is asynchronous and self-clocking, this is easy. But in SPI, the master provides the clock, and the master must clock data out of MOSI while it expects to clock data in over MISO. In SPI, the data is not framed (there is no defined 'start' bit), so there's no such thing as "no data" - the SPI interface will always clock in _something_, by default the last byte written into the slave's SPI data output register.

So, is it incumbent on the master (the host processor) to continually clock data out of MOSI in order to clock event data into MISO, while ensuring that the data clocked out is innocuous (so long as it is not a command), and incumbent on the slave to ensure that after putting valid data into its SPI output buffer it terminates each status or event block with something which the master can discard?

  • Hi Stuart,

    I'm in the same situation as you, I'm trying to use the CC2541 with the HostTestRelease code configured to use SPI as a Network Processor. I haven't got it working yet but one thing I have spotted in the file _hal_uart_spi.c is a comment: "Implementation of a specialized SPI Transport driver for emulating a UART API". There are also comments about a frame around the data. I haven't seen any documentation outside of the code for this.

    Does anyone know if there is any documentation for the SPI protocol used by the BLE stack HAL code?

    Rgds,

    Paul

  • Stuart Smith said:

    I can build the HostTestRelease project from BLE 1.4, and I can set HAL_UART_SPI=1 in the preprocessor defines in order to use P0_2 as MISO and P0_3 as MOSI. And I can build this for a CC2541 key fob.

    That's all fine, but I fail to understand how the HCI protocol can be run over SPI. The HCI protocol relies on the slave returning events to the host. Over a UART interface, which is asynchronous and self-clocking, this is easy. But in SPI, the master provides the clock, and the master must clock data out of MOSI while it expects to clock data in over MISO. In SPI, the data is not framed (there is no defined 'start' bit), so there's no such thing as "no data" - the SPI interface will always clock in _something_, by default the last byte written into the slave's SPI data output register.

    So, is it incumbent on the master (the host processor) to continually clock data out of MOSI in order to clock event data into MISO, while ensuring that the data clocked out is innocuous (so long as it is not a command), and incumbent on the slave to ensure that after putting valid data into its SPI output buffer it terminates each status or event block with something which the master can discard?

    I have only used HostTestRelease with async UART, but a quick check of the source points towards _hal_uart_spi.c which defines SPI_RDYOut and SPI_RDYIn pins on  P0_5 and P0_1 respectively. My thoguhts are these are flow control lines and SPI_RDYOut would be set when the slave has data to send which can trigger / wakeup the master who would then clock the data bytes out until SPI_RDYOut returns low

  • Ah, thank you for pointing me at that file. I didn't scroll to the top of it where it helpfully says:

    Description: Implementation of a specialized SPI Transport driver for emulating a UART API.


    The SPI frame format is
    <SOF> <LEN> <DATA Byte 1> < DATA Byte2 >...<DATA Byte N> <FCS>

    5 GPIO lines are required: MOSI, MISO, SPI Clock, SPI CSn/MRDY, and SRDY.
    MRDY/CS = SPI Master Ready to send and serves as a SPI Slave wakeup from sleep.
    SRDY = SPI Slave Ready to send and serves as a SPI Master wakeup from sleep.

    So, indeed, one more line is required, and the other side of the SPI interface requires a higher layer of software which wraps/unwraps the payload (DATA Byte 1...DATA Byte N) in a frame. Additionally, one would have to ensure that the master never sends a SOF byte while it is simply reading from a slave. And surely something must ensure that the slave does not set the SRDY bit while the master is sending a frame?

    Someone else asked if this is documented - it looks like all the documentation is in the code. Now that I've read the comment at the top the rest of it makes a great deal more sense.

  • Hi Eng351,

    I am a newbie to bluetooth programming. I have to interface the pan module to external microcontroller via UART. I tried flashing the Host Test Release CC2541EM firmware to the pan module according to some links in this forum.

    But unfortunately after flashing, i am not able to detect the bluetooth device on the App. 

    Can you please guide me in the right direction to make the UART communication works.

    Thanks in Advance

    Krishna

  • Hi, 

    How did you flash the code on the PAN module?

    Are you using CC Debugger with DC,DD pins or custom hardware?

    Did you flash the .bin file with SmartRF Flash programmer or use the hostTestApp project, through IAR?

    Let us know, to support you better.

    Regards,

    Vijay

  • One more question,

    How are you trying to detect the device?

    Are you using BTool+CC2540 USB dongle[ with hosttestrelease.hex file pre-flashed] or using Iphone/Android phone with BLE support?

    Regards,

    Vijay

  • Hello Vijay,

    Thanks for the quick reply.

    I am using CC debugger to flash the firmware. I  have flashed the host test release hex file via smart rf flash programmer.

    Yes, im using the  BTool+CC2540 USB dongle[ with hosttestrelease.hex file pre-flashed].

    Have also tried the serialBLE bridge as in the TI wiki page  http://processors.wiki.ti.com/index.php/SerialBLEbridge 

    i am able to flash and make it advertise but i dont know how to test the serial communication whether its transmitting properlly or not? please dont mind if the question is stupid/silly. i am really stuck at this point.

    Please help me out.

    Thanks in advance

    Krishna

  • Hi,

    Can you let me know the PAN module part no. and send the datasheet link?

    Are you using USART mode or SPI mode for communication?

    If you are using USART mode, you will have to configure the corresponding USART that you are using[ UART0 or1] based on what is available in your module[ ref pages 73-74 of CC254x user guide for more info].

    You can use a USB-UART converter[ which should have TTL 3.3v mode supported].

    Connection will look as below.

    PAN Module<-------> USB -UART Board<----------->PC.

    Regards,

    Vijay

  • Hello Vijay,

    We are using PAN 1721 TI which has cc2541 embedded in it and the link for te same is given below   http://na.industrial.panasonic.com/sites/default/pidsa/files/panasonic_pan172x_design_guide.pdf

    Yeah i am using USART Mode and i have configured UART0 according to the CC254x user guide.

    I am providing my block diagram flow for your reference

                                                                BLE connection                                                         UART

    CC2540 USB Dongle (Btool)----------------------------------->PAN1721(cc2541)------------------------->EXT MCU Unit

    I have to get the data from the external micro controller to PAN1721 via UART and display it on the PC with the help of Btool and CC2540 USB dongle (for ble connection).

    I hope im clear about my requirement. Please reply me if any more details required in this regard.

    Regards,

    Krishna