1
我有问题试图在我的F4Discovery开发板(基于STM32F407)上使用UART(USART1)。我对STM32和Keil(我使用的IDE)非常陌生。这里是我的代码:UART与STM32F407(F4Discovery)
#include "stm32f4_discovery.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx.h"
void usartSetup(void);
void USART_PutChar(uint8_t ch);
int main (void) {
usartSetup();
USART_PutChar(0); //I realise this won't send a 0
USART_PutChar(8); //I realise this won't send an 8
USART_PutChar(255); //I realise this won't send a 255
while (1) {
//loop forever
}
}
void usartSetup (void) {
USART_InitTypeDef USART_InitStructure;
//USART_StructInit(&USART_InitStructure);
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);
USART_Cmd(USART1, ENABLE);
}
void USART_PutChar(uint8_t ch) {
USART_SendData(USART1, (uint16_t) 0x49);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, (uint16_t) 0x49);
}
如果有人能帮上忙,我会很感激。它从不将0x49从UART1发送出去(检查引脚PA9和PB6),然后在(USART_GetFlagStatus ...)无休止地卡住。我正在观察使用Keil调试器,并看到它陷入了一阵子。
我在项目中加入了stm32f4xx_usart.c驱动。
谢谢!
http://www.github.com/dwelch67/stm32f4d有一定的UART程序,低水平嵌入。也许他们也许不会帮忙。 – 2012-03-26 13:52:16
谢谢,非常有用的链接。看看uart01,代码与我的距离很远,我很难弥合这个差距。 – user1228123 2012-03-26 14:15:12
问题不在于配置GPIO和时钟。我在ST论坛上找到了一些很好的信息。 – user1228123 2012-03-26 15:44:12