2019-01-23 12:06 PM
My goal: I'm trying to read two ADC pins with 12 bit resolution and output the values through DMA over USART.
I can see that the ADC values are being read in the debug tab in STM32CubeMX. I can "talk" over USART to my serial capture program by having it print "Hello World". However, I cannot get the ADC values to be sent over USART. Part of the problem might be that I need to convert a uint32 to a uint_8 for the USART, although I thought had solved that (with help), but now I'm not so sure. I have a lot of commented out sections of code but would really appreciate someone advice on what I'm doing wrong. The Baud rate on the STM32 and serial monitor are both at 115200.
I attached a zip but I think the issue is likely with the UART transmit part of code:
uint32_t adcVal[2]; /*array to store ADC values*/
HAL_UART_Transmit(&huart2,(void *)adcVal, sizeof(adcVal),10); // Sends 4 bytes, binary data
2019-01-23 12:33 PM
Transmitting binary data over UART needs much thought and a good protocol. Print the ADC values as numbers and send via UART.
2019-01-23 01:22 PM
Is there a tutorial anywhere you might suggest? I've watched 5 or 6 videos on YouTube and read through a few and my programming skills are pretty limited.
2019-01-23 01:24 PM
The problem with STM is that they do not give you any sample programs to learn. Arduino you just google all is there.
enable DMA is Cube Mx
and try something simple first
declare you data
uint8_t data[2];
and try
HAL_UART_Transmit(&huart2, data, 2, 10);
2 is the data array size
10 is 10 ms timeout
2019-01-23 01:35 PM
Thanks for taking the time to respond. I get the same results using that as I did with my original code. It prints "null". I don't currently have a potentiometer connected the the ADC pins, I'm just trying to get the code working before I try this on a different board with the same processor that will have states on the pin. STM definitely makes you work for it, you're exactly right about the Arduino world, that's the place I'm used to but I have to get this working on this chip :)
2019-01-23 01:44 PM
Output of ADC in the debugging screen:
2019-01-23 01:53 PM
the code is right, you must have something incorrect done with initialization in cube mx or there is some problem with terminal in your computer. I assume you use USB to connect to your PC.
You enable asynchronous in cube mx, disable hardware flow control. Do the DMA data lenght byte for USART2_RX. Do the circular mode so it keeps transmiting This is all for cube mx.
this code works HAL_UART_Transmit(&huart2, data, 2, 10); there is nothing else you need. Put the code in while(); loop to test.
It has to work. Look at the terminal you use in your PC.
2019-01-23 02:08 PM
Thanks I will look and get back. I don't think it's my serial monitor because when I type the following, my USART works exactly as it should:
uint8_t mxTxData[13] = "Hello World\r\n";
HAL_UART_Transmit(&huart2,mxTxData,13,10 );
2019-01-23 02:21 PM
You are correct, I am connected to my computer over USB. I had already enabled asynchronous, I don't have RX USART enabled because I only need to send data out over the USART, I don't need to receive anything. Hardware flow control is disabled and "HAL_UART_Transmit(&huart2, data, 2, 10);" is in a while loop but I'm still getting the null character message. I might try to start fresh and see if I can get your example to work and then going to to those code to see where the problem is. I'm all ears if you have any suggestions :) Thanks again for your help!
2019-01-23 04:03 PM
>>The problem with STM is that they do not give you any sample programs to learn.
The HAL libraries comes with literally hundreds of examples.