菜鸟请教一下各位大神,GD32单片机的NVIC是怎么使用的,
本人在CAN初始化过程中使能了CAN的接收中断就出现死机现象,具体代码如下:
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1);/*代码一直卡死在这里*/
}
我的CAN初始化函数模块代码如下:
/* 使能CAN0时钟 */
rcu_periph_clock_enable(RCU_CAN0);
rcu_periph_clock_enable(RCU_GPIOD);
/*打开CAN的NVIC中断程序直接跑死,屏蔽改代码,程序正常运行*/
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
/* configure CAN0 NVIC */
nvic_irq_enable(CAN0_RX0_IRQn,0,1);
/* configure CAN0 GPIO */
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_0);
gpio_af_set(GPIOD, GPIO_AF_9, GPIO_PIN_0);
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_1);
gpio_af_set(GPIOD, GPIO_AF_9, GPIO_PIN_1);
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);
can_struct_para_init(CAN_FILTER_STRUCT, &can_filter);
/* initialize CAN register */
can_deinit(CAN0);
/* initialize CAN */
can_parameter.time_triggered = DISABLE;
can_parameter.auto_bus_off_recovery = DISABLE;
can_parameter.auto_wake_up = DISABLE;
can_parameter.no_auto_retrans = DISABLE;
can_parameter.rec_fifo_overwrite = DISABLE;
can_parameter.trans_fifo_order = DISABLE;
can_parameter.working_mode = CAN_NORMAL_MODE;
can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
can_parameter.time_segment_1 = CAN_BT_BS1_5TQ;
can_parameter.time_segment_2 = CAN_BT_BS2_4TQ;
/* 1MBps */
if(1000 == rate)
{
can_parameter.prescaler = 5;
}
else if(500 == rate)
{
can_parameter.prescaler = 10;
}
else if(250 == rate)
{
can_parameter.prescaler = 20;
}
else if(125 == rate)
{
can_parameter.prescaler = 40;
}
else
{
can_parameter.prescaler = 20;
}
can_init(CAN0, &can_parameter);
/* initialize filter */
can_filter.filter_number = 0;
/* initialize filter */
can_filter.filter_mode = CAN_FILTERMODE_MASK;
can_filter.filter_bits = CAN_FILTERBITS_32BIT;
can_filter.filter_list_high = 0x0000;
can_filter.filter_list_low = 0x0000;
can_filter.filter_mask_high = 0x0000;
can_filter.filter_mask_low = 0x0000;
can_filter.filter_fifo_number = CAN_FIFO0;
can_filter.filter_enable = ENABLE;
can_filter_init(&can_filter);
/* enable CAN receive FIFO1 not empty interrupt */
can_interrupt_enable(CAN0, CAN_INT_RFNE0);
PS:我的工程中还用到了RTOS,我是在OS启动之前就调用CAN初始化函数
各位楼主,还请帮忙看看是什么原因导致的
|