[help me]SPI Commnunication btw nRF52 series and intanRHD2132, SPIM + TIMER

I am implementing SPI communication between the intanRHD2132 (ADC) and nRF52840.

I need to periodically send commands (READ, WRITE, etc.) to the intanRHD2132 (ADC). To achieve this, I am using a TIMER to control the SPI communication.

The commands need to be sent in 16-bit units (I will attach the datasheet for the intanRHD2132, refer to pages 15-16).

Here is a summary of my code:
- The TIMER handler is executed at intervals defined by TIME_TO_WAIT_US. SPI communication occurs within the TIMER handler.
- In the SPI communication handler function, the buffer value is replaced to send the next command.

However, I encountered a few issues. When I set the value of TIME_TO_WAIT_US to 42 or less, a 'spi transfer failed' error occurs. I want to set the TIME_TO_WAIT_US value between 1-10. I am curious about the cause of the issue and if there is any solution for this?

Here is the relevant part of my code:

#define TIME_TO_WAIT_US 5

static void spim_handler(nrfx_spim_evt_t const * p_event, void * p_context)
{
    if(num==30){
        cleanup_spi(spim_inst.p_reg);
    }

    int index=0;

    if (p_event->type == NRFX_SPIM_EVENT_DONE)
    {  
        num++;
        index = 2*(num-1);
        M_tx_buffer[0]=Command[num][0]; M_tx_buffer[1]=Command[num][1];
        result[index]=M_rx_buffer[0]; result[index+1]=M_rx_buffer[1];
    }
}

void send_16bit_data() {
   
    nrfx_err_t err_code = nrfx_spim_xfer(&spim_inst, &spim_xfer_desc, 0);
    if (err_code != NRFX_SUCCESS) {
        NRFX_LOG_ERROR("SPI transfer failed: %d", err_code);
    }
}

static void timer_handler(nrf_timer_event_t event_type, void * p_context)
{  
    if(num==30){
        cleanup_timer(&timer_inst);
    }
    if(event_type == NRF_TIMER_EVENT_COMPARE0)
    {  
        NRFX_LOG_INFO("num %d>> tx: 0x%02x%02x",num, M_tx_buffer[0], M_tx_buffer[1]);
        send_16bit_data();
    }
}

6518.Intan_RHD2000_series_datasheet.pdf

Parents Reply Children
No Data
Related