cancel
Showing results for 
Search instead for 
Did you mean: 

Uart in 7bit mode

mustakahmed
Associate II
Posted on September 12, 2015 at 15:51

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.

5 REPLIES 5
Posted on September 12, 2015 at 16:00

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');
}
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mustakahmed
Associate II
Posted on September 12, 2015 at 16:14

Tried and not working.  The device which is sending data operates on 7 data bits and even parity so I'm unable to receive data. In reference manual on page 698 they have mentioned table please refer it ... I'm unable to give direct link sorry...

Posted on September 13, 2015 at 01:27

This manual?

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00031936.pdf

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mustakahmed
Associate II
Posted on September 14, 2015 at 06:56

In above document  it's on pg 702, table 99.

Posted on September 14, 2015 at 17:09

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..