SPI and RTC Issues within BLE Service Handler on nRF52832

I'm currently working on a project using the nRF52832 as my controller, Segger Embedded Studio version 5.42a as my IDE, and the nRF5 SDK 17.0.2. I started by developing a concurrent central and peripheral switching example project. I've added NUS client and peripheral functionalities and integrated a W25 Winbond external flash memory using SPI, along with the internal RTC. The RTC interrupt priority is 3, and the SPI interrupt priority is 6.

My issue is that when I write data to the external flash memory and then attempt to start the internal RTC within a BLE service event handler, the SPI channel appears busy, and the data is not correctly written to the external flash.

To address this, I implemented a flag system. Inside the BLE service event handlers, I set specific flags when corresponding events occur. In my main loop, I check these flags. If a flag is set, I then perform the operations like writing to/reading from the external flash and setting the date and time in the internal RTC.

This approach works.

My question is: What's likely happening here? Do BLE event handlers have a high interrupt priority? Are peripherals like SPI and RTC excluded from functioning during the execution of these event handlers?

  • Hi,

    First of all, I would advice against using the nRF5 SDK for new product development. It has not been updated for a long time, and the SDK that is recomended now and going forward is the nRF Connect SDK (see nRF Connect SDK and nRF5 SDK statement). And if you still want to use the nRF5 SDK, I would advice that you use the latest, 17.1.0, as that has support for the latest generation of the nRF52 series devices, which are not supported in SDK 17.0.2 and earlier.

    That asside,

    What's likely happening here? Do BLE event handlers have a high interrupt priority?

    Yes, the SoftDevice have high priority Bluetooth interrupts. You can read more about the priority and durations etc under Interrupt model and processor availability. It is possible to be allocated time slots where the application is guaranteed no SoftDevice interrupts by using the Timeslot API if needed.

    Are peripherals like SPI and RTC excluded from functioning during the execution of these event handlers?

    No, they are not. The peripherals will continue to function, but related interrupts are not processed before higher lever interrupts have been processed. So in the case of SPI, you want to make sure you are using SPIM (which has DMA) so that the CPU is not needed during the transaction, only for intitating it and processing Rx data after it is done.

Related