guoyux 发表于 2016-7-19 17:06:35

stm32f030c8t6 usart2无法进入接收中断

int main(void)
{
delay_init();
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
led_conf();      
//中断管理
NVIC_uConfiguration();      
//USART1和USART2初始化配置
//USART1_uConfiguration();//9600,n,8,1 使能接收中断
USART2_uConfiguration();//9600,n,8,1 使能接收中断
//_3485_ENABLE_CONFIG();
      led_on();
      delay_us(700);
//      开中断标志位
while(1)
{
//                USART_SendData(USART1,String);
                USART_SendData(USART2,String);
                delay_ms(3000);
}      
}



void USART2_uConfiguration(void)
{
      GPIO_InitTypeDef   GPIO_uInitStructure,GPIO_uInitStr;
      USART_InitTypeDefUSART_uInitStructure;      
      // USART2_TX -> PA2
      // USART2_RX -> PA3
      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
      
      GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_1);
      GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1);
      
      GPIO_uInitStructure.GPIO_Pin = GPIO_Pin_2;
      GPIO_uInitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_uInitStructure.GPIO_OType = GPIO_OType_OD;
      GPIO_uInitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_uInitStructure.GPIO_Speed = GPIO_Speed_50MHz;// 50M
      GPIO_Init(GPIOA,&GPIO_uInitStructure);
      
      GPIO_uInitStr.GPIO_Pin = GPIO_Pin_3;
      GPIO_uInitStr.GPIO_Mode = GPIO_Mode_AF;
      GPIO_uInitStr.GPIO_OType = GPIO_OType_OD;
      GPIO_uInitStr.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_uInitStr.GPIO_Speed = GPIO_Speed_50MHz;// 50M
      GPIO_Init(GPIOA,&GPIO_uInitStr);
      
      USART_uInitStructure.USART_BaudRate = 9600;
      USART_uInitStructure.USART_Parity = USART_Parity_No;
      USART_uInitStructure.USART_StopBits = USART_StopBits_1;
      USART_uInitStructure.USART_WordLength = USART_WordLength_8b;
      USART_uInitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
      USART_uInitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
      USART_Init(USART2,&USART_uInitStructure);
      USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
      USART_Cmd(USART2,ENABLE);
}



void NVIC_uConfiguration(void)
{
NVIC_InitTypeDef      NVIC_InitStructure;
      NVIC_InitTypeDef      NVIC_InitStructure1;
      
//NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;      
//NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//NVIC_Init(&NVIC_InitStructure);      
      

NVIC_InitStructure1.NVIC_IRQChannel = USART2_IRQn;      
NVIC_InitStructure1.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure1.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure1);
}




void USART2_IRQHandler(void)      
{
      led_off();
      if(USART_GetITStatus(USART2,USART_IT_RXNE)==SET)
      {
                USART_ClearITPendingBit(USART2,USART_IT_RXNE);
                String=USART_ReceiveData(USART2);
      }
}



主程序里一直发送0x55,串口调试助手也可以接到的,说明发送没问题。我在中断服务函数写了led_off(),如果中断,led灯会熄灭,可是使用串口调试助手发送数据led并没有熄灭,发送字符也没有改变


guoyux 发表于 2016-7-19 17:08:09

大神们,帮忙看看。

chen_hang 发表于 2016-7-19 19:41:49

你好像没有进行中断分组,没有调用这个函数NVIC_PriorityGroupConfig();

guoyux 发表于 2016-7-19 22:59:38

chen_hang 发表于 2016-7-19 19:41
你好像没有进行中断分组,没有调用这个函数NVIC_PriorityGroupConfig();

我用的是stm32f030c8,好像没有这个函数。

anobodykey 发表于 2016-7-20 10:19:34

改成
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
试下呢

guoyux 发表于 2016-7-20 10:38:19

现在可以了,只是硬件上,PA3口虚焊:loveliness:谢谢大家

chen_hang 发表于 2016-7-20 13:14:56

guoyux 发表于 2016-7-19 22:59
我用的是stm32f030c8,好像没有这个函数。

这个函数肯定有的 你没有调用肯定会出问题的

anobodykey 发表于 2016-7-20 13:42:41

chen_hang 发表于 2016-7-20 13:14
这个函数肯定有的 你没有调用肯定会出问题的

不是的,你说的那个函数是在M3和M4中会有用到,M0中的中断跟M3和M4不同,是没有优先级分组的,只有抢占优先级而没有子优先级之类的,所以没有该接口。

chen_hang 发表于 2016-7-28 20:37:53

anobodykey 发表于 2016-7-20 13:42
不是的,你说的那个函数是在M3和M4中会有用到,M0中的中断跟M3和M4不同,是没有优先级分组的,只有抢占优 ...

这个我还真不知道 学习了
页: [1]
查看完整版本: stm32f030c8t6 usart2无法进入接收中断