cancel
Showing results for 
Search instead for 
Did you mean: 

UART messages don't send periodically on STM32F4

RobertoCarrasco
Associate II

I am using a custom PCB based on a STM32F446 MCU. I have followed step by step the ST's tutorial posted on their wiki: (https://wiki.st.com/stm32mcu/wiki/STM32StepByStep:Step3_Introduction_to_the_UART), but I can't see the "Hello World" message once per second in a Putty terminal.

I am using an external clock of 8 MHz, UART4 initialized in PC11 and PC10, and other peripherials are working propertly (such as CAN). 

My final goal is to send a through this UART interface a message for notifying that an event has occurred (for example, a relay has been turned on). I have also tried this implemention, and the messages aren't always sent when the event occurs, just sometimes and randomly (for example, with the CAN interface the messages are sent exactly when the event occurs).

Does anyone have any idea about this issue?

10 REPLIES 10
######
Senior

(Sorry for the random suggestions) in your UART_Transmit call are you making sure you are using the UART4 handle. In the example you linked they use UART2 and UART1 at different parts of the page. Also you could change the code to investigate the return value of the HAL_UART_Transmit function to see if that explains anything. e.g:

uint8_t Test[] = "Hello World !!!\r\n"; //Data to send
if (HAL_UART_Transmit(&huart4,Test,sizeof(Test),10) != HAL_OK)  // Make sure you use huart4
{
while(1); // Something has gone wrong, let's catch it here
}
HAL_Delay(1000);

Or assign it to a variable that you can debug to see if the function returns timeout.

Further to this if this is a custom board are you sure those pins are actually the ones connected in Hardware, and there isn't another issue? On some STM32's the UART functionality can be moved around different pins. i.e. multiple pins for a single UART - looking at the reference manual for that chip it seems UART4 is also on PA0 and PA1 as alternatives.

Best of luck with it.