2025-11-05 2:43 AM - last edited on 2025-11-05 3:19 AM by mƎALLEm
Hi,
Im new to STM and trying to use ADC with DMA in circular mode but the value of my ADC remains at 0. I also tested it with Polling, which works.
ICache and DCache : Enable
void menu_adc(void)
uint32_t adc_buffer[1];
uint16_t adc0;
uint8_t flag_adc;
void menu_adc(void)
{
char buf[30];
HAL_ADC_Start_DMA(&hadc1, adc_buffer, 1);
while(1){
if (flag_adc == 1)
{
flag_adc =0;
int len = snprintf(buf, sizeof(buf), "ADC0: %u\r\n", adc0);
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
HAL_Delay(200);
}
if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK)
{
uint32_t adc_value = HAL_ADC_GetValue(&hadc1);
int len = snprintf(buf, sizeof(buf), "ADC0: %lu\r\n", adc_value);
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
}
}
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance == ADC1)
{
adc0 = adc_buffer[0]; // ADC1_INP0
flag_adc = 1;
}
}
Results:
I am also attaching the IOC so that you can look at the configuration of the ADC and DMA.
thank you
2025-11-05 5:09 AM
Hi,
at first try without D-cache, I-cache ON . And D-cache OFF.
To see if this is just a problem with the D-cache.
2025-11-05 5:38 AM