2017-10-29 04:25 AM
Dear Community
I have a problem with the UART1/2 on the NUCLEO-F042K6 board. I try to read some bytes in polling mode using
HAL_UART_Receive();
And i set the size parameter to any number greater than 1 and i only receive 1 byte, even though i am sending more data from the other side. This is really bizarre, i have used this function countless times in other projects with other controllers, and this is the first time this happens.
When i use the
HAL_UART_Receive_IT();
It reads the whole message that can be 4,8 or 10 bytes.
I have an idea of what i am doing and i used the UART peripheral of the STM boards a lot and everything i tried didn't solved this.
Even more strange is that it happened with several identical boards.
Can someone please help me to figure out how to solve this? or is this some kind of a problem with the specific boards?
Thanks,
Dror.
2017-10-29 07:45 AM
Probably something need to be cleared to receive another byte in polling mode.
However, I would never use RX as polling mode: It should be always under interrupt.
TX can be done in polling mode. I usually send byte by byte if sending text strings which are following printf formatting: While a char is being transmitted, the SW prepare the next character during the masked time.
And one note: Don't show the UART registers in the debugger window as this will be read/refreshed by the debugger.
2017-10-29 07:54 AM
Does it return an error? What is that?
Do you have a timeout that is sufficiently long to encompass all the bytes you are looking to receive? Figure baud rate and character count, and that it doesn't occur instantaneously, and might return a partial buffer that you might need to resubmit to get the remaining characters, if that is determinable.
2017-10-30 12:51 AM
Hi,
I am creating an empty buffer with sufficient number of bytes and still it won't read the amount i tell it to.
When i tried to debug the problem i showed the uint8_t buffer in the watch window and i only see that the first byte is received, other bytes remain 0x00.
2017-10-30 12:54 AM
I get the timeout return, but i tried with 1000 ms timeout to read only 4 bytes, and this was in debug mode, i ran the function after the other side has already sent the 4 bytes. this is not suppose to happen. When i read in interrupt mode the bytes are read immediately and everything works fine.
Baud rate is 115200 so 1000 ms is plenty of time to read 4 bytes.