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 ;
}
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.
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:
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?
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.