AnsweredAssumed Answered

STM32F429 USART Communication with Arduino Uno

Question asked by Daattavya Aggarwal on Aug 21, 2017
Latest reply on Aug 21, 2017 by Clive One

Hello. I am trying to perform usart communication between the stm32f429 discovery board and the arduino uno. I have tried both sending and receiving data with the stm board but it is not working. I am sharing the codes I have used for receiving data with the stm board. Any help would be appreciated.

 

STM:

#include <stm32f4xx.h>
void led_init()
{
RCC ->AHB1ENR |= RCC_AHB1ENR_GPIOGEN; //Enables port G input output pins by setting the corresponding bit in advanced high performance bus 1 register.
GPIOG ->MODER |= GPIO_MODER_MODER13_0; //Configures pin 13 as a general purpose output pin by setting the corresponding bit in the mode register
GPIOG ->OTYPER &= ~(GPIO_OTYPER_OT_13); //Makes the output type as push-pull by resetting the corresponding bit in output type register.
GPIOG ->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR13_0;//Makes the output medium speed.
GPIOG ->PUPDR &= ~(GPIO_PUPDR_PUPDR13);//No pull up or pull down.
}
void usart_setup()
{

 

RCC ->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
GPIOA->MODER |= GPIO_MODER_MODER3_1;
GPIOA->AFR[0] |= GPIO_AF7_USART2<<12;
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
USART2->CR1 |= USART_CR1_UE;
USART2->BRR |= 0x2580;
USART2->CR1 |= USART_CR1_RE;

}
char usart_read()
{
char ch;
while(!(USART2->SR & USART_SR_RXNE))

ch = USART2->DR;
return ch;

}
int main(void)
{
led_init();
usart_setup();
while(1)
{
GPIOG->BSRRH|=GPIO_BSRR_BS_13;
if(usart_read())
GPIOG->BSRRL|=GPIO_BSRR_BS_13;
}
}

 

Arduino:

#include <SoftwareSerial.h>
int incoming = 0;
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// put your setup code here, to run once:

Serial.begin(9600);
mySerial.begin(9600);
}

void loop() {
mySerial.write('a');
}

 

As arduino uno runs on 5 volt logic, I am already using a level shifter between the stm board and the arduino.

 

Thanks

Outcomes