新手上路
- 积分
- 44
- 金钱
- 44
- 注册时间
- 2016-11-24
- 在线时间
- 6 小时
|
对照教程修改,写的程序如下,我用导线将PD2和PA9边上的RXD,PC12和PA10边上的TXD相连,但是使用串口助手发送数据,没有显示出来
但是使用串口1,用跳线帽正常连接PA9和PA10就可以正常显示
看了下论坛上的关于串口5的帖子,程序都是一样的,所以不知道问题出在什么地方
希望各路大神指教,菜鸟刚学习STM32,使用的是STM32 MINI,上面芯片是STM32F103RCT
#include "stm32f10x.h"
void My_USART5_Init(void)
{
GPIO_InitTypeDef GPIO_InitStrue;
USART_InitTypeDef USART_InitStrue;
NVIC_InitTypeDef NVIC_InitStrue;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//①
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOC,&GPIO_InitStrue);//②
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOD,&GPIO_InitStrue);//②
USART_InitStrue.USART_BaudRate=115200;
USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_InitStrue.USART_Parity=USART_Parity_No;
USART_InitStrue.USART_StopBits=USART_StopBits_1;
USART_InitStrue.USART_WordLength=USART_WordLength_8b;
USART_Init(UART5,&USART_InitStrue);//③
USART_Cmd(UART5,ENABLE);//使能串口1
USART_ITConfig(UART5,USART_IT_RXNE,ENABLE);//开启接收中断
NVIC_InitStrue.NVIC_IRQChannel=UART5_IRQn;
NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStrue);
}
void UART5_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(UART5,USART_IT_RXNE))
{
res= USART_ReceiveData(UART5);
USART_SendData(UART5,res);
}
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
My_USART5_Init();
while(1);
}
|
|