2015-09-12 06:51 AM
I'm using STM32F051R8 board but i'm unable to configure UART in 7bit bata and one bit parity mode. Tried changing M and PCE bits of UART CR1 register but no luck.
2015-09-12 07:00 AM
Something like this should work
/* USART2 PA.2 Tx, PA.3 Rx STM32F0-Discovery sourcer32@gmail.com */
#include ''stm32f0xx.h''
#include ''stm32f0_discovery.h''
int main(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
/* Configure USART2 pins: Rx and Tx ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 7 bits plus parity bit
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2,ENABLE);
while(1)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, 'X');
}
}
2015-09-12 07:14 AM
2015-09-12 04:27 PM
This manual?
World Plus Chain-Link icon I'm not using F0 parts, but have no reason to believe the parity function is broken. You have to clear errors before the receiver will receive any more. I guess you'll have to test some more, look at a scope or analyzer, or check the other device. Make sure the baud rate is correct, look at the bit timings on a scope, look at a 'U' character.2015-09-13 09:56 PM
In above document it's on pg 702, table 99.
2015-09-14 08:09 AM
Ok, so what values end up in the Control Registers, and what exactly do you see on a scope if you observe the signal on the wire?
Right now you're telling me ''it doesn't work'', you're going to have to analyze the situation and determine a more exact reason for failure, I don't have your chip, board, or system, and it's not my project.