This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Error after transmit complete event in SPI + SoftDevice enabled

Hello,

I am really new to using the Nordic nRF51822 and I'm having problems making SPI work with the S110 SoftDevice. I was able to combine the sample codes spi_master_example and ble_app_hrs. I created some custom service and wish to read some data from a sensor over SPI when a certain data is sent to the Nordic chip over the custom service. All the BLE communication are working correctly, but once I send data over SPI to the sensor, the code gets stuck in the error handler. Before the code jumps to the error handler, I can receive the SPI_MASTER_EVT_TRANSFER_COMPLETED event indicating that the SPI transfer was a success. I can also see the data sent over SPI using an oscilloscope. But after the transfer complete event, the BLE no longer works and the system just hangs within the error handler.

I have tried reading everything about SPI in this forum, but I didn't find anything that can solve my problem. Has anybody encountered this problem previously? Any clues to solving it?

Is there a good sample code for using the SPI master peripheral together with the S110 SoftDevice? Most sample I found are for the I2C or UART. A good working SPI + S110 SoftDevice sample code will help greatly.

I followed the following information from the link https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00006.html to add the SPI support to the ble_app_hrs project.

Regards,

Leo

Parents
  • Try this code out.

    • Make sure you call SPI init procedures after ble_stack_init() call. Take the code piece by piece, this code works for me.

    Take a look on this link for simple source code:

    PasteBin S110+SPI

  • Sorry to resurrect an old thread but I have run into the same problem, and have followed the code suggested above. 

    the problem for me is that I am not sure where to call send_data(). 

    I am wanting to read data from an accelerometer periodically, and have tried to call send_data in rsc_meas_timeout_handler(). 

    however, when I do this the spi_master_event_handler() never gets called, so I think something is either blocking the interrupt somewhere or it has been disabled but I can't find where... 

  • This sounds like an interrupt priority issue, make sure that the SPI interrupt priority is at least the same as the timer priority, or alternatively, call the SPI transfer from the main loop instead of interrupt. (Can be done with the scheduler)

  • SPI interrupt is set to APP_IRQ_PRIORITY_LOW, and so is the RTC: 

    #define RTC1_IRQ_PRI            APP_IRQ_PRIORITY_LOW  

    #define SWI0_IRQ_PRI            APP_IRQ_PRIORITY_LOW

    How to use the scheduler to call from the main loop? 

Reply
  • SPI interrupt is set to APP_IRQ_PRIORITY_LOW, and so is the RTC: 

    #define RTC1_IRQ_PRI            APP_IRQ_PRIORITY_LOW  

    #define SWI0_IRQ_PRI            APP_IRQ_PRIORITY_LOW

    How to use the scheduler to call from the main loop? 

Children
No Data