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

Can not get SPI control back after PPI?

Hello,

I am trying to implement a clean shutdown process, but running into some issues. The flow of the SPI use is as listed here:

  1. Initialize SPI instance and program connected peripheral device via SPI. The calls being used are nrf_drv_spi_init and nrf_drv_spi_transfer with interrupt handler to check spi_tx_done flag. This works fine.

  2. Switch to PPI after everything is setup, the interrupts of the SPI instance is disabled using nrf_spim_int_disable. Transfer is started and held using nrf_drv_spi_xfer with the no_event and on_hold flags. PPI channel assigned and enabled. This also works fine.

  3. I'd like to issue a shutdown command to the peripheral device for a clean system power down.

3a) So first I disconnected all BLE connections, and stopped some ble services.
3b) Then I disabled the PPI channels, trigger sources and some timers used.
3c) Then I try to enable the interrupts and get back the CS control (CS is fine), but anything else I do with this SPI instance hangs the system (as I have a checker in the main loop), and system shutdown is commented out currently, for example, enabling interrupts back hangs the system, do a spi transfer hangs the system even bypassing while(!spi_tx_done) with a delay, uninitialization and initialization of the SPI does not hang the system, and appears to be working, since the enabled interrupts are at default if the instance is uninitialized. What could causing issues for this usage? What should I check into?

Any help is greatly appreciated.

Thanks

FI

  • Yes, I use nrf_drv_spi_uinit, just for test and debug this issue. After a little more checking, the issue appears to have something to do with Interrupts, I used nrf_spim_int_disable to disable interrupts in SPIM-PPI mode, and when getting back the control, I first tried to use nrf_spim_int_enable call to set interrupt enable with corresponding masks, but this seems to cause issue, I then used nrf_spim_int_disable with an all-zero mask, this seems to get the program going, at least the subsequent SPI read and writes would not hang in the while loop waiting for xfer_done flag, or return error with Busy_State if the while is bypassed. So, is it correct that the actual "Enable" and "Disable" is done by just the nrf_spim_int_disable call, and masked differently?

Related