I'm trying to read 8 different single-ended analog signals from an array of op-amps with a STM32H7 MCU, however I only get an array of 8 zeros when using ADC1 with DMA (the readings are recovered via the UART5, but the zeros can also be seen when putting a break point after the ADC buffer is populated). Here's the setup/code:
In the main.c I have the following global variables for reading the ADC values:
/* USER CODE BEGIN PV */
uint8_t adc_ch=0; //adc channel index
volatile uint32_t adc_readings[ADC_CHS_QTITY]; //ADC values buffer, ADC_CHS_QTITY=8
uint16_t adc_res = 19859;
float adc_reading =0; //instantaneous converted value
inside void main(void) I have the following inits():
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
(...)
/* USER CODE BEGIN 2 */
xSemaphoreGive(xsemaph_adc);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *) &adc_readings, ADC_CHS_QTITY);
xTaskCreate(vAnalogRead, "analog_read", 256, NULL, 24, &xAnalogRead_Handle);
xTaskCreate(vSendAnalogReading, "send_reading", 128, NULL, 24, &xSendAnalogReading_Handle); //The ADC readings are sent to the UART for debugging
The AnalogRead and SendAnalogReading tasks:
void vAnalogRead(void *argument)
{
/* Infinite loop */
for(;;)
{
xSemaphoreTake(xsemaph_adc, portMAX_DELAY);
adc_reading = adc_readings[adc_ch] / adc_res;
adc_ch++;
if(adc_ch>7)
{
adc_ch=0;
}
xSemaphoreGive(xsemaph_uart);
}
/* USER CODE END StartLeAnalog */
}
void vSendAnalogReading(void *argument)
{
uint8_t ch=0;
uint8_t reading[8];
for(;;)
{
xSemaphoreTake(xsemaph_uart, portMAX_DELAY);
ch = adc_ch - 1;
if(ch==0xff)
{
ch=7;
}
reading[0] = 0x0a; //read begin
reading[1] = 0x0a; //Analog reading, not digital
reading[2] = ch; //adc channel
gcvt(adc_reading, 3, &reading[3]); //the converted ADC readings
reading[7] = 0x0b; //read end
HAL_UART_Transmit(&huart5, reading, 8, 100);
vTaskDelay(pdMS_TO_TICKS(1500));
xSemaphoreGive(xsemaph_adc);
}
}