2013-11-06 03:26 PM
Does anyone know if you can set Mark or Space parity on the STM32 USARTS?
I only found that you can set Even or Odd parity so far. I need to configure an STM32 for hardware that uses Mark and Space parity bits so any help would be appreciated. Thanks,Devyn #uart-mark-space-parity2013-11-06 03:59 PM
Does anyone know if you can set Mark or Space parity on the STM32 USARTS? I only found that you can set Even or Odd parity so far. I need to configure an STM32 for hardware that uses Mark and Space parity bits so any help would be appreciated.
Set it to 9-bit mode, no parity, and send whatever data patterns you want.2013-11-07 12:15 PM
Thanks for replying, Clive, but how would I send a 9 bit character through the UART? Maybe I'm missing something that's really easy, but I can't think of it.
What I need is to send a message like this:Hex, Binary, Decimal equivalents:
0x115 0b100010101 277 (this is really 21 with a mark parity set)
0x002 0b000000010 2
0x000 0b000000000 0
0x03b 0b000111011 59
0x000 0b000000000 0
0x000 0b000000000 0
0x000 0b000000000 0
0x052 0b001010010 82
so you see, first byte has mark parity(MSB) while all others are space. Just before sending the first byte, I tried to set the UART to 8N2 which should be the equivalent of a mark parity, then set it back to 9N1 before sending the rest of the bytes, but it doesn't seem to change anything. It still sends without making the MSB a 1 for the first byte. Here is my code:uint8_t Message[0] = 21;
uint8_t Message[1] = 2;
uint8_t Message[2] = 0;
uint8_t Message[3] = 59;
uint8_t Message[4] = 0;
uint8_t Message[5] = 0;
uint8_t Message[6] = 0;
uint8_t Message[7] = 82
//set USART3 to 8N2 before sending first byte
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_2;
USART_Init(USART3, &USART_InitStructure);
//send first byte
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) ==RESET);
USART_SendData(USART3, Message[0]);
//set USART3 back to 9N1
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_Init(USART3, &USART_InitStructure);
for (i = 1; i < 8;i++)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, From_MATE_Message[i]);
}
Thanks,
Devyn
2013-11-07 12:29 PM
You'd want to wait on TC before shifting gears.
Or frankly just use 9N1 with USART_SendData(USART1, 0x100 | FirstByte); and USART_SendData(USART1, SubsequentBytes & 0xFF);2013-11-07 12:43 PM
Clive,
Just tried what you said. Works great! Thank you so much for your help! I thought that I had actually tried that before, but here's what I did wrong:Message[0] |= 0x100;
USART_SendData(USART3, Message[0]);
I tried ORing then setting it back into the 8 bit character which didn't do anything, because it only allows 8 bits, but if you do the calculation in the function it will send that 9th bit along with the 8 bit character.
Anyways, thanks Clive! Was working on this issue for a while trying to figure it out.
Devyn
2018-08-21 07:40 AM
With STM32CubeMX, under UART configuration. Why is there no mark parity option available.
Has there been any other workarounds other than above. Above method works though, but is rather troublesome.
2018-08-21 08:06 AM
> Has there been any other workarounds other than above.
Using an external UART.
JW
2018-08-21 10:14 AM
>>Why is there no mark parity option available.
Because the hardware doesn't commit gates to implementing niche functionality.
Use the 9-bit mode and send/receive/check whatever patterns you want.
Why is this troublesome/complex? You're not having to implement a soft-uart.
2018-08-21 12:29 PM
... as if soft-UART would be troublesome or complex... ;)
JW