cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2xx USART 9 Databit, 1 Start bit, 2 stop bit, parity odd

f2
Associate II
Posted on November 06, 2013 at 09:34

Hello,

i'm trying to get a USART connection to a device with the parameters:  USART 9600 Baud, 9 (real)Databits, 1 Start bit, 2 stop bits, parity odd.

I configured my USART like this:

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_9b;

USART_InitStructure.USART_StopBits = USART_StopBits_2;

USART_InitStructure.USART_Parity = USART_Parity_Odd;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

The Problem is,  that the receiver dont understand my commands. Somebody in a german forum told me, that the STM32 cant handle this mode, because the 9th bit is used for the parity an i have to do this with software USART. Ist this right? I cant believe that.

In the RM0033 - 24.3.1 ''Figure 224. Word length programming'' it looks so :(

How can i solve this problem in a smart way? Any Ideas?

regards

Florian

#throwing-my-stapler
9 REPLIES 9
Posted on November 06, 2013 at 10:36

Use an external UART or a small slave microcontroller.

JW
f2
Associate II
Posted on November 06, 2013 at 12:45

I have to implement this in the STM32F2 Controller. An additional component is not a cheap way 🙂

Posted on November 06, 2013 at 13:03

> I have to implement this in the STM32F2 Controller.

Then you have to go for bit-banging.

> An additional component is not a cheap way 🙂

This heavily depends on your definition of cheap...

JW

Posted on November 06, 2013 at 13:38

Do you need Tx only, or Tx and Rx? Remember someone having an odd LCD display module using a 9-bit protocol discussed here some time ago.

If just Tx, could you use a SPI 16-bit mode to emulate the signalling? Slave, with TIM generating a baud rate clock?

What are you communicating with that needs such a non-standard protocol?
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on November 06, 2013 at 13:58

Now of course this is up to the OP, but IMO it's not any simpler than bit-banging in timer interrupt. Contrary maybe.

There are of course latency considerations, but, cm'on, 9600 Baud on a multitenmegahertz 32-bitter? Oh how many times did we this on the 8-bitters at a few megahertz back then...

JW

Posted on November 06, 2013 at 14:17

Just throwing it out there. We just seem to see a lot of posters who focus on the implementation problems, without adequately framing the question.

I know how and where to find the STM32 documentation, and some of it's capabilities, what I don't know is anything about the device being attached.

So, I'm using XYZ display, and it's requirement is 9-bit Odd Parity at 10 Kbaud, here's a cite for the datasheet. Would be far more useful.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
f2
Associate II
Posted on November 07, 2013 at 10:12

Hello clive1,

i need Rx and Tx. At this Time i build a Timer with an 104µs interupt and shift the bits to a port. it works fine, but: i would like to implement a better (smarter) solution. Something with DMA access maybee.

With my question i would like to learn more about the possibilities of an STM32 µC. I hoped to get an hint or idea of a real crack 🙂

(Only reading the manual wouldn't be succesfully in this case )

regards

Florian

Posted on November 07, 2013 at 13:14

I think the SPI peripheral could be used for TX (Slave mode, with TIM driven baud clock), a TIM peripheral in Input Capture could time stamp edges for RX which could be decomposed, perhaps accumulated via DMA. Bit harder as the number of edges is variable depending on the symbol.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
f2
Associate II
Posted on November 07, 2013 at 14:17

Hello clive1,

thanks for your idea. i will check the actual portconfig and discuss it.

regards

Florian