This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to properly configure periodic SPI transfers with PPI and TIMER?

I'm working on a BLE application based on the Zephyr RTOS. I need to read a SPI device at fixed time intervals and, as already suggested me here at point 3, I'm trying to implement a PPI channel that connects the TIMER0 event to the SPI task. I wrote a simple code just to test this feature but it' doesn't work, sure cause I lost something:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <zephyr.h>
#include <logging/log.h>
#define LOG_MODULE_NAME main
LOG_MODULE_REGISTER( LOG_MODULE_NAME );
#define SCK_PIN 0x04
#define MISO_PIN 0x1D
#define MOSI_PIN 0x1C
#define CS_PIN 0x03
static const nrfx_timer_t timerInst = NRFX_TIMER_INSTANCE( 0 );
static const nrfx_spim_t spiInst = NRFX_SPIM_INSTANCE( 0 );
static const nrfx_spim_config_t spiConfig = NRFX_SPIM_DEFAULT_CONFIG( SCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN );
nrf_ppi_channel_t readingPpiChan;
static uint32_t readingTaskAddr;
static uint32_t readingEventAddr;
static uint8_t tempBuff[ 2 ];
static uint8_t tempReg;
void Timer_Handler( nrf_timer_event_t event_type, void *p_context )
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have some doubts:

1) Here it describes that if I wanto to use the NRFX_SPIM_FLAG_HOLD_XFER flag I must to set the chip select pin as NRFX_SPIM_PIN_NOT_USED and manage it outside the driver. How I should do it if the tranfers are supposed to be autonomous?

2) To generate the TIMER0 event in the PPI can I set false the enable_int parameter in the nrfx_timer_compare function or I have to set it as true? Because if I enable the interrupt, the Zephyr OS crash and restart the chip.

What am I doing wrong? Can you help me?