本帖最后由 S448 于 2012-7-29 02:45 编辑
现在用的是STM32F103RCT6,USART3的接收中断死活进不去,用示波器监测波形,数据也到了USART3的接收管脚PB11,但就是进不去接收中断,发送数据可以正常发出来,非常奇怪。
以前用过STM32F103VBT6和STM32F103C8T6,也都用过这两个芯片的USART3,一点问题没有,又仔细检查了代码,没有发现问题,所以觉的不是程序配置的问题。
//管脚初始化函数
void RS485_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //RX(PB11)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //Tx(PB10)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //DE(PB2)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//通讯接口初始化函数
void RS485_Init(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate= 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //打开接收中断
USART_Cmd(USART3, ENABLE);
RS485_Rx_CS; //切换到接收状态
}
void USART3_IRQHandler(void)
{
u8 temp=0;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
temp=USART_ReceiveData(USART3);
//其他接收处理。。。。
}
}
//还一个USART3的中断优先级配置
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
上述代码我实在没看出有什么问题,因为在其他型号的STM32F103上我都用过的
实在没招了,现在怀疑买的STM32F103RCT6芯片可能是封装为64脚的其他小FLASH或RAM的STM32F103或STM32F101改了丝印来的。 |