nrfx_saadc crashing nrfx_spim using st7735 tft

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

components/drivers_ext/st7735/st7735.c
is :
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.

Parents
  • Hello,

    It may not be seen obvious issues from the snippet; However there are some configuration and relevant parts missing from the post, for example- the value of NRFX_SAADC_CONFIG_IRQ_PRIORITY / NRFX_SPIM_DEFAULT_CONFIG ,

       

    How SPI transfers and SAADC sampling are triggered (could be interrupt priority issues), etc. 

    A few things that could potentially cause issues:

    1. We can see from your snippet that you have set AIN3 pin for SADDAC (nrfx_saadc_channel_t tuner_ch   = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, 0)). This pin is by default used for RTS pin on DK if project initializes the UART library and driver (Nordic Semiconductor Infocenter).

    2. Pin 16 to 18 (P0.16 to P0.18) is used for SPI in  your code. But these are used for LEDs and Buttons on the DK. This may be an issue if Board Support package (BSP) is initialized in the project.

    Best Regards,

    Kazi Afroza Sultana

Reply
  • Hello,

    It may not be seen obvious issues from the snippet; However there are some configuration and relevant parts missing from the post, for example- the value of NRFX_SAADC_CONFIG_IRQ_PRIORITY / NRFX_SPIM_DEFAULT_CONFIG ,

       

    How SPI transfers and SAADC sampling are triggered (could be interrupt priority issues), etc. 

    A few things that could potentially cause issues:

    1. We can see from your snippet that you have set AIN3 pin for SADDAC (nrfx_saadc_channel_t tuner_ch   = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, 0)). This pin is by default used for RTS pin on DK if project initializes the UART library and driver (Nordic Semiconductor Infocenter).

    2. Pin 16 to 18 (P0.16 to P0.18) is used for SPI in  your code. But these are used for LEDs and Buttons on the DK. This may be an issue if Board Support package (BSP) is initialized in the project.

    Best Regards,

    Kazi Afroza Sultana

Children
No Data
Related