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...

Parents
  • difficult to understand what exactly problem

    Is it?

    The problem is that it is not in the INITLIALIZED state - it needs to be!

    https://en.wikipedia.org/wiki/Assertion_(software_development)

  • Hi,

    By disabled NRF_LOG_BACKEND_UART_ENABLED 0 in sdk_config.h then this error solved but now getting ERROR 17 [NRF_ERROR_BUSY] at the time of sending command over SPI.

     APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, address, sizeof(address), m_rx_buf, sizeof(m_rx_buf))); 

    Thanks,

    Vishal

  • 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!

  • Yes you are right but right we are not thinking to buy it and don't have any option.

    Actually here is below SPI command sequence that I want to write and read:

    Conversion start for pressure measurement (D1): 0Fh & 40h
    Conversion start for temperature measurement (D2): 0Fh & 20h
    Read calibration word 1 (W1): 1Dh & 50h
    Read calibration word 2 (W2): 1Dh & 60h
    Read calibration word 3 (W3): 1Dh & 90h
    Read calibration word 4 (W4): 1Dh & A0h
    Reset sequence command: 15h & 55h & 40h 
    

    I this my above program snippet is correct, I am getting problem for pressure and temperature measurement. When I send 0Fh & 40h byte then in rx buffer continuous receiving FF bytes.

    Is it necessary to send dummy bytes for read operation through SPI?

    Thanks....

Reply
  • Yes you are right but right we are not thinking to buy it and don't have any option.

    Actually here is below SPI command sequence that I want to write and read:

    Conversion start for pressure measurement (D1): 0Fh & 40h
    Conversion start for temperature measurement (D2): 0Fh & 20h
    Read calibration word 1 (W1): 1Dh & 50h
    Read calibration word 2 (W2): 1Dh & 60h
    Read calibration word 3 (W3): 1Dh & 90h
    Read calibration word 4 (W4): 1Dh & A0h
    Reset sequence command: 15h & 55h & 40h 
    

    I this my above program snippet is correct, I am getting problem for pressure and temperature measurement. When I send 0Fh & 40h byte then in rx buffer continuous receiving FF bytes.

    Is it necessary to send dummy bytes for read operation through SPI?

    Thanks....

Children
Related