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 Pablo,

    Sorry for late reply. As your reply arrived in weekend.

    Looking at the part of codes (as not the complete project) I have few comment: -

    Normally no code being run from header files so I am just thinking how it gets stuck in the header files. 

    It seems like nrf_spim.h:560 is a check for an event, but it should not get stuck there. 

    May be it gets stuck somewhere else if the driver that uses this function to wait for an event that is never generated.  

    If it is possible you can send the complete project.

    BR

    Kazi Afroza Sultana

Reply
  • Hello Pablo,

    Sorry for late reply. As your reply arrived in weekend.

    Looking at the part of codes (as not the complete project) I have few comment: -

    Normally no code being run from header files so I am just thinking how it gets stuck in the header files. 

    It seems like nrf_spim.h:560 is a check for an event, but it should not get stuck there. 

    May be it gets stuck somewhere else if the driver that uses this function to wait for an event that is never generated.  

    If it is possible you can send the complete project.

    BR

    Kazi Afroza Sultana

Children
  • Hi Kazi,

    I had put the code into the same snippet for convenience, but is not a single header file, sorry for the confusion.

    I don't want to share the entire project.

    Is there any configuration (visible in the already shared code snippers) that I've done to the NRFX_SPIM and NRFX_SAADC that is not compatible or might be prone to error, given the pinout used in my project ?

    Do the NRFX_SAADC and NRFX_SPIM share any resource that should be handled differently ? Is any of the NRFX_SAADC config code "overwriting" in some how something that has been configured by the NRFX_SPIM before ?

    BR

Related