Page 1 of 1

Serial 1200 Baud with Odd Parity

Posted: Sat Feb 15, 2014 9:00 pm
by Tabulous
Trying to setup SD3 with following serial parameters, 1200 Baud, 8 databits with Odd Parity

ive set serialconfig as this

static const SerialConfig sd3cfg = {
1200,
USART_CR1_M | USART_CR1_PS | USART_CR1_PCE,
0,
0
};

But not getting any data, have i got this setup correctly ?

Re: Serial 1200 Baud with Odd Parity

Posted: Sat Feb 15, 2014 9:23 pm
by Giovanni
Depending on the peripherals clock 1200 bauds could be too low to handle using the 12bits resolution of the BRR register. You may reduce the peripherals clock in mcuconf.h, STM32_PPRE1 for USART3.

I am assuming you are using an STM32F4.

Giovanni

Re: Serial 1200 Baud with Odd Parity

Posted: Sun Feb 16, 2014 9:37 am
by Tabulous
Giovanni wrote:Depending on the peripherals clock 1200 bauds could be too low to handle using the 12bits resolution of the BRR register. You may reduce the peripherals clock in mcuconf.h, STM32_PPRE1 for USART3.

I am assuming you are using an STM32F4.

Giovanni


This was the issue, needed to divide the clock down more, so set STM32_PPRE1 to STM32_PPRE1_DIV8, this seems to work ok.

One thing that did come to mind, its not that intuitive to setup serial ports. My thoughts behind OS level drivers are that they should be well abstracted from the hardware, but i still found myself needing to find out what CR1,Cr2 and CR3 register bits were, so i could match them up to the defines in Chibios.

I'm sure you have seen the how a uart is configured using the STM32 plibs, having a configuration structure like that would be very helpful.

something like


/* Prepare USART parameters - 1200 / 9b / odd parity, no flow control */
SerialConfig.USART_Driver = &SD3;
SerialConfig.USART_BaudRate = 1200;
SerialConfig.USART_WordLength = USART_WordLength_9b;
SerialConfig.USART_StopBits = USART_StopBits_1;
SerialConfig.USART_Parity = USART_Parity_Odd;
SerialConfig.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
sdStart(&SerialConfig);

In the low level driver the above configurations are placed into to correct CRx registers. To me this is alot more intuitive.

Thanks for the help :-)

Re: Serial 1200 Baud with Odd Parity

Posted: Mon Feb 17, 2014 9:06 pm
by Giovanni
You could write an helper function for that, it is not strictly required because would not make the code any more portable nor abstract. HAL configuration structures are meant to be generated by high level tools like it is done in SPC5Studio. By keeping them close to the HW also allows to expose architecture-specific features.

Giovanni