微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32中CAN中断2

STM32中CAN中断2

时间:11-24 来源:互联网 点击:
void CAN_SetBaudRate(uint8_t iBaud)

{

CAN_StructInit(&CAN_InitStructure);

CAN_InitStructure.CAN_TTCM = DISABLE;

CAN_InitStructure.CAN_ABOM = ENABLE; //ENABLE:一旦硬件检测到128 次11位连续的隐性位,则自动退出离线状态

CAN_InitStructure.CAN_AWUM = ENABLE;//ENABLE硬件自动唤醒

CAN_InitStructure.CAN_NART = DISABLE;//DISABLE:CAN报文一直重传直到成功

CAN_InitStructure.CAN_RFLM = ENABLE;//EANBLE:FIFO满之后再次接收到的报文将被丢弃

CAN_InitStructure.CAN_TXFP=ENABLE;//enable:优先级由发送请求的顺序决定

// CAN_InitStructure.CAN_TTCM = DISABLE;

// CAN_InitStructure.CAN_ABOM = DISABLE; //ENABLE:一旦硬件检测到128 次11位连续的隐性位,则自动退出离线状态

// CAN_InitStructure.CAN_AWUM = DISABLE;//ENABLE硬件自动唤醒

// CAN_InitStructure.CAN_NART = DISABLE;//DISABLE:CAN报文一直重传直到成功

// CAN_InitStructure.CAN_RFLM = DISABLE;//EANBLE:FIFO满之后再次接收到的报文将被丢弃

// CAN_InitStructure.CAN_TXFP=DISABLE;//enable:优先级由发送请求的顺序决定

CAN_InitStructure.CAN_Mode =CAN_Mode_Normal;//CAN_Mode_LoopBack;//

if(36000000==SystemCoreClock)

{

switch (iBaud)

{

case 0://5K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 450;

break;

case 1://10K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 225;

break;

case 2: //50K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 45;

break;

case 3: //100K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_14tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 10;

break;

case 4://125K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 9;

break;

case 5: //250K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 9;

break;

case 6://500K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_8tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 3;

break;

case 7: //1M

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_14tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 1;

break;

default://125K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 9;

break;

}

}

else

{

switch (iBaud)

{

case 0://5K

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;

CAN_InitStructure.CAN_Prescaler = 450;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top