ADS1299 reading register_SPI_nRF52832

Hello everyone,

Testing on:

  • nRF52DK (PCA 10040)
  • SDK 13.0.0

I have been struggling with reading from the register of ADS1299. I just want to try to read info from ID register of this IC to make sure getting correctly data using SPI.

Below is my code to read the register, I couldn't receive correct the data which is supposed to get 0x1E. Could you help me to check whether something is wrong in this code?

Thank you!

uint8_t RREG_ADS(uint8_t address)
{
	  uint8_t data_reg;
	  dataToSend[0] = address | 0x20;  //Opcode 000n nnnn =0 : write n channels
	  nrf_gpio_pin_clear(SPIM0_SS_PIN); // enable SS pin for ADS
	  if(DEBUG){NRF_LOG_INFO("Read from DR register of ADS\r\n");NRF_LOG_FLUSH();}
	  // Reset rx buffer and transfer done flag
	  spi_xfer_done = false; memset(m_rx_buf,0,sizeof(m_rx_buf));
      APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, dataToSend, 1, &data_reg, 1));
	  while (!spi_xfer_done){__WFE();}
	  NRF_LOG_FLUSH();
	  if(DEBUG){NRF_LOG_INFO("Send 0x00\r\n");NRF_LOG_FLUSH();}
	  spi_xfer_done = false; memset(m_rx_buf,0,sizeof(m_rx_buf));
	  APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, 0x00, 1, m_rx_buf, sizeof(m_rx_buf)));  
	  while (!spi_xfer_done){__WFE();}
	  NRF_LOG_FLUSH();
	  nrf_gpio_pin_set(SPIM0_SS_PIN); // disable SS pin for ADS
		nrf_delay_us(15);
		return data_reg;	
}

Parents
  • Hi,

    Here is part of the code from my project, where I read registers:

    void AdsGetConfig (uint8_t *RdCfg)
    {
      LineControl(AdsLineCs, AdsLineLow);
      AdsSpiSendByte(AdsCmdRReg);
      AdsSpiSendByte(ADS_REGISTER_COUNT);
      for(uint8_t idx = 0; idx < (ADS_REGISTER_COUNT); ++idx)
      {
        *RdCfg = AdsSpiReadByte();
        RdCfg++;
      }
      LineControl(AdsLineCs, AdsLineHigh);
    }
    
    
    void AdsSpiSendByte  (uint8_t byte)
    {
    	SpimWrite(AfeSpi, &byte, 1);
    }
    
    
    uint8_t AdsSpiReadByte (void)
    {
    	uint8_t ReadData;
    	SpimRead(AfeSpi, &ReadData, 1);
    
    	return ReadData;
    }
    
    /* From my spim driver*/
    void SpimRead 	(NRF_SPIM_Type *SPIx, uint8_t *rx_data, uint8_t rx_size)
    {
      if((NRF_SPIM_Type*)SPIx == NRF_SPIM2) while(Spim2Busy) __NOP();
      
      SPIx->TXD.PTR		= (uint32_t)0x00;
      SPIx->RXD.PTR		= (uint32_t)rx_data;
      SPIx->TXD.MAXCNT	= 0;
      SPIx->RXD.MAXCNT	= rx_size;
      
      Spim2Busy = true;
      SPIx->TASKS_START = 1;
      if((NRF_SPIM_Type*)SPIx == NRF_SPIM2) while(Spim2Busy) __NOP();
    }
    
    void SpimReadWrite 	(NRF_SPIM_Type *SPIx, uint8_t *tx_data, uint8_t tx_size, uint8_t *rx_data, uint8_t rx_size)
    {
      if((NRF_SPIM_Type*)SPIx == NRF_SPIM2) while(Spim2Busy) __NOP();
      
      SPIx->TXD.PTR		= (uint32_t)tx_data;
      SPIx->RXD.PTR		= (uint32_t)rx_data;
      SPIx->TXD.MAXCNT	= tx_size;
      SPIx->RXD.MAXCNT	= rx_size;
    
      Spim2Busy = true;
      SPIx->TASKS_START = 1;
      if((NRF_SPIM_Type*)SPIx == NRF_SPIM2) while(Spim2Busy) __NOP();
    }
    
    void SPIM2_SPIS2_SPI2_IRQHandler(void)
    {
      volatile uint32_t dummy;
      
      if(NRF_SPIM2->EVENTS_STOPPED)
      {
        NRF_SPIM2->EVENTS_STOPPED = 0;
        dummy = NRF_SPIM2->EVENTS_STOPPED;
        (void)dummy;
      }
      
      if(NRF_SPIM2->EVENTS_ENDRX)
      {
        NRF_SPIM2->EVENTS_ENDRX = 0;
        dummy = NRF_SPIM2->EVENTS_ENDRX;
        (void)dummy;
      }
      
      if(NRF_SPIM2->EVENTS_ENDTX)
      {
        NRF_SPIM2->EVENTS_ENDTX = 0;
        dummy = NRF_SPIM2->EVENTS_ENDTX;
        (void)dummy;
      }
      
      if(NRF_SPIM2->EVENTS_END)
      {
        NRF_SPIM2->EVENTS_END = 0;
        dummy = NRF_SPIM2->EVENTS_END;
        (void)dummy;
        Spim2Busy = false;
      }
    
      if(NRF_SPIM2->EVENTS_STARTED)
      {
        NRF_SPIM2->EVENTS_STARTED = 0;
        dummy = NRF_SPIM2->EVENTS_STARTED;
        (void)dummy;
        Spim2Busy = true;
      }
    }

    Note: this is not the most optimal code, but it works.

    also, it must be remembered that this ADS1299 is whimsical to the diagram of inclusion, the order of appearance of the feeds.

    And I hope you have interface line monitoring tools, such as a logic analyzer.

Reply Children
No Data