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

should I set SPI master priority to NRF_APP_PRIORITY_HIGH when using with SoftDevice

I have an application which uses SPI to communicate with ADC.

when I don't use SoftDevice and use nrf_drv_timer to start conversion periodically it works

but when I use SoftDevice and use app_timer which need the softDevice enabled to work (i'm I mistaken?) I got false conversions

with SoftDevice : when I initialise SPI first and then SoftDevice it doestn work when I initialsie SoftDevice first and then initialsie SPI at the end, the SPI seems to work (the spi_master_evt_handler is executed after spi_master_send_recv completed, can see my led toggle) but then I got false ADC conversion so I think there is something wrong with the SPI

I tried to put the spi_master_evt_handler code in main code and just just put flag on the handler but still not working

now when I try to set spi_instance.SPI_PriorityIRQ = NRF_APP_PRIORITY_HIGH; according to this link my program freeze (I think spi_master_evt_handler is not called)

so is spi_instance.SPI_PriorityIRQ = NRF_APP_PRIORITY_HIGH mandatory when using Softdevice and why it's not working in my case

notice then in my program I just called ble_stack_initand without setting softdevice_ble_evt_handler_set (I just enabled soft device (sd_ble_enable))

Parents
  • Hi,

    You don't need the SoftDevice to use app_timer, see here for a tutorial on app_timer.

    The spi_master driver actually requires the SoftDevice to be enabled to work if the SoftDevice is present. This is not well written. In SDK 10 we have a ned SPI driver called nrf_drv_spi, which seems to not require this. I would recommend to use this as it seems that the spi_master driver have some other issues as well.

    Anyhow, the spi_master_send_recv() function includes some SoftDevice calls. You cannot do a SoftDevice call from APP_PRIORITY_HIGH, then the application will run into hardfault. Therefore setting the interrupt priority to APP_PRIORITY_HIGH will not work. It should however work if you set a flag in the event handler and do the calls in main.

    I don't know why the data is not correct, but I advise you to check the lines with a logic analyzer or an oscilloscope to see what is really going on. The problem may be if you do the SPI function calls in interrupt context. The SPI data handling is also done in interrupt context. You could try to do the reading in main instead?

    If it is possible, use nrf_drv_spi from SDK 10 instead.

    Ole

  • This question should be in an own post with more information, not in the comment section here.

Reply Children
No Data
Related