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

nrf51822 SPI timing

Hi, 

I working on a project that need to communicate with other mcu by SPI, the communication is work, but I have question about the start and stop of communication.

The version now using is: nrf51822, s130, SDK12.

SPI setting: master, 125KHz

Attached is the timing from logic analyzer.

Logic view

Q1: After the chip select go LOW, about 25us later, the clock start. Is this time fixed or can make it shorter ?

Q2: When clock finish, about 17us later, chip select go HIGH. Also, is this time fixed or can make it shorter ?

Thank You !!

Parents
  • (a) I see no good reason to develop for Nrf51822 today. Nrf52810 is cheaper and MUCH more powerful. Check it out.

    (b) That said, the delays you observe are in the low hundreds of CPU cycles and can well be due to software latency in the library and in your code. I do not think they are deliberate in the SDK, but maybe in some other code you are using? Without a code snippet, impossible to tell. By optimisation or by writing your own integrated driver, you might be able to reduce this latency, but never get completely rid of it.

Reply
  • (a) I see no good reason to develop for Nrf51822 today. Nrf52810 is cheaper and MUCH more powerful. Check it out.

    (b) That said, the delays you observe are in the low hundreds of CPU cycles and can well be due to software latency in the library and in your code. I do not think they are deliberate in the SDK, but maybe in some other code you are using? Without a code snippet, impossible to tell. By optimisation or by writing your own integrated driver, you might be able to reduce this latency, but never get completely rid of it.

Children
  • Hi niebert, 

    Thank you for your reply.

    And the code is from spi example in SDK12.2: 

    int main(void)
    {
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    
        NRF_LOG_INFO("SPI example\r\n");
    
    	nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin   = SPI_SS_PIN;
        spi_config.miso_pin = SPI_MISO_PIN;
        spi_config.mosi_pin = SPI_MOSI_PIN;
        spi_config.sck_pin  = SPI_SCK_PIN;
    		
    	spi_config.frequency = NRF_DRV_SPI_FREQ_125K;
    	spi_config.mode = NRF_DRV_SPI_MODE_3;
    	spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_LSB_FIRST;
    		
    //    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL));
    
    	m_tx_buf[0] = 0x5A;
    	m_tx_buf[1] = 0x16;
    	m_tx_buf[2] = 0x01;
    	m_tx_buf[3] = 0x80;
    	m_tx_buf[4] = 0x00;
    
        while (1)
        {
            // Reset rx buffer and transfer done flag
            memset(m_rx_buf, 0, m_length);
    //        spi_xfer_done = false;
    
    		APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, 5, m_rx_buf, 5));
    
    //        while (!spi_xfer_done)
    //        {
    //            __WFE();
    //        }
    
            nrf_delay_ms(1000);
        }
    
    }

    without the softdevice, the delay is little bit shorter.

    I trace the code nrf_drv_spi.c and can't know where the time is come from.

    Thanks. 

Related