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];
}

  • 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);
    }
    
      

  • I find that using this method to read do a sensor read apart from the 20us delay in between transfer, the receive bytes is also 2 bytes instead of 1 bytes. Although it has been declared to receive 1 byte as following. Does anyone see this and how to fix it so that I could get only 1 bytes instead of 2 bytes? Is this a Nordic bug?

    nrf_drv_spi_transfer(&spi, NULL ,0, m_rx_buf, 1);	

Related