2025-07-15 11:54 PM - last edited on 2025-07-16 1:04 AM by Andrew Neil
Hii Team,
I'm using STM32G070RBT6 MCU to communicate with ADS124S06.
I've configured the SPI on the MCU for Mode1 and GPIOs CS, RST, START pins as output (NO pull up/ pull down) and DRDY as input (NO pull up/ pull down).
GPIO Configuration:
SPI Configuartion:
Clock Configuration:
Code :
the ADS124S06_Init function:
bool ADS124S06_Init(ADS124S06_Handle *dev) {
DEBUG_PRINT("Entered init Function");
// RESET pin sequence
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);
HAL_Delay(5);
ADS124S06_WriteRegister(dev, 0x02, 0x54); // I/p MUX: AIN5-AIN4 0x54
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x03, 0x00); // GAIN: PGA=1, 20SPS
ADS124S06_WriteRegister(dev, 0x04, 0x14); // DataRAte : 20SPS, osc-4.096MHz
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x05, 0x0A); // REF : internal 2.5V On always.
ADS124S06_WriteRegister(dev, 0x06, 0x00); // IDACMAG
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x07, 0xFF); // IDACMUX
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x08, 0x00); // VBIAS
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x09, 0x10); // SYS
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x0A, 0x00);
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x0B, 0x00);
ADS124S06_WriteRegister(dev, 0x0C, 0x00);
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x0D, 0x00);
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x0E, 0x00);
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x0F, 0x40);
ADS124S06_WriteRegister(dev, 0x10, 0x00);
HAL_Delay(1);
ADS124S06_WriteRegister(dev, 0x11, 0x00);
HAL_Delay(1);
return true;
}
bool ADS124S06_WriteRegister(ADS124S06_Handle *dev, uint8_t reg, uint8_t data) {
uint8_t cmd[3] = { ADS_CMD_WREG | (reg & 0x1F), 0x00, data };
cs_low(dev);
bool ok = HAL_SPI_Transmit(dev->hspi, cmd, 3, ADS_TIMEOUT) == HAL_OK;
cs_high(dev);
return ok;
}
in the ADS124S06_ReadRegister function I'm just doing
{
uint8_t txData[20];
uint8_t rxData[20];
txData[0] = 0x20 ; //RREG
txData[1] = 0x11;
txData[2] = 0x00;
txData[3] = 0x00;
txData[4] = 0x00;
txData[5] = 0x00;
txData[6] = 0x00;
txData[7] = 0x00;
txData[8] = 0x00;
txData[9] = 0x00;
txData[10] = 0x00;
txData[11] = 0x00;
txData[12] = 0x00;
txData[13] = 0x00;
txData[14] = 0x00;
txData[15] = 0x00;
txData[16] = 0x00;
txData[17] = 0x00;
txData[18] = 0x00;
txData[19] = 0x00;
cs_low(dev);
HAL_SPI_TransmitReceive(dev->hspi, txData, rxData, sizeof(rxData), 100);
cs_high(dev);
for (uint8_t i =0; i<20;i++)
{
DEBUG_PRINT("rxdata[%d] = 0x%02X",i, rxData[i]);
}
///////////////////////
static void cs_low(ADS124S06_Handle *dev) {
HAL_GPIO_WritePin(dev->cs_port, dev->cs_pin, GPIO_PIN_RESET);
}
static void cs_high(ADS124S06_Handle *dev) {
HAL_GPIO_WritePin(dev->cs_port, dev->cs_pin, GPIO_PIN_SET);
}
this is what I'm doing. I've configured all the SPI settings as per the datasheet of ADS124S06 and able to receive the data on MISO line,
I've verified it using logic analyser.
written data zoom out view
read data RREG
by seeing the logic analyser output, I can say that the data is available on MISO line but through firmware unable to receive/store it into buffer.
in debug mode keeping the rxData[20] in global and addded it into LiveExpressions, I'm facing an issue that rxData is not filling.
in this only SPI1 is enabled and also uart for debugging.
Please help me out from this issue. I hope I've given all the necessary information to debug this issue in detail, I can also provide any further information needed regarding the same.
Thank you, Kindly Please help me.
Edited to apply source code formatting - please see How to insert source code for future reference.
Solved! Go to Solution.
2025-07-18 3:39 AM
Hii @Saket_Om, @Andrew Neil
Thank you for your detailed and insightful responses regarding the SPI states.
I’m pleased to inform you that the issue has been resolved, and I can now be able to successfully receive data on rxData. The problem was traced to improper soldering at the controller end, which has been corrected now.
I sincerely apologize for my oversight. I hope that your expertise will continue to guide me in my future tests. Thank you again for your time and support.
2025-07-16 1:01 AM
Welcome to the forum.
Please see How to write your question to maximize your chances to find a solution for best results - in particular, How to insert source code.
I'll edit the post for you, but all the indentation has already been lost.
What board are you referring to?
Please show a schematic of how the ADS124S06 is connected; some goof, clear photos of your setup would also help.
2025-07-16 1:08 AM - edited 2025-07-16 1:08 AM
Here:
HAL_SPI_TransmitReceive(dev->hspi, txData, rxData, sizeof(rxData), 100);
The length needs to be the total length of the transaction - both transmit and receive.
2025-07-16 3:27 AM - edited 2025-07-16 3:29 AM
Thanks for the response.
I'm referring to STM32G070RBT6.
Let's keep it short. I'm gonna read only single register value. So, according to ADS124S06 datasheet, to read register value, we should use RREG command (0x20 | regAddress, 0x00)
//Reads Single Register
uint8_t ADS124S06_ReadRegisters(ADS124S06_Handle *dev)
{
uint8_t txData[3];
// Prepare RREG command
txData[0] = 0x22 ; // (0x20 | 0x02) = 0x22
txData[1] = 0x00; // no.of register - 1 = (1-1) = 0x00
txData[2] = 0xFF; // dummy data to receive value
// Pull CS low to start communication
cs_low(dev);
HAL_SPI_TransmitReceive(dev->hspi, txData, rxData, 3, 100);
cs_high(dev);
return rxData[2];
}
When I run this code, I got the output in logic analyser as given Screenshot
same SPI lines are connected to logic analyser lines, and the screenshot shows us the data on MISO line.
I'm transmitting 2 bytes and receiving 1 Byte. So, the total size I've given was 3.
rxData[3] is not being updated.
Sorry, I'm unable to provide the setup pictures.
schematic lines from the ADC to STM32G070RBT6.
pullups are added for these three lines.
Thank you.
2025-07-16 3:30 AM
@spd-kalyan wrote:I'm transmitting 2 bytes and receiving 1 Byte. So, the total size I've given was 3.
And that's working?
2025-07-16 3:41 AM - edited 2025-07-16 3:43 AM
Hardware is working fine as we're seeing the output in logic analyser, but the firmware side is the problem.
I want the data to be stored in rxData buffer, but it is not happening. only 0x00 are in rxData buffer.
uint8_t ADS124S06_ReadRegisters(ADS124S06_Handle *dev)
{
uint8_t txData[3];
// Prepare RREG command
txData[0] = 0x22 ;
txData[1] = 0x00;
txData[2] = 0xFF;
// Pull CS low to start communication
cs_low(dev);
HAL_SPI_TransmitReceive(dev->hspi, txData, rxData, 3, 100);
cs_high(dev);
return rxData[2];
}
//expected output.
rxData[0] = 0x00;
rxData[1] = 0x00;
rxData[2] = 0x54;
//actual output.
rxData[0] = 0x00;
rxData[1] = 0x00;
rxData[2] = 0x00;
logic Analyser output.
zoom-out view
2025-07-16 11:18 PM
Hii @Andrew Neil, Good morning,
I also tried with Transmit and receive individual calls, and also on interrupt mode. Data on MISO line is visible but not in rxData buffer.
uint8_t ADS124S06_ReadRegisters(ADS124S06_Handle *dev)
{
uint8_t txData[2];
// Prepare RREG command
txData[0] = 0x22 ;
txData[1] = 0x00;
// txData[2] = 0xFF;
// Pull CS low to start communication
cs_low(dev);
// HAL_SPI_TransmitReceive(dev->hspi, txData, rxData, 3, 100);
// HAL_SPI_TransmitReceive_IT(dev->hspi, txData, rxData, 3);
HAL_SPI_Transmit(dev->hspi, txData, 2, 100);
HAL_SPI_Receive(dev->hspi, rxData, 1, 100);
cs_high(dev);
return rxData[0];
}
Kindly, let me know anything specific to be changed.
logic analyser output.
STMCubeIDE Debug mode Live expressions
Also tried transmitting the rxData on UART and checked in serial monitor, still the value is 0x00.
What should I do? I'm with no clue and helpless. Please help me out. Thank you.
.
2025-07-17 1:57 AM
Are you sure the signal is actually reaching the STM32 pin?
Probe directly on the pin of the STM32 package.
Can you read both high & low with the pin configured just as a GPIO input?
Have you tested this on a standard devboard?
Maybe try bit-banging ...
2025-07-17 2:56 AM
Hii @Andrew Neil,
I wanted to share some observations from my recent tests with the STM32 MISO pin and the ADS124S08EVM. During my testing to verify if the MISO pin on the STM32 was functioning correctly, I shorted the MISO and MOSI pins to create a loopback while the ADC was also connected. Surprisingly, instead of receiving the data sent on the MOSI line, I received the expected data from the ADC. This was unexpected, and I'm curious about the reason behind this behavior.
Additionally, I noticed a difference in the MISO line behavior between the STM32 and the ADS124S08EVM. When using the ADS124S08EVM as a reference, the MISO line is initially high and goes low when data is received (high on pulses). However, with the STM32, the MISO line remains low and only goes high during pulses. Could this difference in the MISO line's idle state (high vs. low) be related to the issue? I've attached images for your reference.
STM32 Connected with ADS124S06 in parallel with logic analyser.
ADS124S08EVM SPI line connected with logic anaylser.
2025-07-17 7:51 AM
Hello @spd-kalyan
Could you try with the below configuration:
HAL_SPI_TransmitReceive(dev->hspi, (uint8_t *)txData, (uint8_t *)rxData, 3, 100);