本帖最后由 we76092822 于 2016-8-24 18:07 编辑
我目前使用了USART1跟USART6配置都一样但是只有USART1进得去接收中断USART6却进不去
想請問要怎麼才能讓USART6也進去
附上我的程式码
void bsp_InitUart(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOG, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_USART6, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource14, GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource9, GPIO_AF_USART6);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOG, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 19200;
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_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(USART6, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART6, ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART6,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART1, USART_IT_ORE_RX, ENABLE);
USART_ITConfig(USART6, USART_IT_ORE_RX, ENABLE);
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_EnableIRQ(USART6_IRQn);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn | USART6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_EnableIRQ(USART1_IRQn);
}
void USART6_IRQHandler(void)
{
if(USART_GetFlagStatus(USART6,USART_FLAG_RXNE)==SET)
{
USART_ClearITPendingBit(USART6, USART_IT_RXNE);
wififlag=1;
}
}
void USART1_IRQHandler(void)
{
char c;
char p;
char b;
char d;
if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==SET)
{
c = USART_ReceiveData(USART1);
d=(c&0xf0) /16;
if(d==0x0A || d==0x0B || d==0x0C || d==0x0D || d==0x0E || d==0x0F)
d=d+0x37;
if(d==0x00 || d==0x01 || d==0x02 || d==0x03 || d==0x04 || d==0x05 || d==0x06 || d==0x07 || d==0x08 || d==0x09)
d=d+0x30;
b=(c&0x0f);
if(b==0x0A || b==0x0B || b==0x0C || b==0x0D || b==0x0E || b==0x0F)
b=b+0x37;
if(b==0x00 || b==0x01 || b==0x02 || b==0x03 || b==0x04 || b==0x05 || b==0x06 || b==0x07 || b==0x08 || b==0x09)
b=b+0x30;
qaz[a] = d;
a++;
qaz[a]=b;
a++;
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
ttt=1;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
主要检查几个地方:
1.GPIO寄存器对应位模式设置是否为2,复用寄存对应位值是否为8
2.检查NVIC中对应的中断向量是否使能
3.检查USART寄存器中的中断位是否置位
4.检查中断服务函数是否和启动文件中定义的函数名相同.
以上如果都对,那就是硬件连线的问题.
一周热门 更多>