今天在調(diào)試串口程序時(shí)發(fā)現(xiàn)(STM32107RC),UART4明明就是配置好了,可以發(fā)送,但是就是不能中斷接受。在網(wǎng)上看到很多人也有這個(gè)疑問,今晚終于搞定,順便寫篇博客,希望能幫到下一個(gè)遇到同樣問題的人。最主要的問題是啟動(dòng)代碼有問題,不知道我那啟動(dòng)代碼是什么年代的了,所以沒有添加UART4,UART5.
本文引用地址:http://butianyuan.cn/article/201611/322765.htm如果你出現(xiàn)了這個(gè)問題,去看看啟動(dòng)代碼是否有
IMPORTUART4_IRQHandler
IMPORTUART5_IRQHandler
DCDUART4_IRQHandler
DCDUART5_IRQHandler
如果有的話,還不行,那我也不清楚了。另尋他人!
沒有的話去找個(gè)新的啟動(dòng)引導(dǎo)程序。
順便也把我初始化配置貼出來,大家也好比較!這樣的初始化我是可以運(yùn)行!
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
void UART4_IRQHandler(void)
{能進(jìn)入中斷就行}
Send_String("ABC",3);//發(fā)送函數(shù)
void Send_String(char *buff,INT16U Len)
{
INT16U i;
for(i=0;i{
USART_SendData(UART4,*buff++);
while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET);
}
}
應(yīng)該就這些了。
評(píng)論