[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
  • "Thank you so much for your response. I am applying PPI and making some adjustments.

    I have a few questions that are different from the original post's topic.

    1. The person in the link you provided uses 'nRF5_SDK,' right? It seems to me that 'nRF5_SDK' is often used with 'SEGGER Embedded Studio'.

    2. Is the difference between 'nRF Connect SDK' and 'nRF5_SDK' just that one is the newer version and the other is the older version? Sometimes it's really confusing and difficult when looking at different versions of the code. There's no clear place that explains these concepts, so I'm asking you."

  • Hi,

     

    For new projects, we recommend that you use nRF connect SDK (ncs):

    https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/

     

    seongmincho said:

    1. The person in the link you provided uses 'nRF5_SDK,' right? It seems to me that 'nRF5_SDK' is often used with 'SEGGER Embedded Studio'.

    Yes, but the low level nrfx APIs are quite similar (almost identical).

    seongmincho said:
    2. Is the difference between 'nRF Connect SDK' and 'nRF5_SDK' just that one is the newer version and the other is the older version? Sometimes it's really confusing and difficult when looking at different versions of the code. There's no clear place that explains these concepts, so I'm asking you."

    Both nRF5 SDK and NCS runs on the same hardware, so there will be similarities in the low level APIs.

    As mentioned, we do recommend that you use NCS for new projects.

     

    Kind regards,

    Håkon

  • Hello! I have programmed new code based on your advice. Thank you for your help.
    As a result, the minimum value of 'TIME_TO_WAIT_US' has been reduced from 43us to 13us. However, there is still room for improvement. I need the value to be smaller than 13us('TIME_TO_WAIT_US'). It seems that I am not utilizing the buffer effectively. Could you please review the code and suggest any necessary modifications?

    Here are the requirements I need to implement:

    - Send a 16-bit command to the ADC via SPI. (receive the 16-bit data to the nRF52840 via SPI)
    - The 16-bit command must be sent at regular intervals defined by TIME_TO_WAIT_US.

    Could you advise on how to manage the variables uint8_t Command[30][2] and uint8_t result[70] more efficiently in the code?



  • Hi,

     

    When using easydma list, it will auto-increment your pointers for each transaction. You should setup a buffer that is as large as your overall transfer on both RX and TX.

    Instead of using m_tx_buffer/m_rx_buffer as the EasyDMA buffers, you should use Command (declare it as a 1-d array instead of 2-d array) / result.

     

    Kind regards,

    Håkon

  • Thank you for your kind response. I've decided on the next course of action

Related