如题 CAN1通信不成功 初始化代码是从别的板子搬过来的 对照手册修改过
是哪里的问题 求大佬指出 小弟给大神跪了
void CAN1_Init(void)
{
rcu_periph_clock_enable(RCU_CAN1);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
/* configure CAN1 GPIO */
gpio_init(GPIOB,GPIO_MODE_IPU,GPIO_OSPEED_50MHZ,GPIO_PIN_5);
gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_6);
gpio_pin_remap_config(GPIO_CAN1_REMAP,ENABLE);
nvic_irq_enable(CAN1_RX0_IRQn,0,0);
can_deinit(CAN1);
/* initialize CAN parameters */
can_init_parameter.time_triggered=DISABLE;
can_init_parameter.auto_bus_off_recovery=DISABLE;
can_init_parameter.auto_wake_up=DISABLE;
can_init_parameter.no_auto_retrans=DISABLE;
can_init_parameter.rec_fifo_overwrite=DISABLE;
can_init_parameter.trans_fifo_order=DISABLE;
can_init_parameter.working_mode=CAN_NORMAL_MODE;
can_init_parameter.resync_jump_width=CAN_BT_SJW_1TQ;
can_init_parameter.time_segment_1=CAN_BT_BS1_5TQ;
can_init_parameter.time_segment_2=CAN_BT_BS2_4TQ;
can_init_parameter.prescaler =24;
can_init(CAN1, &can_init_parameter);
/* initialize filter */
can_filter_parameter.filter_number=0;
can_filter_parameter.filter_mode = CAN_FILTERMODE_MASK;
can_filter_parameter.filter_bits = CAN_FILTERBITS_32BIT;
can_filter_parameter.filter_list_high = (((uint32_t)0x5A5<<21)&0xffff0000)>>16;
can_filter_parameter.filter_list_low = 0x0000;
can_filter_parameter.filter_mask_high = 0xffff;
can_filter_parameter.filter_mask_low = 0xffff;
can_filter_parameter.filter_fifo_number = CAN_FIFO0;
can_filter_parameter.filter_enable=ENABLE;
can_filter_init(&can_filter_parameter);
/* CAN1 filter number */
can_filter_parameter.filter_number=15;
can_filter_init(&can_filter_parameter);
can_interrupt_enable(CAN1, CAN_INTEN_RFNEIE0);
}
void CAN_test(void)
{
transmit_message.tx_sfid = 0x05A5;
transmit_message.tx_efid = 0x00;
transmit_message.tx_ft = CAN_FT_DATA;
transmit_message.tx_ff = CAN_FF_STANDARD;
transmit_message.tx_dlen = 2;
transmit_message.tx_data[0] = 0x00;
transmit_message.tx_data[1] = 0x05;
can_message_transmit(CAN1, &transmit_message);
}
|