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

SPI doesn't work in nrf52810 while emulating nrf52810 in nrf52832DK was successful

Our project is to read the gyro (lis3dh) by using SPI communication.

Since the infocenter says that using nrf52832 for developing nrf52810 is okay.

We currently developed codes by using nrf52832DK for nrf52810.

SPI was successful in the emulation and we have tried to transfer the code to the actual nrf52810 chip as the infocenter explained and correcting some bugs

emulating and transferring process:

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fnrf52810_user_guide.html&cp=4_0_0_5_0

correcting bugs: SPIM0 peripheral

https://devzone.nordicsemi.com/f/nordic-q-a/35145/crashing-during-the-spi-transfer-on-nrf52810

We thought that mapping the pins would be enough but it was not.

In emulation, reading the sensor was successful but in the actual nrf52810 environment, SPI reads only '0xff'

For double checking, blinking LED and BLE NUS was successful but the spi communication was failed.

How can we solve this problem?

Does the transferring procedure has some bug?

Parents Reply Children
  • Thanks. Here is a schematic of our code

    #define SPI_INSTANCE	  0 /**< SPI instance index. */
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    static volatile bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */
    
    void spi_init(void)
    {
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = 16;
    spi_config.miso_pin = 15;
    spi_config.mosi_pin = 14;
    spi_config.sck_pin = 12;
    spi_config.mode = NRF_DRV_SPI_MODE_3;
    spi_config.frequency = NRF_DRV_SPI_FREQ_4M;
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
    }
    
    uint8_t SPI_Read(uint8_t cmd, uint8_t cmd_len, int delay)
    {
    memset(m_tx_buf,0,3);
    memset(m_rx_buf,0,4);
    
    m_tx_buf[0]=cmd;
    spi_xfer_done = false;
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, cmd_len,m_rx_buf, cmd_len));
    while(!spi_xfer_done); // sending command
    
    m_tx_buf[0]=0xFF;
    spi_xfer_done = false;
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, cmd_len,m_rx_buf, cmd_len));
    while(!spi_xfer_done);
    return m_rx_buf[0]; // reading recieved data
    }
    
    uint8_t LIS3DH_ReadID(void)
    {
    uint8_t ret, cmd;
    
    cmd=0x8F;
    ret=SPI_Read( cmd, 1,DELAY_MS);
    
    nrf_delay_ms(DELAY_MS);
    return m_rx_buf[0];
    }
    
    main{
    
    spi_init();
    
    LIS3DH_ReadID();
    
    	NRF_LOG_INFO("[HHC] LIS3DH ID = 0x%x.", sensorId); //returns 0xff  only..
    
    } 

  • So what have you found with the oscilloscope?

    And what have you found with the debugger?

    How to properly post source code:

  • Thanks awneil. We will check the actual signal by using oscillo scope tommorow since we have to borrow it...

    We just used segger RTT debuger and log_info for debugging but we couldn't find any insight by using them. Is there any proper way to check the spi by using debugger?

  • You use the debugger to step through your code, set breakpoints, examine variables, etc

  • I already used the breakpoints but couldn't find anything..

    I edited the source code.

    Using oscilloscope may give me some breakthroughs.

    I will reply later.

    My concern is that bugs exist in the SDK 15.0

Related