STM32E407 Serial port 9 bits

Post Reply
tcv
Posts: 4
Joined: Sat Apr 04, 2020 5:50 pm
Location: VALENCIA - SPAIN

STM32E407 Serial port 9 bits

Post by tcv »

Hi all


I have been working with Arduino for some time and I have decided to make the leap to ARM MCU so I started recently and I have some doubts
I have an Olimex STM32E407 with STM32F407ZGT6
What I intend is to communicate this board with a machine through a serial port, in the same way that I do with the arduino mega 2560.

The peculiarity of this communication is that it uses a 9-bit UART configuration, but not constantly, it only uses 9 bits to send the first byte, the rest of the bytes are sent with the ninth bit deactivated.

I need to do the same with one of the UARTS of the STM32E407 so I appreciate in advance any help or advice to carry out this communication
Regards

This is the code that I use in the arduino mega:

Code: Select all

void sendCommand (byte temp [], int len) // Send frame to EGM
{
  UCSR1B = 0b10011101; // 9 bits on
  serEgm.write (temp [0]); // send first byte (machine address)
  delay (5);
  UCSR1B = 0b10011100; // 9 bits off
  for (int i = 1; i <len; i ++)
  {
    serEgm.write (temp [i]); // send the rest of the bytes of the frame
    delay (5);
  }
}
sheepdoll
Posts: 32
Joined: Fri Dec 20, 2019 6:47 pm

Re: STM32E407 Serial port 9 bits

Post by sheepdoll »

I had a similar issue. In doing some research, there is no real difference between 8 bits with the 9th bit 0 and 9 bits with the 9th bit 0. This is what the start bits are for in Async transmission. They tell the system when to start clocking bits. Then come the parity bits. The stop bit is basically a return to the idle state so the next start bit can be detected. If one is sending 8 bits with the 9th bit high then it is a parity bit.

Where things get messy is when Hardware MCM (multiprocessor communications mode) is used. ST implemented this differenct that AVR. This is where the hardware does the address matching and ignores data that does not match the address. I was not using the hardware address compare register, so I did not bother researching more into this.

-julie

PS: I should also mention that in STM data is written and read as 2 bytes (16 bits) So the buffer is 16 bits even when it is 8 bits. On the AVR the 9th bit is in a control register that requires a separate write or read.
Post Reply

Return to “STM32F4 based boards”