stm32f429 usart1 无数据
最近做stm32f429开发,但是我的串口通信就是没有数据,下面是我参照网上的代码,网上都可以,但是我的不行啊,我用的mini stm32f429开发板+7寸显示屏,求助啊。
void uart_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable GPIOC and GPIOE clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA , ENABLE);
/* Enable USART1 APB clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* USART1 Pins configuration
************************************************/
/* Connect pin to Periph */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
/* Configure pins as AF pushpull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure); //TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure); //RX
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART
USART_InitStructure.USART_BaudRate = bound;
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_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
void USART1_IRQHandler(void)
{
u8 Res;
#ifdef OS_TICKS_PER_SEC
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART1);//(USART1->DR);
if((USART_RX_STA&0x8000)==0)
{
if(USART_RX_STA&0x4000)
{
if(Res!=0x0a)USART_RX_STA=0;
else USART_RX_STA|=0x8000;
}
else
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-
1))USART_RX_STA=0;
}
}
}
}
RE:stm32f429 usart1 无数据
试试修改官方提供的例程, 那个使能正常使用的RE:stm32f429 usart1 无数据
自己把RX和TX短接一下看看能不能收到数据。对照一下配置还有你的电路板,RX和TX是不是一致的。
回复:stm32f429 usart1 无数据
我这几天做测试,stm32f103什么都可以,但是我做f4系列的都不行,stm32f407和stm32f429,我用官网的都收不到数据。RE:stm32f429 usart1 无数据
1.你既然选择的是引脚复用,为什么不把引脚复用时钟打开呢?2.发送端口引脚配置成复用推挽,接收端口配置成浮空,你俩引脚配置的都一样吧
3.其他的我就不细看了,你把上面俩问题解决再说
RE:stm32f429 usart1 无数据
引脚配置对的话, 时钟引用的作用又是什么RE:stm32f429 usart1 无数据
103的串口与F4的还是有点区别的,如果你不想麻烦的去调试的话,就一直官方F4的串口程序。你可以进入调试模式,单步调试,看你的串口的GPIO是否配置到了,看串口是否配置到了,然后,万用表或者示波器观察一下输出。这个需要自己去调,我这里倒是有现成的程序,但是还是不给你更好,我的经验,发现的问题越多就对其认识越深。如果,你真的要现成的程序,可以给你RE:stm32f429 usart1 无数据
请问楼主解决问题没有??我的程序问题弄不来了,接收的跟发送的数据不一样……RE:stm32f429 usart1 无数据
数据不一样就是波特率的问题,如果一直都没有数据的话有可能是硬件问题,管脚虚焊
页:
[1]