Contents
How to read ADC value and transmit using UART?
Make sure that ADCValue variable is uint32_t or at least uin16_t as the return value of HAL_ADC_GetValue is uint32_t. If the ADC’s resolution is above 8 bit then 1 byte won’t be enough to store the result. The HAL_UART_Transmit expects an uint8_t* as a second parameter, given your code you pass a simple variable.
How does a UART transmitter and receiver work?
UART Summary The UART interface does not use a clock signal to synchronize the transmitter and receiver devices; it transmits data asynchronously. Instead of a clock signal, the transmitter generates a bitstream based on its clock signal while the receiver is using its internal clock signal to sample the incoming data.
How to transmit ADC value in c-stm32?
The HAL_UART_Transmit expects an uint8_t* as a second parameter, given your code you pass a simple variable. You should use the & operator before ADCValue and cast it to uint8_t*. Also it only sends 1 byte in your code, based on the third parameter. If ADCValue is uint32_t then you should modify this parameter to 4.
How much data can I transfer with UART?
This translates to 12MB/s of data to transfer from the MCU to the computer, which is no trivial amount. UART will not do. SPI, at a max of 30Mbps (2-3MB/s) wont do it either. Writing to a microSD card via SDIO would come close.
Is it OK to call ADC in while loop?
Assuming that you call HAL_ADC_Start (&hadc1) before entering the while loop. Basically it is OK to call you code in a while loop, but I have some remarks. Make sure that ADCValue variable is uint32_t or at least uin16_t as the return value of HAL_ADC_GetValue is uint32_t.
Do you need to send null to UART?
So really need to send all the chars returned by itoa () including the NULL so that the receiver will know it got the end of the string. Rather than do this, you might just send the raw 8-bit value over the UART (which will usually NOT display properly on a terminal) and process it on the other side.