cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with USART

vderoc
Associate
Posted on March 15, 2016 at 08:31

HI, I'm trying to develop a simple communication with my laptop sending just one character, the problem is that I need to send the character more than 5 times for reconogise it in the Discovery board, the code is simple.

void USART1init()

{

usart1.Instance = USART1;

usart1.Init.BaudRate = 9600;

usart1.Init.WordLength = USART_WORDLENGTH_8B;

usart1.Init.StopBits = USART_STOPBITS_1;

usart1.Init.Parity = USART_PARITY_NONE;

usart1.Init.Mode = USART_MODE_TX_RX;

usart1.Init.CLKPolarity = USART_POLARITY_LOW;

usart1.Init.CLKPhase = USART_PHASE_1EDGE;

usart1.Init.CLKLastBit = USART_LASTBIT_DISABLE;

HAL_USART_Init(&usart1);

}

void USART1_Pins_Init(){

RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN;//Damos reloj al GPIO

RCC->APB2ENR|=RCC_APB2ENR_USART1EN;//Damos reloj al USART1

//__USART1_CLK_ENABLE();

GPIO_InitTypeDef GPIO_InitStruct;

    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF7_USART1;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

void Read_Usart1(){

uint8_t Buffer=0;

uint16_t Size=1;

uint32_t Timeout=500;

HAL_USART_Receive(&usart1,&Buffer,Size,Timeout);

if (Buffer=='B')Led_ON();

if (Buffer=='C')Led_OFF();

}
2 REPLIES 2
Posted on March 15, 2016 at 10:34

Ok, and which of the dozens of different discovery boards would this be?

The STM32F407-DISCO would have a problem with PA9 due to VERY large capacitor. Does it work better at 1200 baud?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vderoc
Associate
Posted on March 15, 2016 at 11:15

Thanks, my board is the STM32 discovery 429-DISC0

I´ve checked it at 1200 baud and it doesn´t work,

this time don´t recive anything