小弟刚刚开始学ARM,这个问题好久了都没有解决,求各位大神帮我改改,我的板的是stm32f207的
#include <stm32f2xx.h>
unsigned char TX_Buffer[]="串口测试!";
unsigned i=0;
void RCC_init(void);
void USART1_IRQHandler(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void USART_initi(void);
int main(void)
{
SystemInit();
RCC_init();
NVIC_Configuration();
GPIO_Configuration();
USART_initi();
// USART_SendData(USART1,TX_Buffer[0]);
while(1);
}
void RCC_init(void)
{
RCC_PCLK2Config(RCC_HCLK_Div4);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //打开串口1时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //打开串口1使用的GPIOA时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
}
void NVIC_Configuration(void)//串口中断配置
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStruct.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=0;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_9;//配置TX管脚;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_10;//配置RX管脚;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
// GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
// GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
// GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_8;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOF,&GPIO_InitStruct);
GPIO_SetBits(GPIOF,GPIO_Pin_7);
GPIO_SetBits(GPIOF,GPIO_Pin_8);
// GPIO_ResetBits(GPIOF,GPIO_Pin_7);
}
void USART_initi(void)
{
USART_InitTypeDef* USART_InitStruct;
// USART_StructInit(USART_InitStruct);
USART_InitStruct->USART_BaudRate = 9600;
USART_InitStruct->USART_WordLength = USART_WordLength_8b;
USART_InitStruct->USART_StopBits = USART_StopBits_1;
USART_InitStruct->USART_Parity = USART_Parity_No ;
USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,USART_InitStruct);
USART_ITConfig(USART1,USART_IT_TXE|USART_IT_RXNE,ENABLE);//打开接收发送中断
USART_Cmd(USART1, ENABLE);//使能串口
}
void USART1_IRQHandler(void)
{
i++;
if(TX_Buffer!='\0')
{
USART_SendData(USART1,TX_Buffer);
}
}
|