刚刚学习072,can无法成功初始化,怎么回事,死在了这里,CAN_Init
void CAN_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_4);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_4);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* 定义 CAN 控制器和过滤器初始化结构体 */
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN 寄存器复位 */
CAN_DeInit(CAN);
CAN_StructInit(&CAN_InitStructure);
/*
* CAN 控制器初始化:
*
* 失能时间触发通讯模式
* 失能自动离线管理
* 失能自动唤醒模式
* 失能非自动重传输模式
* 失能接收 FIFO 锁定模式
* 失能发送 FIFO 优先级
* CAN 硬件工作在环回模式
* 重新同步跳跃宽度 1 个时间单位
* 时间段 1 为 8 个时间单位
* 时间段 2 为 7 个时间单位
* 分频数为5
*/
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_LoopBack;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_8tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler = 5;
CAN_Init(CAN, &CAN_InitStructure);
CAN_Init返回失败值,怎么回事?
|