AnsweredAssumed Answered

Question on UART and HSE setting on Keli

Question asked by yuen.jason on Jan 12, 2013
Latest reply on Jan 13, 2013 by Clive One
I am writing the program on Usart but the program is not function well. 
Here is the program:

#include <STM32F4xx.h>
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"


USART_InitTypeDef UART1_InitS; 
GPIO_InitTypeDef  GPIO_UART1A; 
GPIO_InitTypeDef  GPIO_UART1B; 


uint16_t Uart_ReadByte(void);




void GPIO_Configuration(void);
void Uart_Configuration(void);
void Uart_WriteByte(uint8_t writeByte);
void RCC_Configuration(void); 
void ledon (int i) {
     GPIOD->ODR |= ((1UL << (i+12)));
}
void RCC_Configuration(void)

//           RCC->AHB1ENR  |= ((1UL <<  3) );         /* Enable GPIOD clock                */
//       GPIOD->MODER = 0x55000000;
//      GPIOD->OTYPER==0x0000;


     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //Check the port condition
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,  ENABLE);
}


void GPIO_Configuration(void)
{
  GPIO_UART1A.GPIO_Pin =  GPIO_Pin_9;
  GPIO_UART1A.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_UART1A.GPIO_Mode = GPIO_Mode_AF;
     GPIO_UART1A.GPIO_OType = GPIO_OType_PP;
     GPIO_UART1A.GPIO_PuPd = GPIO_PuPd_UP;               // enable pull up resistors
  GPIO_Init(GPIOA,&GPIO_UART1A);
     
     GPIO_UART1B.GPIO_Pin =  GPIO_Pin_10;
  GPIO_UART1B.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_UART1B.GPIO_Mode = GPIO_Mode_IN;     
     GPIO_UART1B.GPIO_PuPd =  GPIO_PuPd_NOPULL;               // enable pull up resistors
  GPIO_Init(GPIOA, &GPIO_UART1B);
     
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1) ;
}


void UART_Configuration(void)

     UART1_InitS.USART_BaudRate = 9600;
     UART1_InitS.USART_WordLength = USART_WordLength_8b;
     UART1_InitS.USART_StopBits = USART_StopBits_1;
  UART1_InitS.USART_Parity = USART_Parity_No;
  UART1_InitS.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
     UART1_InitS.USART_HardwareFlowControl = USART_HardwareFlowControl_None;  
     
     USART_Init(USART1, &UART1_InitS);
     USART_Cmd(USART1, ENABLE);
}
void Delay(void )
{int i ;
     for(i =0; i!= 100000; i++);
}


void Uart_WriteByte(uint8_t writeByte)
{
     while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
     USART_SendData(USART1, (uint8_t)writeByte);
}


uint16_t UART_ReadByte()
{
     uint16_t temp =0 ;
     while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
          temp =  USART_ReceiveData(USART1);
     return (uint16_t) temp & 0x00FF;
}




int main (void) {
  
     int loop = 0;
     RCC_Configuration();
     GPIO_Configuration();
     UART_Configuration();


     for(loop = 'a'; loop != 'z' +1; loop++)
          {Uart_WriteByte(loop); Delay();}
          ledon(3);
  
}

Here is the char I have recieved :  ðàà€ðààà

I have read some posts and some of them point out that HSE must be set correctly.
So I have already change the HSE 

In stm32f4xx.h ,

#if !defined  (HSE_VALUE) 
  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

In stm32f4xxconf.h ,
#if defined  (HSE_VALUE)
/* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */
 #undef HSE_VALUE
 #define HSE_VALUE    ((uint32_t)8000000) 

And the ex

So, my questions are 
1. Are the setting of the USART1 wrong???
2. Is that the problem on setting the external clock??
3.  Are the any setting I have to modify in the Keli project setting???

Outcomes