2018-07-10 01:37 PM
Hi,
When I enable my USART peripheral it sends an unwanted byte interpreted as 0xFE.
To enable the USART peripheral, I first enable it in the APBENR register then I reset it through APBRSTR.
I then disable flow control, and program the baudrate.
I then configure the number of stop bits (0, this is quasi default communication) and then I enable USART through CR1 register. After that all what is left is to enable the TE and RE bit in CR1.
After sending this unwanted byte, it all works very well because I can send data without any problem at the correct baudrate. There is juste this annoying byte that get sent first...
Do you have any idea where I should look ?
I think it may be related to this note in the datasheet :
Note: 1: During transmission, a “0�? pulse on the TE bit (“0�? followed by “1�?) sends a preamble
(idle line) after the current word, except in smartcard mode. 2: When TE is set there is a 1 bit-time delay before the transmission starts.Thanks a lot & have a nice day !
Note: this post was migrated and contained many threaded conversations, some content may be missing.2018-07-11 01:46 AM
Yes, that remark is probably related. I usually set all 3 bits (TE, RE, UE) at once, by one writing into the CR1, and haven't observed any problem (but honestly, did not look very carefully so far).
JW
2018-07-11 03:07 AM
Read the data register immediately after initializing the USART, but before enabling interrupts. This will clear any junk sitting there.
-- pa
2018-07-11 05:26 AM
I also set all of them at once...
Here is a capture of what is happening :
The unwanted byte is the first 0xFF isolated from the rest.
2018-07-11 05:35 AM
I tried multiple ways of reading to DR. Reading it with gdb should be working right ? I also tried to read it from my program but it changed nothing.
Moreover the reference specify that the registers is initialized with 0.
I really don't know what to do...
2018-07-11 06:31 AM
I tried multiple ways of reading to DR. Reading it with gdb should be working right ? I also tried to read it from my program but it changed nothing.
This is expected, because a read accesses the RX register, and not TX. In other words, this shouldn't make a difference.
Pretty sure you do some init accesses in a wrong order. I used to base my UART code on SPL examples, and never had such an issue. And thus I can't remember the detailed order ...
2018-07-11 06:44 AM
Here is my init routine in pseudo code.
I am using USART3 clocked through APB1.
I don't use any interrupt for the moment.
2018-07-11 06:58 AM
Just as an example, my initialization of UART3 on a F407 looks like this (SPL-based):
void initUART3 (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART3, ENABLE); // USART clock
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD, ENABLE); // GPIO clock
GPIO_PinAFConfig (GPIOD, GPIO_PinSource8, GPIO_AF_USART3); // configure AF
GPIO_PinAFConfig (GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
GPIO_InitStructure.GPIO_OType = ... <et cetera >
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = ... <et cetera >
USART_Init (USART3, &USART_InitStructure);
USART_ClockInitStructure.USART_Clock = ... <et cetera >
USART_ClockInit (USART3, &USART_ClockInitStructure);
USART_Cmd (USART3, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = ... <et cetera >
NVIC_Init (&NVIC_InitStructure);
/* Interrupt at reception and receive errors */
USART_ITConfig (USART3, USART_IT_RXNE, ENABLE);
USART_ITConfig (USART3, USART_IT_ERR, ENABLE);
}
Actual init values left out, they are of no interest here, supposedly.
2018-07-11 07:02 AM
Show code.
JW
2018-07-11 07:02 AM
I don't do any kind of GPIO initialization except for enabling them and setting up the alternate function.
Is there anything else that I should do ?