Hi,
I have an application where I use nrfx_saadc for getting some samples and I also run the st7735 driver, modified to use nrfx_spim instead nrf_drv.
For the nrfx_saadc code, I have used the example described in: https://github.com/NordicSemiconductor/nrfx/wiki/SAADC-Advanced-mode-with-IRQs
The spi driver using nrfx_spim I wrote is quite simple, to be able to use more stuff.
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "eeprom.h"
#include "nrfx_spim.h"
#define SPI_PIN_UNUSED NRFX_SPIM_PIN_NOT_USED
typedef struct {
uint8_t miso;
uint8_t mosi;
uint8_t clk;
} spi_pindef_t;
void spi_init(const spi_pindef_t pins);
void spi_xfer(uint8_t user_cs, uint8_t * tx_data, uint16_t tx_size, uint8_t * rx_data, uint16_t rx_size);
static const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(2);
// We allocate memory for the biggest eeprom just in case
static uint8_t rx_buf[EEPROM_SIZE_CAT25040 + 3];
void spi_init(const spi_pindef_t pins) {
nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
// SS is not init because we will use a different CS depending on the device
spi_config.ss_pin = NRFX_SPIM_PIN_NOT_USED;
spi_config.miso_pin = pins.miso;
spi_config.mosi_pin = pins.mosi;
spi_config.sck_pin = pins.clk;
APP_ERROR_CHECK(nrfx_spim_init(&spi, &spi_config, NULL, NULL));
}
void spi_xfer(uint8_t user_cs, uint8_t * tx_data, uint16_t tx_size, uint8_t * rx_data, uint16_t rx_size) {
if(user_cs != NRFX_SPIM_PIN_NOT_USED) {
nrf_gpio_pin_clear(user_cs);
}
nrfx_spim_xfer_desc_t xfer_desc = {
.p_tx_buffer = tx_data,
.tx_length = tx_size,
.p_rx_buffer = rx_buf,
// Account for that the data needs to be clocked out
.rx_length = rx_size + tx_size,
};
APP_ERROR_CHECK(nrfx_spim_xfer(&spi, &xfer_desc, 0));
if(user_cs != NRFX_SPIM_PIN_NOT_USED) {
nrf_gpio_pin_set(user_cs);
}
for (uint8_t i = 0; i < rx_size; i++) {
rx_data[i] = rx_buf[tx_size + i];
}
}
The only thing I changed from the original st7735.c at
static inline void spi_write(const void * data, size_t size) {
spi_xfer(_pins.cs, data, size, NULL, 0);
}
Once I've used the saadc for a single conversion, spi stops to work, when I use the debugger it gets 'trapped' inside the spi driver. In a task that if I don't use the adc, works no problem.