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

SPI inconsistent read

Hello ! When I make a read with the SPI from a sensor's register the data sometimes comes correct and most of the time wrong. I tested the read operation with an Arduino and it always comes correct. Why is that problem ? I am using NRF51822 with s130, softdevice enabled.

  • May be problem with the clock speed. If the sensor can't operate at high speed and the clock in the mater is high then you get the problem in reading. try to check with the low frequency as possible.

  • Hello ! Thank you for your answer. I set the frequency of the SPI bus to the lowest possible. The problem persists for every frequency that I choose.

  • Hi Robert, SPI in nordic chip is known to work correctly (I have not seen any issues) Are you using SDK SPI drivers or are you using your own SPI code? Are you sure you have configured the SPI to right mode?

  • Hello ! I am using nrd_drv_spi. In the spi function I believe I made the right configuration. This is my configuration:

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
    spi_config.sck_pin = SPI_SCK_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.ss_pin = SPI_CS_PIN;
    spi_config.irq_priority = APP_IRQ_PRIORITY_HIGHEST;
    spi_config.frequency = NRF_DRV_SPI_FREQ_250K;
    error1 = nrf_drv_spi_init(&spi, &spi_config, spi_update_imu_data);
    

    Where error1 is NRF_SUCCESS, and all the macros for the pins have been checked and are the correct ones.

  • you are using NRF_DRV_SPI_MODE_0 , can you make sure if the polarities are matching your SPI device. Apart from that i cannot see anything wrong with your configuration.

1 2