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

SPI AND SPIM READING ISSUES

hi all i am trying to read data from a sensor in burst mode i can"t able to read all datas from the register .I tried to read the data in both spi and spim(with easydma) . spim is more better it reads data from 2 register(i am trying to read data of 3 register using burst mode).how can i solve this issues.

Parents
  • In passing I would suggest your code will not work as NULL or 0 for tx buffer and length is not valid and will cause an assert; this is the assert trap discussed in this thread (have to keep loading more to see the that post):

        ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
        ASSERT(p_xfer_desc->p_tx_buffer != NULL || p_xfer_desc->tx_length == 0);
        ASSERT(p_xfer_desc->p_rx_buffer != NULL || p_xfer_desc->rx_length == 0);

    At least 1 transmit byte is required. Typically one would read all 3 bytes in a single invocation, assuming the hardware device allows thatwhich your device may not

    // Write out a dummy data byte which will be ignored and read motion data 
     APP_ERROR_CHECK(nrf_drv_spi_transfer(i_spi_address,tx_buf, 1, rx_bm_data, 3)); 
    

    I haven't looked at the rest of the code, but I think it requires review; for example, this is not a buffer but a single byte:

    uint8_t rx_bm_dummy; //receive buffer for dummy

    This is probably the intention:

    uint8_t rx_bm_dummy[3]; // 3-byte receive buffer for dummy

Reply
  • In passing I would suggest your code will not work as NULL or 0 for tx buffer and length is not valid and will cause an assert; this is the assert trap discussed in this thread (have to keep loading more to see the that post):

        ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
        ASSERT(p_xfer_desc->p_tx_buffer != NULL || p_xfer_desc->tx_length == 0);
        ASSERT(p_xfer_desc->p_rx_buffer != NULL || p_xfer_desc->rx_length == 0);

    At least 1 transmit byte is required. Typically one would read all 3 bytes in a single invocation, assuming the hardware device allows thatwhich your device may not

    // Write out a dummy data byte which will be ignored and read motion data 
     APP_ERROR_CHECK(nrf_drv_spi_transfer(i_spi_address,tx_buf, 1, rx_bm_data, 3)); 
    

    I haven't looked at the rest of the code, but I think it requires review; for example, this is not a buffer but a single byte:

    uint8_t rx_bm_dummy; //receive buffer for dummy

    This is probably the intention:

    uint8_t rx_bm_dummy[3]; // 3-byte receive buffer for dummy

Children
  •  yes uint8_t rx_bm_dummy;  is a single byte  this byte is only used when there is a write to "Motion_Burst register" the value received in these variable has no use.

    For receiving  valued datas from motion register ,x_Delta register and y_Delta register i used  uint8_t rx_bm_data[3]; its declared globally  its not in the above code i posted.

    Sir i also tried with  transmit  byte instead of null in this function "nrf_drv_spi_transfer(i_spi_address,NULL,0,&rx_bm_data[0],1));" call but not receiving all three  datas correctly.

    i can"t find out what the issue is . when reading the register data individually  its getting correctly but using burst mode not receiving correctly 

  • SPI initialization was correct and the data from sensor registers are getting when the sensor registers read separately (SPI USED NOT SPIM). If BURST MODE(SPIM IS USED) is used motion register data getting data from x and y register is not getting.

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = SPI_MOUSE_CSN_PIN;
    spi_config.miso_pin = SPI_MOUSE_MISO_PIN;
    spi_config.mosi_pin = SPI_MOUSE_MOSI_PIN;
    spi_config.sck_pin = SPI_MOUSE_SCK_PIN;
    spi_config.frequency = NRF_SPI_FREQ_1M;
    spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    spi_config.irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY;
    spi_config.mode = NRF_DRV_SPI_MODE_0;
    spi_config.orc = 0xFF;

    err_code = nrf_drv_spi_init(&spi, &spi_config,NULL, NULL);
    if(err_code != NRF_SUCCESS)
    return NRF_ERROR_SPI;

    SPI INSTANCE 0 IS USED

Related