probelm with UART between arduino uno and an stm32f407vg discovery board

Hi, I want to test the UART between an arduino uno and an stm32f407vg discovery board but all I get is junk characters.
I am able to send/receive characters and strings and numbers between 2 arduinos or between 2 stm32f407vg discovery boards so I think the code is fine.

Here is what I did:

arduino uno rx --> logic level shifter --> PA2
arduino uno tx --> PA3
A common ground between the arduino uno, the logic level shifter, the stm32f4.

I am using the same configuration on both boards: 9600 baudrate, 1 stop bit, no parity, PA2 and PA3 are pulled up and I tried both open drain and push pull.

Am I missing something?

void setup() {
  Serial.begin(9600);
  while ( ! Serial ){
    ;
  }
  pinMode(8, OUTPUT);

}
char c =0;
void loop() {
  if ( Serial.available() ){
    while ( (c = Serial.read()) > 0 ){
          Serial.write(c);
          if ( c == 'A' ){
            digitalWrite(8, HIGH);
          }
          else if ( c == 'B' ){
            digitalWrite(8, LOW);
          }
    }
  }
}
int main(void){
     // gpio initialisation PA2 and PA3 pulled up, push pull( also tried open drain), alternative function
     //usart initialisation 9600 baudrate, 1 stop bit, no parity and no hardware flow control
     char to_send[16]="ABBAABABA";
     int i=0;
     while ( 1) {
         for(i=0; i<strlen(to_send);++i){
                 putcc(to_send[i]);
                 delay();
         }
     }
}
int putcc(int n){
  while ( USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET ) {
   ;
 }
  char to_send = (char)n ; // for debugging pruposes
  USART2->DR = to_send ;
  return 0 ;
}

You have not posted a link to the datasheet for the stm32f407vg

Is it producing a signal at TTL or RS232 voltages?
And if at TTL voltages, what voltage is it working at?

What Arduino are you using?
And what voltage is it working at?

...R
Serial Input Basics

Please don't add extra information to a previous post - put it in a new Reply.

I think you have been looking for complicated answers to my simple questions.

All I needed to know was whether you are using a 5v or a 3.3v Arduino and whether your STM board is 5v or 3.3v.

I "think" you are saying that the STM board works at 3.3v but can accept 5v inputs and an Uno works at 5v. If I am correct I doubt if there is any need for a level-shifter between them.

When I asked for the datasheet for the STM board I was hoping there would be something the equivalent of the spec for an Uno (rather than an Atmega 328). I don't feel like wading through 1748 pages of the ST datasheet.

And you can assume that most people here are familiar with the relevant Atmega datasheets.

...R

Thank you for taking the time to read my post :).

The stm32f4 sends at most 3 volts for an output high, the 5 volts arduino uno needs at least 3 volts so I thought I need a conversion from the 3 volts to the 5 volts:

stm32f4 TX sends 3v --> logic level shifter --> arduino uno RX receives 5v.

Of course you don't have to read the reference, ask me anything about the stm32f4 and I'll look for the answer in the reference.

stm32f4 ------> stm32f4 OK
arduino uno ------> arduino uno OK
stm32f4 ------> arduino uno KO

  • when the stm32f4 sends a character the arduino receives two!
    example : stm32f4 sends A the arduino receives äÿ

  • when the arduino sends a charcter the stm32f4 receives one.
    example : arduino sends A the stm32f4 receives þ.

You describe the thing as a "stm32f407vg discovery board". Do you not have a link to any data for the whole board rather than the STM chip?

Or is the discovery board simply a breakout board to facilitate easy accesss to the chip?

What is the overall purpose of the chip/board? Why are you using it?
What data should the chip send to the Arduino?
What data should the Arduino send to the chip?
The more general information you provide the easier it is to make sense of the problem.

What chapter of the datasheet deals with Serial communication?

...R

  1. The stm32f4 discovery board is like an arduino but with a ARM cortex m4 core and a few peripherals. Here is a link to the user manual of the board:
    http://www.st.com/content/ccc/resource/technical/document/user_manual/70/fe/4a/3f/e7/e1/4f/7d/DM00039084.pdf/files/DM00039084.pdf/jcr:content/translations/en.DM00039084.pdf

  2. I am using it for education purposes, I want to get familiar with both the arm cortex m4 and the atmega328p.

  3. & 4) The stm32f4 sends a character and based on the character the arduino will do different things

Thank you very much :slight_smile: .

I don't have time now to read that document. I can't immediately see where it describes the electrical characteristics.

I am finding it very hard to get you to give me useful information that might enable me to help you. If that is my fault I apologise.

Have you written a program for the STM board? If so, what does it do?

Have you tried using any of the Arduino examples in the link I gave you in Reply #1?

Are you trying to use Serial (pins 0 and 1) on the Arduino to communicate with the STM as well as with the Arduino Serial Monitor? That is not a good idea.

...R