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.

SPI on CC2541, a good working example?

Other Parts Discussed in Thread: CC2541

Hi. There is quite a few examples of SPI on the CC2541 but I'm struggling to get any working. I have based most of my work on this: 

http://processors.wiki.ti.com/index.php/SerialBLEbridge 

As I don't have an up to date version of IAR (8.20.2) I need to use this version rather than the suggested 1.4.1.

 

I've managed to get HalUARTWrite working (checked on a scope) once I added HAL_SPI_MASTER to the project defines but I can't get SPI read to work.

 

It seems like the project isn't working for SPI. Am I doing something wrong?

 

Does anyone have a working project they could share, either based upon BLE_BRIDGE or SIMPLEBLEPERIPHERAL?

 

Thanks

  • Hello Martin,

    Have you looked at the KeyFob demo project which uses SPI? Are you using BLE 1.4.0 or 1.4.1? As stated in the release notes, IAR 9.10.3 was used for 1.4.1, so I'm not sure how the older IAR will work with this release as it wasn't tested.

    Best wishes
  • Does your CC2541 act as SPI master or slave?
  • I can confirm that the processors.wiki.ti.com/.../SerialBLEbridge demo works as intended.
  • Thanks for all of the help.

    @TimC, if the serialBLEbridge demo works as intended for SPI, can you confirm that if I connect MOSI to MISO without a "real" SPI slave, will that allow me to confirm that HALUARTwrite and HALUARTread are working i.e. the written data will be echoed back in a read? Can you comment on why I needed to add HAL_SPI_MASTER to the defines to get HALUARTwrite to work?

    @YKChen - I'm want to use SPI in master mode.

    @JXS - thanks for the suggestion of looking at the keyfob demo. I'll see if that helps. My understanding is that's not using the HAL? I can't open the 1.4.1 bridge demo as it uses a later version of IAR. I'm relucant to try and port it back to my version of IAR as that may just introduce more problems.
  • Thanks again. So an update...

    I can get the master sample working in the link you gave above (CC2541_43_44....) after realising that the comments at the start of spi_master_send.c were incorrect:

    - MISO: P0_2 (PIN9 on Debug Connector P18)
    - MOSI: P0_3 (PIN11 on Debug Connector P18)
    - SSN: P0_4 (PIN13 on Debug Connector P18)
    - SCK: P0_5 (PIN15 on Debug Connector P18)
    - GND: (PIN20 on Debug Connector P18)

    ... should have been:

    - MISO: P0_2 (PIN5 on Debug Connector P1)
    - MOSI: P0_3 (PIN7 on Debug Connector P1)
    - SSN: P0_4 (PIN3 on Debug Connector P1)
    - SCK: P0_5 (PIN1 on Debug Connector P1)

    .. so now I can talk to my external slave SPI device and control it. Good news.

    Question 1: I now want to integrate that test code with the BLE code. My worry is that accessing the SPI will block the BLE processes. Is there a preferred way to make these two operations co-exist? I'll be regularly access the SPI device. I had thought that using the HAL within simplebleperiperal may have helped with this - but that was just a guess. Any comments would be appreciated.

    Question2: For the record, I also re-tried the 1.4.1 version of BLE_BRIDGE after downloading the evaluation version of iar 9.30.3.

    I can't get this working properly. What happens is as follows:

    I have built the code using either HAL_UART_SPI=1 or UAL_UART_SPI=2. When I run the code I see the BLE device advertised as BLEBRDG. I then connect to the BLE device and write some values to characteristic 3 - such as 0x05, 0x01, 0x02, 0x03, 0x4, 0x5. This correctly triggers the sendDataToHost function in serialinterface.c. However, when I try and send more data - such as 0x04, 0x01, 0x02, 0x03, 0x0x4 - the HalUARTWrite function fails to send any bytes. I know this as I've set a breakpoint on the "return 1" value (see below). I'm at a loss to know why this fails. I don't have a scope available (working at home) to see if the first SPI write worked. Can anyone suggest what might be wrong? Do I need to do something with SRDY to make this all work? (The SPI code I have working above worked when I just connected MISO to MOSI, which is a useful check).

    Thanks

    uint8 sendDataToHost(uint8* data, uint8 len)
    {
      uint8* buf = osal_mem_alloc((2+len)*sizeof(uint8));
      if (buf)  //if allocated
      {
        buf[0] = SERIAL_MSG_START_ID;
        buf[1]= SERIAL_DATA;
        osal_memcpy(&buf[2], data, len);
        uint8 bytes_sent = HalUARTWrite(NPI_UART_PORT, (uint8*)buf, len+2);
        osal_mem_free(buf);
        if (bytes_sent == len + 2)
        {
            return SUCCESS;
        }
        else
        {
          return 1;  //data not sent over UART
        }    
      }
      else
      {
        return bleMemAllocError;
      }
    }

  • SPI communication usually takes some milli-seconds and should not block BLE communications.