cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F205RB. Problems with USART

bahec06
Associate
Posted on April 30, 2014 at 21:02

Hi. I have a device with STM32F205RB controller. First of all, i want to transmit any phrase, such as ''Hello World'', using USART. I'm configured external clock, using PLL to set 100 MHz and configured USART. I'm connected my device to computer through USB-UART PL-2303. On computer i'm using Terminal 1.9 to display data from controller. On both side i have a 9600 baud rate. But on the computer i see some strange symbols. What am i doing wrong? Code is below:

#include <STM32F2xx.h>

#include <system_stm32f2xx.h>

#include <stm32f2xx_rcc.h>

#include <stm32f2xx_gpio.h>

#include <stm32f2xx_spi.h>

#include <stm32f2xx_usart.h>

#include <stdio.h>

void ClockSetup(void) {

RCC_DeInit();

RCC->CR |= ((uint32_t)RCC_CR_HSEON);

while((RCC->CR & RCC_CR_HSERDY) == 0){}

FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_3WS;

RCC->CFGR |= RCC_CFGR_HPRE_DIV1;

RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;

RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;

RCC->PLLCFGR = 0x25403214;

RCC->CR |= RCC_CR_PLLON;

while((RCC->CR & RCC_CR_PLLRDY) == 0){}

RCC->CFGR |= RCC_CFGR_SW_PLL;

while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL){}

}

void USART1Setup(void) {

USART_InitTypeDef URT1;

GPIO_InitTypeDef PORTB;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

PORTB.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

PORTB.GPIO_Mode = GPIO_Mode_AF;

PORTB.GPIO_Speed = GPIO_Speed_100MHz;

PORTB.GPIO_OType = GPIO_OType_PP;

PORTB.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOB, &PORTB);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

USART_DeInit(USART1);

URT1.USART_BaudRate = 9600;

URT1.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

URT1.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

URT1.USART_Parity = USART_Parity_No;

URT1.USART_StopBits = USART_StopBits_1;

URT1.USART_WordLength = USART_WordLength_8b;

USART_Init(USART1, &URT1);

USART_Cmd(USART1, ENABLE);

}

void Delay(void) {

volatile uint32_t i;

for (i=0; i != 0x80000; i++);

}

void SendStrtoPC(char* str_p)

{

uint16_t i=0;

while(str_p[i] != 0)

{

while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)

{

}

USART_SendData(USART1, str_p[i]);

i++;

}

}

int main() {

char str[30];

ClockSetup();

USART1Setup();

sprintf(str, ''Hello World'');

while(1) {

SendStrtoPC(str);

Delay();

}

}
1 REPLY 1
Posted on April 30, 2014 at 21:36

Do you have an oscilloscope? Can you confirm the bit timing?

What external clock source are you using? Is it's speed correctly reflected in HSE_VALUE ?

Also use TXE, not TC to determine if you can send another character.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..