2026-01-29 4:39 AM - last edited on 2026-01-29 4:57 AM by mƎALLEm
NUCLEO-F411RE
I have ADC1 to DMA in a circular buffer 4 samples long (ADC_VAL). I then use a TIM1 interrupt to send the contents via UART to a PC.
int16_t ADC_VAL[4];
...
HAL_ADC_STart_DMA(&hadc1, (uint32_t *)ADC_VAL, 4);
/* TIM1 callback */
void HAL_TIM_periodElapsedCallback(TIM_HandleTypeDef *htim)
{
HAL_UART_Transmit(&huart2, (uint8_t *)ADC_VAL, 16, 10);
}
Should I have declared ADC_VAL as a uint32_t ?
Solved! Go to Solution.
2026-01-29 6:03 AM
> Should I have declared ADC_VAL as a uint32_t ?
In general, no. ADC only needs a uint16_t to store content. Ensure your DMA is set up to half-word size.
> int16_t ADC_VAL[4];
This is an array of 4 uint16_t values, which is a total of 8 bytes, not 16.
2026-01-29 5:28 AM
Hello @NicRoberts
Please refer to the example below which use __IO uint16_t variable when calling HAL_ADC_Start_DMA().
2026-01-29 5:43 AM
Thanks for the reply, maybe I wasn't being clear enough in the OP.
In the example you linked to (and similarly in my own code) we have
HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&uhADCxConvertedValue, 1)
where uhADCxConvertedValue is first declared as 16 bit then cast as 32 bit for the DMA. What is the size of uhADCxConvertedValue in memory?
Is it 16 bits of actual values from the ADC padded with 16 bits of 0s?
or
is it 16 bits?
I ask as I need to know when transmitting the bytes via UART i.e. If its 16 then I just need 2 bytes...
Does that make sense?
2026-01-29 6:03 AM
> Should I have declared ADC_VAL as a uint32_t ?
In general, no. ADC only needs a uint16_t to store content. Ensure your DMA is set up to half-word size.
> int16_t ADC_VAL[4];
This is an array of 4 uint16_t values, which is a total of 8 bytes, not 16.