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.

  •  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

  • This is the problem, I think:

    spi_config.ss_pin = SPI_MOUSE_CSN_PIN;

    This causes the SPIM driver to de-activate NCS between the first byte and the next 3 bytes, which terminates the burst transfer. Change this to manually drive NCS low before and after the transfers, not between.

    From the data sheet "After sending the register address, the microcontroller must wait tSRAD and then begin reading data. All data bits can be read with no delay between bytes by driving SCLK at the normal rate." tSRAD is 4uSecs, so for the "burst" read you are using the first byte is sent without removing NCS the three bytes are read in in the next SPI transfer, So send two commands and do not allow the spim handler to drive NCS and ensure there is at least 4 usec delay between 1st and second commands.

  • sir how "spi_config.ss_pin = SPI_MOUSE_CSN_PIN;" causes the SPIM driver to de-activate NCS between the first byte and the next 3 bytes, which terminates the burst transfer.

    i  am changeing  manually NCS low before and after the transfers( and not between look at the code i posted at the beginning)

    adns_ncs_assert(i_spi_address,1); //disable ncs
    adns_ncs_assert(i_spi_address,0); //enable ncs

    look this

  • I assume you control NCS correctly, setting low before the first of two transfers and only high after the second with the 4 uSec delay between the two transfers. However your code shows that you are also telling the nRF SPI code to take control of NCS. Here is the default setting for NCS and the handler for init:

    // Starts by assuming NCS is not required
    
    /**
     * @brief SPI master instance default configuration.
     */
    #define NRF_DRV_SPI_DEFAULT_CONFIG                           \
    {                                                            \
        .sck_pin      = NRF_DRV_SPI_PIN_NOT_USED,                \
        .mosi_pin     = NRF_DRV_SPI_PIN_NOT_USED,                \
        .miso_pin     = NRF_DRV_SPI_PIN_NOT_USED,                \
        .ss_pin       = NRF_DRV_SPI_PIN_NOT_USED,                \
        .irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY,         \
        .orc          = 0xFF,                                    \
        .frequency    = NRF_DRV_SPI_FREQ_4M,                     \
        .mode         = NRF_DRV_SPI_MODE_0,                      \
        .bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,         \
    }
    
    // Tests if NCS is not required
    
        // - Slave Select (optional) - output with initial value 1 (inactive).
        if (p_config->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
        {
            nrf_gpio_pin_set(p_config->ss_pin);
            nrf_gpio_cfg_output(p_config->ss_pin);
        }
        m_cb[p_instance->drv_inst_idx].ss_pin = p_config->ss_pin;
    
    

    However your code shows that you are requesting the nRF SPI driver to take over NCS:

    spi_config.ss_pin = SPI_MOUSE_CSN_PIN;

    The nRF handler will now drive NCS low before and high after every transaction, including between the two transactions you require, for example sww nrf_drv_spi.c

    static void finish_transfer(spi_control_block_t * p_cb)
    {
        // If Slave Select signal is used, this is the time to deactivate it.
        if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
        {
            nrf_gpio_pin_set(p_cb->ss_pin);
        }
    
    

Related