cancel
Showing results for 
Search instead for 
Did you mean: 

UART problem

marcl
Associate II
Posted on October 16, 2008 at 01:41

UART problem

3 REPLIES 3
marcl
Associate II
Posted on May 17, 2011 at 12:47

Hello,

I am new with the STM32 programming and I have some problems using the UART. I tried some examples and I can´t see any output on Windows Hyper Terminal, I really don´t know what is the problem.

I am using the Raisonance REva starter kit and this is the source I use:

int main(void)

{

RCC_Configuration();

NVIC_Configuration();

GPIO_Configuration();

UART_Configuration();

USART_Cmd(USART1, ENABLE);

printf(''USART Printf Example: retarget the C library printf function to the USART'');

while (1)

{

}

}

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);

/* PLLCLK = 8MHz * 9 = 72 MHz */

RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

RCC_PLLCmd(ENABLE);

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

{

}

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

while(RCC_GetSYSCLKSource() != 0x08)

{

}

}

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);

}

void GPIO_Configuration(void)

{

/* Configure USART1_Tx as alternate function push-pull */

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);

/* Configure USART1_Rx as input floating */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

void UART_Configuration(void)

{

/* USARTx configured as follow:

- BaudRate = 9600 baud

- Word Length = 8 Bits

- One Stop Bit

- No parity

- Hardware flow control disabled (RTS and CTS signals)

- Receive and transmit enabled */

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_Rx | USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);

}

/*******************************************************************************

* Function Name : PUTCHAR_PROTOTYPE

* Description : Retargets the C library printf function to the USART.

* Input : None

* Output : None

* Return : None

*******************************************************************************/

PUTCHAR_PROTOTYPE

{

/* Write a character to the USART */

USART_SendData(USART1, (u8) ch);

/* Loop until the end of transmission */

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

{

}

return ch;

}

[ This message was edited by: marcl on 08-10-2008 15:34 ]

tibo
Associate II
Posted on May 17, 2011 at 12:47

try this:

PUTCHAR_PROTOTYPE {

while(!USART_GetFlagStatus(USART1, USART_FLAG_TXE)) {

}

USART_SendData(USART1, (u8) ch);

}

jki79ros81
Associate II
Posted on May 17, 2011 at 12:47

[ This message was edited by: jki79ros81 on 16-10-2008 05:17 ]