Hi,
I am using an STM32G474 MCU to interact with the ADC. I have setup the SPI at the MCU side and I am trying to read back the device ID from the ID register. But all I get is 0xFF, whatever value I send to the ADC.
Here is a rough flow of our program:
1. Configure MCU clocks and GPIO ports
2. Initialize the SPI as first bit MSB, SPI clock frequency as 4.6125 MHz, CPOL: 1 and CPHA: 0.
4. After that, we initialize the SPI, Start the clock, and enable the SPI periphereal.
5. As we are only using one slave, we pull the chip select to active low. After this, 100 ms delay.
6. Transmit 10 0xFF's to the ADC. (Are we support to receive anything in the MISO line when we do this?)
7. Another 100 ms delay
8. After that I send 0x40 to the ADC, and in response I receive 0xFF.
9. Another 100 ms delay.
10. I read somewhere that you need to send dummy values to get back things from the MISO line. So, we send 0x00 to the ADC and then we just get back 0xFF.
I have added the code we used before, although I intend to ask this question also in the STM32 forum to see if there is a mistake in the setup of SPI from the MCU side.
// pull low the chip select
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
// Delay 100 ms
HAL_Delay(100);
// Wait for SPI1 to not be busy
while(SPI1->SR & SPI_SR_BSY_Msk);
// Flush the Rx Fifo
HAL_SPIEx_FlushRxFifo(&hspi1);
// Transmit 10 0xFF (registerword)
response=HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)registerWord, (uint8_t*)registerreceive, 10, 100);
if(response==HAL_OK)
{
// If response is okay. Do something. This is executed properly
}
HAL_Delay(100);
// Get register ID
ADC_send=0x40; // 0x40 to communicaiton register to read from ID register
while(SPI1->SR & SPI_SR_BSY_Msk);
response=HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)&ADC_send, (uint8_t*)&ADC_received, 1, 100);
if(response==HAL_OK)
{
// If status is OK. Do something. This too gets executed.
}
HAL_Delay(100);
// Send dummy variable to receive data
ADC_send=0x00;
response=HAL_SPI_TransmitReceive(&hspi1,(uint8_t*)&ADC_send,(uint8_t*)&ADC_received,1,100);
while(SPI1->SR & SPI_SR_BSY_Msk);
if(response==HAL_OK)
{
// Print device ID here. But it is just 0xFF
}
We have done some basic measurements, and at least we are sure that the ADC is getting both AVdd and DVdd. I would also appreciate some input on troubleshooting with the scope. What pins should I measure, etc.
Thanks for the help.

