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

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 all,

    I modified my code a bit.

    uint8_t* RREG_ADS(uint8_t address)
    {
    		static uint8_t data_reg[4];
    		dataToSend[0] = address | 0x20;				//Opcode 000n nnnn =0 : write n channels
    		uint8_t opcode2 = 0x00;  // specify how many registers used
    	  nrf_gpio_pin_clear(CS); // 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(data_reg,0,sizeof(data_reg));
          APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, dataToSend, 1, data_reg, count));
    	  while (!spi_xfer_done){__WFE();}
    	  NRF_LOG_FLUSH();
    		if(DEBUG){NRF_LOG_INFO("Send opcode2\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, &opcode2, 1, m_rx_buf, sizeof(m_rx_buf)));  
    	  while (!spi_xfer_done){__WFE();}
    	  NRF_LOG_FLUSH();
    		// send dummy bytes
    		/*
    		if(DEBUG){NRF_LOG_INFO("Send dummy bytes\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_delay_us(15);
    		nrf_gpio_pin_set(CS); // disable SS pin for ADS
    		return data_reg;	
    }
    

    Basically, here I try to read data from ID register and first byte is (address | 0x20), the second one is 0x00 which I denoted as opcode2 as I just read only one register. Looking at the diagram, I'm wondering for the output in DOUT, will the REG DATA (red arrow) be available in the third index of output array supposed to receive?

    I logged output data I received as the following image. The third element should be 0x1E which is supposed to indicate the IC I am using; however it was 0x1F.

    Since I put 15us delay in the code, does it effect on not receiving correctly data back from the IC?

    Thank you!

  • Lol. I solved this issue. It was due to SPI configuration mode. Mine should be set up as Clock polarity 0 and Clock phase 1 (sample from falling edge) --> Mode_1. I changed it and it worked.

Reply Children
Related