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
  • 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);
        }
    
    

  • so i want to remove this  "spi_config.ss_pin = SPI_MOUSE_CSN_PIN;" portion from the code  then only i get correct data from burst mode read.

  • Yes, I thought I made that clear. You require the following if you are manually driving NCS before and after the two transfers:

    spi_config.sck_pin = NRF_DRV_SPI_PIN_NOT_USED;

    This is the default, as I posted above, so you can also just remove .sck_pin in initialisation

  • SIR I CHANGED "spi_config.ss_pin = SPI_MOUSE_CSN_PIN;" TO "spi_config.sck_pin = NRF_DRV_SPI_PIN_NOT_USED;

    BUT I CAN"T ABLE TO READ DATA FROM ALL 3 REGISTERS

  • CONFIGURATION OF SPI

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
    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;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    FUNCTION FOR READING DATA IN BURST MODE

    uint32_t adns_motion_burst_read(const nrf_drv_spi_t * i_spi_address , uint8_t * motion , uint8_t * deltaY , uint8_t * deltaX)
    {

         uint32_t err_code;

         if (i_spi_address == NULL )
         {
             return NRF_ERROR_INVALID_PARAM;
         }

         uint8_t tx_bm_data;
         uint8_t rx_bm_dummy; //receive buffer for dummy
         uint8_t i_reg;

        // Reset serial port
         adns_ncs_assert(i_spi_address,1); //disable ncs
         adns_ncs_assert(i_spi_address,0); //enable nc


         i_reg = ADNS_REG_MOTION_BURST;
        // Format for register in burstmode read
         tx_bm_data = i_reg & 0x7f; // The MSB to "0" to indicate a read operation

       // Write to Motion_Burst register.
         APP_ERROR_CHECK(nrf_drv_spi_transfer(i_spi_address,(const uint8_t  *)&tx_bm_data,1,&rx_bm_dummy,1));
       *motion = rx_bm_dummy; // Execute dummy read to clear RX buffer for motion


         nrf_delay_us(4); //tSRAD

       //Read motion datas by Writing out a dummy data byte which will be ignored 
         APP_ERROR_CHECK(nrf_drv_spi_transfer(i_spi_address,(const uint8_t  *)&tx_bm_dummy[0],3,&rx_bm_data[0],3));


        adns_ncs_assert(i_spi_address,1); //disable ncs


        *motion = rx_bm_data[0];
        *deltaY = rx_bm_data[1];
        *deltaX = rx_bm_data[2];

         nrf_delay_us(1); //tBEXIT

         return NRF_SUCCESS;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    sdk_config.h

    #ifndef SPI0_ENABLED
    #define SPI0_ENABLED 1
    #endif
    // <q> SPI0_USE_EASY_DMA - Use EasyDMA

    #ifndef SPI0_USE_EASY_DMA
    #define SPI0_USE_EASY_DMA 0
    #endif

Reply
  • CONFIGURATION OF SPI

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
    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;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    FUNCTION FOR READING DATA IN BURST MODE

    uint32_t adns_motion_burst_read(const nrf_drv_spi_t * i_spi_address , uint8_t * motion , uint8_t * deltaY , uint8_t * deltaX)
    {

         uint32_t err_code;

         if (i_spi_address == NULL )
         {
             return NRF_ERROR_INVALID_PARAM;
         }

         uint8_t tx_bm_data;
         uint8_t rx_bm_dummy; //receive buffer for dummy
         uint8_t i_reg;

        // Reset serial port
         adns_ncs_assert(i_spi_address,1); //disable ncs
         adns_ncs_assert(i_spi_address,0); //enable nc


         i_reg = ADNS_REG_MOTION_BURST;
        // Format for register in burstmode read
         tx_bm_data = i_reg & 0x7f; // The MSB to "0" to indicate a read operation

       // Write to Motion_Burst register.
         APP_ERROR_CHECK(nrf_drv_spi_transfer(i_spi_address,(const uint8_t  *)&tx_bm_data,1,&rx_bm_dummy,1));
       *motion = rx_bm_dummy; // Execute dummy read to clear RX buffer for motion


         nrf_delay_us(4); //tSRAD

       //Read motion datas by Writing out a dummy data byte which will be ignored 
         APP_ERROR_CHECK(nrf_drv_spi_transfer(i_spi_address,(const uint8_t  *)&tx_bm_dummy[0],3,&rx_bm_data[0],3));


        adns_ncs_assert(i_spi_address,1); //disable ncs


        *motion = rx_bm_data[0];
        *deltaY = rx_bm_data[1];
        *deltaX = rx_bm_data[2];

         nrf_delay_us(1); //tBEXIT

         return NRF_SUCCESS;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    sdk_config.h

    #ifndef SPI0_ENABLED
    #define SPI0_ENABLED 1
    #endif
    // <q> SPI0_USE_EASY_DMA - Use EasyDMA

    #ifndef SPI0_USE_EASY_DMA
    #define SPI0_USE_EASY_DMA 0
    #endif

Children
Related