2012-05-06 10:45 AM
Hi all,
I just wanted to share the surprise that I had today when, in order to have the USB CDC example virtualizing USART2 at 115200,8O1 on a STM32F102RB clocked with a 16MHz oscillator I had to configure like this:USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Odd;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
And disable the USART_Config() function because it would break things when called by the application on the PC.
bool
USART_Config(
void
)
{
USART_InitTypeDef USART_InitStructure;
/* set the Stop bit*/
switch
(linecoding.format) {
case
0:
USART_InitStructure.USART_StopBits = USART_StopBits_1;
break
;
case
1:
USART_InitStructure.USART_StopBits = USART_StopBits_1_5;
break
;
case
2:
USART_InitStructure.USART_StopBits = USART_StopBits_2;
break
;
default
:
// USART_Config_Default();
return
(FALSE);
}
/* set the parity bit*/
switch
(linecoding.paritytype) {
case
0:
USART_InitStructure.USART_Parity = USART_Parity_No;
break
;
case
1:
USART_InitStructure.USART_Parity = USART_Parity_Even;
break
;
case
2:
USART_InitStructure.USART_Parity = USART_Parity_Odd;
break
;
default
:
return
(FALSE);
}
/*set the data type : only 8bits and 9bits is supported */
switch
(linecoding.datatype) {
case
0x07:
/* With this configuration a parity (Even or Odd) should be set */
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
break
;
case
0x08:
if
(USART_InitStructure.USART_Parity == USART_Parity_No) {
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
}
else
{
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
}
break
;
default
:
return
(FALSE);
}
USART_InitStructure.USART_BaudRate = linecoding.bitrate;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure and enable the USART */
if
(eDevOnUSB==GPSRX1) {
USART_Init(GPS1UART_PORT, &USART_InitStructure);
USART_Cmd(GPS1UART_PORT, ENABLE);
}
else
if
(eDevOnUSB==GPSRX2) {
// USART_Init(GPS2UART_PORT, &USART_InitStructure);
// USART_Cmd(GPS2UART_PORT, ENABLE);
}
else
if
(eDevOnUSB==RS422) {
USART_Init(RS422_PORT, &USART_InitStructure);
USART_Cmd(RS422_PORT, ENABLE);
}
return
(TRUE);
}
I am wondering if anyone has also noticed that using
USART_Parity_Odd you need to use
USART_WordLength_9b for a normal 801 communication?
Thanks in advance for your kind answers.
Best regards,
Michele
#uart/usart-parity-and-wordlengt
2012-05-07 06:57 PM
DId you try with 8b Wordlength ? I think it shall work without problem.
For your configuration, did you check the signals on Oscilloscope ?2012-05-08 02:13 PM
2012-05-11 07:25 AM
I agree with Chris,,,,
Examples to help...../*USART3 Structure Config*/
USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Even;// Even or Odd
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART3, &USART_InitStructure);/*USART2 Structure Config*/
USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART2, &USART_InitStructure);