Other Parts Discussed in Thread: ADS124S08EVM
Tool/software:
Good evening, Team,
I'm working in a project where I need to read data from a sensor continuously. To read the data from the sensor, I'm using ADS124S06.
ADS124S06_Handle adc1 = {
.hspi = &hspi1,
.cs_port = ADC1_CS_GPIO_Port,
.cs_pin = ADC1_CS_Pin,
.start_port = ADC1_START_GPIO_Port,
.start_pin = ADC1_START_Pin,
.reset_port = ADC1_RST_GPIO_Port,
.reset_pin = ADC1_RST_Pin
};
bool ADS124S06::WriteRegister(ADS124S06_Handle *dev, uint8_t reg, uint8_t data) {
uint8_t cmd[3]= {0};
cmd[0] = (WREG | (reg & 0x1F)); //WREG = 0x40
cmd[1] = 0x00;
cmd[2] = data;
cs_low(dev);
bool ok = HAL_SPI_Transmit(dev->hspi, cmd, 3, ADS_TIMEOUT) == HAL_OK;
cs_high(dev);
return ok;
}
void ADS124S06::Init(ADS124S06_Handle *dev)
{
HAL_GPIO_WritePin(dev->reset_port, dev->reset_pin, GPIO_PIN_RESET);
HAL_Delay(1);
HAL_GPIO_WritePin(dev->reset_port, dev->reset_pin, GPIO_PIN_SET);
WriteRegister(dev, 0x03, 0x00); // GAIN: PGA=1, 20SPS
WriteRegister(dev, 0x02, 0x54); // I/p MUX: AIN5-AIN4 0x54
WriteRegister(dev, 0x04, 0x14); // DataRAte : 20SPS, osc-4.096MHz
WriteRegister(dev, 0x05, 0x0A); // REF : internal 2.5V On always.
WriteRegister(dev, 0x06, 0x00); // IDACMAG
WriteRegister(dev, 0x07, 0xFF); // IDACMUX
WriteRegister(dev, 0x08, 0x00); // VBIAS
WriteRegister(dev, 0x09, 0x10); // SYS
WriteRegister(dev, 0x0A, 0x00);
WriteRegister(dev, 0x0B, 0x00);
WriteRegister(dev, 0x0C, 0x00);
WriteRegister(dev, 0x0D, 0x00);
WriteRegister(dev, 0x0E, 0x00);
WriteRegister(dev, 0x0F, 0x40);
WriteRegister(dev, 0x10, 0x00);
WriteRegister(dev, 0x11, 0x00);
}
After the initialisation of the ADS124S06 with the above parameters I'm reading back the registers.
void ADS124S06::ReadRegisters(ADS124S06_Handle *dev) {
uint8_t txData[20];
uint8_t rxData[20];
/*Prepare RREG command*/
txData[0] = RREG; //RREG = 0x20
txData[1] = 0x11;
for (int i = 2; i < 20; i++) {
txData[i] = 0xFF;
}
/* Pull CS low to start communication*/
cs_low(dev);
HAL_SPI_TransmitReceive(dev->hspi, (uint8_t*) txData, (uint8_t*) rxData, 20,
100);
cs_high(dev);
}
I'm getting all the register values as expected. everything goes well till here.
phReadings ADS124S06::ReadData(ADS124S06_Handle *dev) {
uint8_t tx_buf[1];
static bool st = true;
tx_buf[0] = RDATA; // 0x12
cs_low(dev);
if (st) {
HAL_SPI_Transmit(dev->hspi, tx_buf, 1, 100);
st = false;
}
HAL_SPI_Receive(dev->hspi, rx_buf, 3, 100);
cs_high(dev);
return calculate_voltage(rx_buf, 2.495, 1);
}
Now, I'm trying to read data in continuous mode using start_pin (through hardware, not used start command "0x08")
configured the DRDY_PIN in interrupt mode (falling edge trigger). whenever DRDY_PIN goes low adc1_drdy flag will be HIGH.
I'm starting the conversation once and continuously reading the data using ReadData function (in loop runs every 100ms).
able to read values for few readings later DRDY_PIN is being HIGH all the time, that leads adc1_drdy flag LOW and now I'm unable to read data.
If I reset the controller then again, I'm able to read data for few readings and then previous issue repeats.
What do I do? Please help me out.
Thanks in advance.
