This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52832 SPI Master

Hi,

I'm facing an issue when communicating to a sensor using Nordic SPI master. The sensor requires nRF52832 to have 2us delay after first byte (address) is transmitted before receive byte (data) from the sensor. Is there any way to insert the 2us delay given Nordic's SPI Master has only continuous SPI clock input? 

Here is my source code and I couldn't find a way to insert the 2us delay between the address and data. Any other workaround is appreciated as well. Thanks. 

uint8_t spi_read ( uint8_t addr)
{
memset(m_rx_buf, 0, m_length); // Reset rx buffer and transfer done flag
spi_xfer_done = false;

nrf_drv_spi_transfer(&spi, &addr, 2, m_rx_buf, 2);

while (!spi_xfer_done)
{
__WFE();
}

return m_rx_buf[1];
}

Parents
  • Hi,

    You can try this:

    1. Transmit the data with nrf_driver_spi_transfer()  and pass a NULL to the receive buffer.
    2. Insert the delay 
    3. Receive the data with nrf_driver_spi_transfer() and pass a NULL to the transmit buffer.

    Chip select should be held low the entire time, the clock signal will only tick when data is exchanged. 

    Best regards

    Jared 

  • Thanks Jared!

    It helped, however I noticed there is around 20us delay in between step(1) and step(3), even I didn't insert any delay in step(2). Is it because of waiting the spi_xfer_done flag to be set in the spi_event_handler after transfer completed? 

     

    void sensor_read(uint8_t addr)
    {
    		spi_xfer_done = false;	
    		nrf_gpio_pin_clear(SPI_SS_PIN);	
    		nrf_drv_spi_transfer(&spi, &addr, 1, NULL, 0);		
    		while (!spi_xfer_done){
                __WFE();}
    						
    		spi_xfer_done = false;		
    		nrf_drv_spi_transfer(&spi, NULL ,0, m_rx_buf, 1);	
    		while (!spi_xfer_done){
                __WFE();}
    		nrf_gpio_pin_set(SPI_SS_PIN);
    }
    
      

Reply
  • Thanks Jared!

    It helped, however I noticed there is around 20us delay in between step(1) and step(3), even I didn't insert any delay in step(2). Is it because of waiting the spi_xfer_done flag to be set in the spi_event_handler after transfer completed? 

     

    void sensor_read(uint8_t addr)
    {
    		spi_xfer_done = false;	
    		nrf_gpio_pin_clear(SPI_SS_PIN);	
    		nrf_drv_spi_transfer(&spi, &addr, 1, NULL, 0);		
    		while (!spi_xfer_done){
                __WFE();}
    						
    		spi_xfer_done = false;		
    		nrf_drv_spi_transfer(&spi, NULL ,0, m_rx_buf, 1);	
    		while (!spi_xfer_done){
                __WFE();}
    		nrf_gpio_pin_set(SPI_SS_PIN);
    }
    
      

Children
No Data
Related