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

SPI communication problem with interfaced sensor getting ASSERTION FAILED?

Hello Everyone,

We are using nRF52840 DK with Segger Embedded Studio (SES) using SDK v15.0 We are sending few command to sensor via SPI for reading sensor value. But while reading sensor value getting asseration failed ERROR at line no: nRF5_SDK_15.0.0_a53641a/modules/nrfx/drivers/src/nrfx_uarte.c:269

When I go to this line saw NRFX_ASSERT(p_cb->state == NRFX_DRV_STATE_INITIALIZED); difficult to understand what exactly problem. Please help me for fixing this issue.

Looking forward your response....!!!

Thanks...

  • Hi,

    Thanks for your suggestion..

    I have changed spi_xfer_done = false; before nrf_drv_spi_transfer() ; Now as you suggested I have looked and used actual data after size of address: And logs all read calibration factor and looks like working but the first bytes always same here is my below logs:

    <info> app: Level Detector started.
    <info> app: m_length: 2
    <info> app: Reset Sensor
    <info> app: Transfer completed.
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE                     |.       
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE                     |.       
    <info> app: RX Buff_byte1:FE byte2:F0 byte3:D7
    <debug> app: Calibration Word 1: 55280
    <info> app: m_length: 2
    <info> app: Reset Sensor
    <info> app: Transfer completed.
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE 01 9F               |...     
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE 01 9F FF F0         |.....   
    <info> app: RX Buff_byte1:FE byte2:F0 byte3:9F
    <debug> app: Calibration Word 2: 40944
    <info> app: m_length: 2
    <info> app: Reset Sensor
    <info> app: Transfer completed.
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE                     |.       
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE                     |.       
    <info> app: RX Buff_byte1:FE byte2:F0 byte3:C6
    <debug> app: Calibration Word 3: 50928
    <info> app: m_length: 2
    <info> app: Reset Sensor
    <info> app: Transfer completed.
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE 01 DA               |...     
    <info> app: Transfer completed.
    <info> app:  Received:
    <info> app:  FE 01 DA 7F F0         |.....   
    <info> app: RX Buff_byte1:FE byte2:F0 byte3:DA
    <debug> app: Calibration Word 4: 56048
    <info> app: coefficients- C1: 27640 C2:3120 C3:875 C4:795 C5:639 C6:48
    

    Also a logic analyzer (e.g. https://www.saleae.com/) can be very useful.

    Currently we don't have logic analyzer so can not be able to view SPI waveforms.

    I assume it just set spi_xfer_done = true;

    Yes you are correct.

    After that when I tried to read sensor register for measurement received same bytes every measurement like FF FF.

    Will you please make this case as private, So I can share my other code with you..

    Thanks... 

  • I recommend that you get logic analyzer asap, then you can look at the timing, clock and data lines, and also compare the rx_buf/tx_buf to the actual SPI transactions.

    Best regards,
    Kenneth

  • Actually right now we will not able to get logic analyzer, So can you please suggest me solution for How I can fixed this.

    When I send SPI command to sensor it response How I can read correct bytes from this means MSB first and then LSB.

    Is below function is correct for read and write SPI communication.

    unsigned int read_cal_word(uint8_t *address) {
      spi_xfer_done = false;
      unsigned int word = 0;
      uint8_t dummy_byte = 0x00;
      memset(m_rx_buf, 0, m_length);
      memset(m_rx_buf2, 0, sizeof(m_rx_buf2));
    //  NRF_LOG_INFO("m_length: %d", m_length)
      
      reset_sensor(); /*Before read calibration word need to reset sensor module*/
      APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, address, sizeof(address), m_rx_buf, sizeof(m_rx_buf)));
      nrf_delay_ms(200);
      wait_for_spi_event();
      NRF_LOG_FLUSH();
      APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &dummy_byte, sizeof(dummy_byte), m_rx_buf2, sizeof(m_rx_buf2)));
      wait_for_spi_event();
      nrf_delay_ms(200);
      NRF_LOG_INFO("RX Buff_byte1:%X byte2:%X", m_rx_buf[2], m_rx_buf2[1]);
      word = (m_rx_buf[2] << 8) | m_rx_buf2[1]; /*Combine received 2 bytes from sensor*/
    //  NRF_LOG_DEBUG("Return Calibration word = %u", word);
      return word;
    }
    

    Please let me know your valuable suggestion..?

    Thanks..

  • I suggest to connect MISO and MOSI together to first verify that m_rx_buf is a loopback of the address and commands you are sending. However a logic analyzer would speed up debugging a lot.

    Best regards,
    Kenneth

  • a logic analyzer would speed up debugging a lot

    Absolutely!!

    This is a hardware interface - trying to debug it with no view into the hardware is just folly!

Related