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

nRF52840 - ADS1292

Hi,

I want to read register 0x00 (chip ID) of ads1292. i do following...

=============================================================================================================================

///// init spi /////

spi_config.ss_pin = ARDUINO_7_PIN;
spi_config.miso_pin = ARDUINO_12_PIN;
spi_config.mosi_pin = ARDUINO_11_PIN;
spi_config.sck_pin = ARDUINO_13_PIN;
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
spi_config.mode = NRF_DRV_SPI_MODE_0;
spi_config.frequency = NRF_DRV_SPI_FREQ_4M;
spi_config.orc = 0x00;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
NRF_LOG_INFO("SPI example started.");NRF_LOG_FLUSH();

///// reset the board by pulling low hardware pin /////

nrf_gpio_pin_write(ADS1292_PWDN_PIN, action);

delay(100);

nrf_gpio_pin_write(ADS1292_PWDN_PIN, action);

delay(100);

nrf_gpio_pin_write(ADS1292_PWDN_PIN, action);

delay(100);

/////// stop continues data receive mode ///////

spi_xfer_done=false;memset(m_rx_buf,0,sizeof(m_rx_buf));
spiDataTx[0]=0x11;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, spiDataTx, 1, m_rx_buf, sizeof(m_rx_buf)));
while (!spi_xfer_done){__WFE();}
NRF_LOG_FLUSH();

//////// read chip id register (0x00) ///////////

char tempData[3];
tempData[0]=0x20;
tempData[1]=0x00;
tempData[2]=0x00;
spi_xfer_done=false;memset(m_rx_buf,0,sizeof(m_rx_buf));
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, tempData, 3, m_rx_buf, sizeof(m_rx_buf)));
while (!spi_xfer_done){__WFE();}
NRF_LOG_FLUSH();

=============================================================================================================================

but i always get garbage value. It should come as 0x73 but every time receiving garbage values.

i did exactly same as described in datasheet of ads1292.

Did i anything wrong as far as nRF52 board concern ? Waiting for better solution.

Thanks in advance.

Parents
  • 4MHz and Mode 0 will create difficulties for the ADS1292. Try the following:

    spi_config.frequency = NRF_DRV_SPI_FREQ_500K;  // Ensure less than 4 clk cycles for ADS1292
    spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    spi_config.mode      = NRF_DRV_SPI_MODE_1;
    APP_ERROR_CHECK(nrf_drv_spi_init(&mAfeSpiInstance, &spi_config, afe_spi_event_handler, NULL));
    

    Reading the version code is easiest using a single transfer:

    // Scratch pad comms buffers, used for reading all AFE registers - want to preserve these for debugging
    #define AFE_HARDWARE_VERSION 0x53
    
    static uint8_t mTxBuf[] = {ADS_CMND_RREG, NUMBER_OF_ADS_REGISTERS-1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    static uint8_t mRxBuf[sizeof(mTxBuf)];
    static const uint8_t mRxTxBufLength = sizeof(mTxBuf);
    
    /**
     * @brief SPI command to read AFE registers
     * @param event
     */
    static void ReadAfeRegisters(void)
    {
        uint32_t spiAttempCount, mAfeSpiErrorCount = 0;
    
        for (spiAttempCount=0; spiAttempCount < AFE_MAX_ATTEMPTS; spiAttempCount++)
        {
            memset(mRxBuf, '?', mRxTxBufLength);
            mAfePacketTransferComplete = false;
            APP_ERROR_CHECK(nrf_drv_spi_transfer(&mAfeSpiInstance, mTxBuf, mRxTxBufLength, mRxBuf, mRxTxBufLength));
            // Hard delay per byte to transmit
            nrf_delay_us(mRxTxBufLength*AFE_SPI_PER_BYTE_uSECS);
            // Check for ADS1292 Id
            if (mAfePacketTransferComplete && (mRxBuf[2] == AFE_HARDWARE_VERSION))
            {
                // Correct Id for this AFE
                break;
            }
            else
            {
                mAfeSpiErrorCount++;
                // Extra hard delay per byte to transmit
                nrf_delay_us(mRxTxBufLength*AFE_SPI_PER_BYTE_uSECS);
            }
        }
        // Post the results (may be bad)
        ...
    }
    
    /**
     * @brief SPI event handler indicating SPI transfer has completed
     * @param event
     */
    static void afe_spi_event_handler(nrf_drv_spi_evt_t const * p_event, void *p_context)
    {
        mAfePacketTransferComplete = true;
    }
    
    

    Read the data sheet to see why the slow transfer speed is being used in my example; it is related to the number of clock cycles required by the part to handle SPI commands before the next SPI info; faster speeds are ok provided the code manages that restriction - I choose to take the simplest solution :-)

  • Read the data sheet

    Always good advice!

    -  How to properly post source code:

Reply Children
No Data
Related