AnsweredAssumed Answered

USART Send String Problem

Question asked by DamnCM on May 30, 2014
Latest reply on May 30, 2014 by Clive One
Hi, I need your help...
I try to use the USART1 of the STM32F107 to send a string ("HELLO WORLD") but on the hyperterminal, I receive just the first letter ("H"). I cannot found the fault, I use Coocox CoIDE with the GCC ARM compiler. Here's my code:

#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_usart.h"
#include "misc.h"

ErrorStatus HSEStartUpStatus;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void USART_Configuration(void);
void USART_Send(USART_TypeDef*,volatile char*);

int main(void)
{
     RCC_Configuration();
     GPIO_Configuration();
     USART_Configuration();

     USART_Send(USART1,"HELLO WORLD");

     while(1)
     {
     }
     return 0;
}

void RCC_Configuration(void)
{
     RCC_DeInit();
     RCC_HSEConfig(RCC_HSE_ON);
     HSEStartUpStatus = RCC_WaitForHSEStartUp();
     if(HSEStartUpStatus == SUCCESS)
     {
          FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
          FLASH_SetLatency(FLASH_Latency_2);
          RCC_HCLKConfig(RCC_SYSCLK_Div1);
          RCC_PCLK2Config(RCC_HCLK_Div1);
          RCC_PCLK1Config(RCC_HCLK_Div2);
          RCC_PREDIV2Config(RCC_PREDIV2_Div5);
          RCC_PLL2Config(RCC_PLL2Mul_8);
          RCC_PLL2Cmd(ENABLE);
          while(RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET){}
          RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2,RCC_PREDIV1_Div5);
          RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_9);
          RCC_PLLCmd(ENABLE);
          while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){}
          RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
          while(RCC_GetSYSCLKSource() != 0x08){}
     }
     SysTick_Config(SystemCoreClock/1000);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
}

void GPIO_Configuration()
{
     /* TX - PA9 */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
     GPIO_Init(GPIOA,&GPIO_InitStructure);

     /* RX - PA10 */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
     GPIO_Init(GPIOA,&GPIO_InitStructure);
}

void USART_Configuration(void)
{
     USART_InitStructure.USART_BaudRate = 9600;
     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
     USART_InitStructure.USART_StopBits = USART_StopBits_1;
     USART_InitStructure.USART_Parity = USART_Parity_No;
     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
     USART_InitStructure.USART_Mode = USART_Mode_Tx;
     USART_Init(USART1,&USART_InitStructure);
     USART_Cmd(USART1,ENABLE);
}

void USART_Send(USART_TypeDef* USARTx,volatile char *str)
{
     while(*str)
     {
          while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE) == RESET);
          USART_SendData(USARTx,*str);
          str++;
     }
}

Outcomes