AD搞定了,CAN又卡住了,哪位大神帮看看
void rcuInit(void) //设置系统时钟及外设时钟
{
rcu_deinit(); //复位RCU
rcu_system_clock_source_config(RCU_CKSYSSRC_PLL); //系统时钟CK_SYS为PLL时钟 最高108M
rcu_pll_config(RCU_PLLSRC_HXTAL,9); //外部晶振作为PLL时钟,8倍频 12*8
rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1); //系统时钟1分频作为AHB时钟
rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV1); //AHB时钟1分频作为APB2时钟
//rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV1); //AHB时钟1分频作为APB1时钟
rcu_osci_on(RCU_HXTAL); //打开振荡器--外部高速晶体
rcu_osci_on(RCU_PLL_CK); //打开振荡器--锁相环
rcu_periph_clock_enable(RCU_AF); //使能复用功能时钟
rcu_periph_clock_enable(RCU_GPIOE); //使能GPIOE时钟
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV12); //配置ADC时钟 最大14M APB2时钟12分频为8M
rcu_periph_clock_enable(RCU_ADC1); //使能ADC1时钟
rcu_periph_clock_enable(RCU_GPIOA); //使能GPIOA时钟
rcu_periph_clock_enable(RCU_CAN0); //使能CAN0时钟
}
void gpioInit(void)
{
gpio_init(GPIOE,GPIO_MODE_OUT_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_3); //GPIO参数初始化 PE3输出
gpio_init(GPIOA,GPIO_MODE_AIN,GPIO_OSPEED_50MHZ,GPIO_PIN_2); //PA2模拟输入
gpio_init(GPIOA,GPIO_MODE_IPU,GPIO_OSPEED_50MHZ,GPIO_PIN_11); //RD0上拉输入
gpio_init(GPIOA,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_12); //TD0为AFIO推挽输出
}
void canInit(can_parameter_struct can_parameter, can_filter_parameter_struct can_filter,uint CAN_BAUDRATE)
{
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);//CAN初始化参数结构体
can_struct_para_init(CAN_FILTER_STRUCT, &can_filter);//CAN过滤器参数结构体
can_struct_para_init(CAN_TX_MESSAGE_STRUCT, &transmit_message); //CAN发送信息参数结构体
can_deinit(CAN0);//复位CAN0外设
while(!can_working_mode_set(CAN0,CAN_MODE_INITIALIZE)); //CAN工作模式设置 初始化模式
/* 初始化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; //接收FIFO满时覆盖
can_parameter.trans_fifo_order = DISABLE; //发送FIFO顺序
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; //位段1
can_parameter.time_segment_2 = CAN_BT_BS2_3TQ; //位段2
can_parameter.prescaler = 24;
/* 1MBps */
//#if CAN_BAUDRATE == 1000
// can_parameter.prescaler = 6;
// /* 500KBps */
//#elif CAN_BAUDRATE == 500
// can_parameter.prescaler = 12;
// /* 250KBps */
//#elif CAN_BAUDRATE == 250
// can_parameter.prescaler = 24;
// /* 125KBps */
//#elif CAN_BAUDRATE == 125
// can_parameter.prescaler = 48;
// /* 100KBps */
//#elif CAN_BAUDRATE == 100
// can_parameter.prescaler = 60;
// /* 50KBps */
//#elif CAN_BAUDRATE == 50
// can_parameter.prescaler = 120;
// /* 20KBps */
//#elif CAN_BAUDRATE == 20
// can_parameter.prescaler = 300;
//#else
// can_parameter.prescaler = 24;
//#endif
while(!can_init(CAN0, &can_parameter)); //初始化外设CAN
/* initialize filter */
can_filter.filter_number=0; //过滤器索引号
can_filter.filter_mode = CAN_FILTERMODE_MASK; //过滤模式 掩码模式
can_filter.filter_bits = CAN_FILTERBITS_32BIT; //过滤器位宽
can_filter.filter_list_high = 0x3000; //过滤器列表数高位
can_filter.filter_list_low = 0x0000; //过滤器列表数低位
can_filter.filter_mask_high = 0x3000; //过滤器掩码数高位
can_filter.filter_mask_low = 0x0000; //过滤器掩码数低位
can_filter.filter_fifo_number = CAN_FIFO0; //接收FIFO编号
can_filter.filter_enable = ENABLE; //过滤器工作使能
can_filter_init(&can_filter); //CAN过滤器初始化
while(!can_working_mode_set(CAN0,CAN_MODE_NORMAL)); //CAN工作模式设置 正常模式 硬件自动唤醒
}
void cansend(void)
{
uint m;
transmit_message.tx_sfid = 0x300>>1; //标准格式帧标识符
transmit_message.tx_efid = 0x00; //扩展格式帧标识符
transmit_message.tx_ft = CAN_FT_DATA; //帧类型 数据帧(DATA)或远程帧(REMOTE)
transmit_message.tx_ff = CAN_FF_EXTENDED; //帧格式 标准(STANDARD)或扩展(EXTENDED)
transmit_message.tx_dlen = 2; //数据长度
transmit_message.tx_data[0] = 0x55;
transmit_message.tx_data[1] = 0xAA;
can_message_transmit(CAN0, &transmit_message);
yscx(100);
}
也看不出还有什么问题了 |