本文整理汇总了C++中CAN_ITConfig函数的典型用法代码示例。如果您正苦于以下问题:C++ CAN_ITConfig函数的具体用法?C++ CAN_ITConfig怎么用?C++ CAN_ITConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CAN_ITConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: can_init
void can_init(can_t* can_filters)
{
gpio_clock_init(GPIOA);
can_clock_init(CAN1);
GPIO_InitTypeDef GPIO_InitStructure =
{
.GPIO_Pin = CAN_RX_PIN,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
};
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CAN_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
CAN_InitTypeDef CAN_InitStructure;
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_Prescaler = 1;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_4tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_11tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_4tq;
CAN_InitStructure.CAN_ABOM = ENABLE;
CAN_InitStructure.CAN_RFLM = ENABLE;
CAN_Init(CAN1, &CAN_InitStructure);
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CAN1, CAN_IT_FMP1, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure =
{
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
.NVIC_IRQChannelPreemptionPriority = 7,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
};
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX1_IRQn;
NVIC_Init(&NVIC_InitStructure);
for (int i = 0; i < can_filters->n_filters; i++)
CAN_FilterInit(can_filters->CAN_filterInit + i);
xCAN_receive_queue0 = xQueueCreate(10, sizeof(CanRxMsg));
xCAN_receive_queue1 = xQueueCreate(10, sizeof(CanRxMsg));
}
void USB_LP_CAN1_RX0_IRQHandler()
{
CanRxMsg RxMessage;
portBASE_TYPE resch = pdFALSE;
CAN_Receive(CAN1, CAN_FIFO0,&RxMessage);
xQueueSendFromISR(xCAN_receive_queue0, &RxMessage, &resch);
portEND_SWITCHING_ISR(resch);
}
示例2: Can1_Init
void Can1_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
// 首先打开电源及时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 然后配置pin
Can_GPIO_Config();
CAN_config_init();
CAN_ITConfig(CAN1, CAN_IT_FMP0 | CAN_IT_FF0 | CAN_IT_FOV0, ENABLE); // fifo0中断
CAN_ITConfig(CAN1, CAN_IT_FMP1 | CAN_IT_FF1 | CAN_IT_FOV1, ENABLE); // fifo1中断
//CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE); // 发送中断
}
示例3: Can_Hw_DisableControllerInterrupts
EXPORT void Can_Hw_DisableControllerInterrupts(uint8 controller)
{
imask_t state;
Can_UnitType *canUnit;
CAN_HW_t *canHw;
canUnit = CAN_GET_PRIVATE_DATA(controller);
VALIDATE_NO_RV( (canUnit->state!=CANIF_CS_UNINIT), 0x4, CAN_E_UNINIT );
Irq_Save(state);
if(canUnit->lock_cnt > 0 )
{
// Interrupts already disabled
canUnit->lock_cnt++;
Irq_Restore(state);
return;
}
canUnit->lock_cnt++;
Irq_Restore(state);
/* Don't try to be intelligent, turn everything off */
canHw = GetController(controller);
/* Turn off the tx interrupt mailboxes */
CAN_ITConfig(canHw, CAN_IT_TME, DISABLE);
/* Turn off the bus off/tx warning/rx warning and error and rx */
CAN_ITConfig(canHw, CAN_IT_FMP0 | CAN_IT_BOF | CAN_IT_ERR | CAN_IT_WKU, DISABLE);
}
示例4: hal_can_enable
extern hal_result_t hal_can_enable(hal_can_t id)
{
hal_result_t res;
//hal_can_internals_t *intitem = s_hal_can_internals[HAL_can_id2index(id)];
hal_can_internal_item_t* intitem = s_hal_can_theinternals.items[HAL_can_id2index(id)];
CAN_TypeDef* CANx = HAL_can_port2peripheral(id);
if(hal_false == s_hal_can_initted_is(id))
{
return(hal_res_NOK_generic);
}
if(NULL == intitem)
{
return(hal_res_NOK_generic);
}
//res = s_hal_can_hw_registers_init(id); // hardware setup
hl_can_enable((hl_can_t)id);
if(res != hal_res_OK)
{
return(hal_res_NOK_generic);
}
// disable scheduling
hal_base_osal_scheduling_suspend();
intitem->enabled = 1;
// configure interrupts on rx (CAN_IT_FMP0 -> FIFO 0 message pending) and tx (CAN_IT_TME -> transmit mailbox empty)
// it is the same using only one call of CAN_ITConfig() or two ...
CAN_ITConfig(HAL_can_port2peripheral(id), (CAN_IT_FMP0 | CAN_IT_TME), ENABLE);
//CAN_ITConfig(HAL_can_port2peripheral(id), CAN_IT_FMP0, ENABLE);
//CAN_ITConfig(HAL_can_port2peripheral(id), CAN_IT_TME, ENABLE);
CAN_ITConfig( HAL_can_port2peripheral(id), CAN_IT_ERROR, ENABLE); // VALE
// nvic
s_hal_can_isr_rx_enable(id);
// dont enable the nvic for the tx
//s_hal_can_tx_enable(id);
s_hal_can_isr_tx_disable(id);
intitem->txisrisenabled = 0;
s_hal_can_isr_err_enable(id);// VALE
// it is in can driver by K&%L. it was not in hal-1. it seems not be important. it does not make can2 work ..
CANx->MCR &= ~(1 << 0); /* normal operating mode, reset INRQ */
while (CANx->MSR & (1 << 0));
// enable scheduling
hal_base_osal_scheduling_restart();
return(hal_res_OK);
}
示例5: Can_IT_Config
void Can_IT_Config(void)
{
#if USE_CAN1_R0
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
#endif
#if USE_CAN1_R1
CAN_ITConfig(CAN1, CAN_IT_FMP1, ENABLE);
#endif
#if USE_CAN2_R0
CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
#endif
#if USE_CAN2_R1
CAN_ITConfig(CAN2, CAN_IT_FMP1, ENABLE);
#endif
}
示例6: can1_init
/*
***************************************************************
* 名称: can1_init
* 功能: can1初始化
* 输入: 1.baud_num
* 输出: NULL
* 返回: NULL
* 描述: 无
***************************************************************
*/
void can1_init(u32 baud_num)
{
CAN_InitTypeDef CAN_InitStructure;
/* CAN register init */
CAN_NVIC_Configuration();
CAN_GPIO_Configuration();
CAN_Address_GPIO_Config();
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE; // 非时间触发通信模式
CAN_InitStructure.CAN_ABOM = DISABLE; // 软件自动离线管理
CAN_InitStructure.CAN_AWUM = DISABLE; // 睡眠模式通过软件唤醒(清除CAN->MCR的SLEEP位)
CAN_InitStructure.CAN_NART = DISABLE; // 禁止报文自动传送
CAN_InitStructure.CAN_RFLM = DISABLE; // 报文不锁定,新的覆盖旧的
CAN_InitStructure.CAN_TXFP = ENABLE; // 优先级由报文标识符决定
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = BaudTable[baud_num].SJW;
CAN_InitStructure.CAN_BS1 = BaudTable[baud_num].BS1;
CAN_InitStructure.CAN_BS2 = BaudTable[baud_num].BS2;
CAN_InitStructure.CAN_Prescaler = BaudTable[baud_num].PreScale;
CAN_Init(CAN1, &CAN_InitStructure);
//设置CAN接收过滤器
CAN_ConfigFilter(0, 0x7ff); // 广播地址,接受广播命令
CAN_ConfigFilter(1, Read_CAN_Address()&0x7f); // 本节点真实地址
//使能接收中断
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}
示例7: PIOS_CAN_TxGeneric
/**
* @brief This function handles CAN1 TX irq and sends more data if available
*/
static void PIOS_CAN_TxGeneric(void)
{
CAN_ClearITPendingBit(can_dev->cfg->regs, CAN_IT_TME);
bool valid = PIOS_CAN_validate(can_dev);
PIOS_Assert(valid);
bool tx_need_yield = false;
if (can_dev->tx_out_cb) {
// Prepare CAN message structure
CanTxMsg msg;
msg.StdId = CAN_COM_ID;
msg.ExtId = 0;
msg.IDE = CAN_ID_STD;
msg.RTR = CAN_RTR_DATA;
msg.DLC = (can_dev->tx_out_cb)(can_dev->tx_out_context, msg.Data, MAX_SEND_LEN, NULL, &tx_need_yield);
// Send message and get mailbox number
if (msg.DLC > 0) {
CAN_Transmit(can_dev->cfg->regs, &msg);
} else {
CAN_ITConfig(can_dev->cfg->regs, CAN_IT_TME, DISABLE);
}
// TODO: deal with failure to send and keep the message to retransmit
}
#if defined(PIOS_INCLUDE_FREERTOS)
portEND_SWITCHING_ISR(tx_need_yield ? pdTRUE : pdFALSE);
#endif /* defined(PIOS_INCLUDE_FREERTOS) */
}
示例8: RecvFrame
int RecvFrame(u8 type,u8 *pRecvFrame)
{
u8 os_err;
int iLength=0;//系统时间 有问题
while(1){
switch(type){
case OBD_TYPE_ISO:
iLength=Normal_RecvFrame(pRecvFrame,50);
break;
case OBD_TYPE_KWP:
iLength=KWP_RecvFrame(pRecvFrame);
break;
case OBD_TYPE_VPW:
iLength=VPW_RecvFrame(pRecvFrame);
break;
case OBD_TYPE_PWM:
iLength=PWM_RecvFrame(pRecvFrame);
break;
case OBD_TYPE_CAN1:
case OBD_TYPE_CAN2:
CAN_ITConfig(CAN1,CAN_IT_FMP0 | CAN_IT_FOV0, ENABLE);
OSSemPend(sem_obd_prot, 1*OS_TICKS_PER_SEC, &os_err);//timeout: 1 seconds
if(os_err)break;
iLength=CAN_RecvFrame(pRecvFrame);
break;
}
if(iLength==0)continue;
else break;
}
my_icar.event = 0;
return iLength;
}
示例9: CAN_device_init_1
static void CAN_device_init_1(int baud)
{
CAN_DeInit(CAN1);
/* CAN GPIOs configuration ************************************************* */
/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
/* Connect CAN pins to Alternate Function */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_9);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_9);
initGPIO(GPIOB, GPIO_Pin_8 | GPIO_Pin_9);
/* CAN configuration ******************************************************* */
/* Enable CAN clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
initCAN(CAN1, baud);
//set default filter
CAN_device_set_filter(0, 0, 0, 0, 0);
/* Enable FIFO 0 message pending Interrupt */
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
initCANInterrupts(CAN1, USB_LP_CAN1_RX0_IRQn);
}
示例10: CAN2_TX_IRQHandler
void CAN2_TX_IRQHandler(void)
{
CanTxMsg tx;
if(_buffer_pull(__can->tx,&tx,sizeof(CanTxMsg)))
CAN_Transmit(CAN2,&tx);
else
CAN_ITConfig(CAN2, CAN_IT_TME, DISABLE);
}
示例11: CAN_Config
void CAN_Config(void) {
CAN_InitTypeDef CAN_InitStruct;
CAN_FilterInitTypeDef CAN_FilterInitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_9);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_9);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
// can peripherial
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
CAN_StructInit(&CAN_InitStruct);
CAN_InitStruct.CAN_ABOM = DISABLE;
CAN_InitStruct.CAN_AWUM = DISABLE;
CAN_InitStruct.CAN_NART = DISABLE;
CAN_InitStruct.CAN_RFLM = DISABLE;
CAN_InitStruct.CAN_TTCM = DISABLE;
CAN_InitStruct.CAN_TXFP = DISABLE;
CAN_InitStruct.CAN_Prescaler = 18; // 125000 Baud rate assuimg CAN speed 36MHz
CAN_InitStruct.CAN_SJW = CAN_SJW_1tq;
CAN_InitStruct.CAN_BS1 = CAN_BS1_13tq;
CAN_InitStruct.CAN_BS2 = CAN_BS2_2tq;
CAN_InitStruct.CAN_Mode = CAN_Mode_Normal;
CAN_Init(CAN1, &CAN_InitStruct);
// can filter
CAN_FilterInitStruct.CAN_FilterNumber = 0;
CAN_FilterInitStruct.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStruct.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStruct.CAN_FilterActivation = ENABLE;
CAN_FilterInitStruct.CAN_FilterFIFOAssignment = CAN_FIFO0;
CAN_FilterInitStruct.CAN_FilterIdHigh = 0;
CAN_FilterInitStruct.CAN_FilterIdLow = 0;
CAN_FilterInitStruct.CAN_FilterMaskIdHigh = 0;
CAN_FilterInitStruct.CAN_FilterMaskIdLow = 0;
CAN_FilterInit(&CAN_FilterInitStruct);
// can interrupt
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
NVIC_InitStruct.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStruct);
}
示例12: RCC_AHB1PeriphClockCmd
void DST_CAN_1::CAN_Configuration_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//使能相关时钟
RCC_AHB1PeriphClockCmd(RCC_CAN_1, ENABLE);//使能PORTA时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);//使能CAN1时钟
//初始化GPIO
GPIO_InitStructure.GPIO_Pin = CAN_1_TX | CAN_1_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIO_CAN_1, &GPIO_InitStructure);//初始化CAN_1_TX,CAN_1_RX
//引脚复用映射配置
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_CAN1); //GPIOD1复用为CAN1_TX
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_CAN1); //GPIOD0复用为CAN1_RX
//CAN单元设置
CAN_InitStructure.CAN_TTCM=DISABLE; //非时间触发通信模式
CAN_InitStructure.CAN_ABOM=DISABLE; //软件自动离线管理
CAN_InitStructure.CAN_AWUM=DISABLE;//睡眠模式通过软件唤醒(清除CAN->MCR的SLEEP位)
CAN_InitStructure.CAN_NART=ENABLE; //禁止报文自动传送
CAN_InitStructure.CAN_RFLM=DISABLE; //报文不锁定,新的覆盖旧的
CAN_InitStructure.CAN_TXFP=DISABLE; //优先级由报文标识符决定
CAN_InitStructure.CAN_Mode= CAN_Mode_Normal; //模式设置
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; //重新同步跳跃宽度(Tsjw)为tsjw+1个时间单位 CAN_SJW_1tq~CAN_SJW_4tq
CAN_InitStructure.CAN_BS1=CAN_BS1_9tq; //Tbs1范围CAN_BS1_1tq ~CAN_BS1_16tq
CAN_InitStructure.CAN_BS2=CAN_BS2_4tq;//Tbs2范围CAN_BS2_1tq ~ CAN_BS2_8tq
CAN_InitStructure.CAN_Prescaler=3; //分频系数(Fdiv)为brp+1
CAN_Init(CAN1, &CAN_InitStructure); // 初始化CAN1
//配置过滤器
CAN_FilterInitStructure.CAN_FilterNumber=0; //过滤器0
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //32位
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;////32位ID
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;//32位MASK
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;//过滤器0关联到FIFO0
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //激活过滤器0
CAN_FilterInit(&CAN_FilterInitStructure);//滤波器初始化
CAN_ITConfig(CAN1,CAN_IT_FMP0,ENABLE);//★FIFO0★消息挂号中断允许.
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // 主优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // 次优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
示例13: Can_Hw_EnableControllerInterrupts
EXPORT void Can_Hw_EnableControllerInterrupts( uint8 controller )
{
imask_t state;
Can_UnitType *canUnit;
CAN_HW_t *canHw;
const Can_ControllerConfigType *canHwConfig;
canUnit = CAN_GET_PRIVATE_DATA(controller);
VALIDATE_NO_RV( (canUnit->state!=CANIF_CS_UNINIT), 0x5, CAN_E_UNINIT );
Irq_Save(state);
if( canUnit->lock_cnt > 1 )
{
// IRQ should still be disabled so just decrement counter
canUnit->lock_cnt--;
Irq_Restore(state);
return;
} else if (canUnit->lock_cnt == 1)
{
canUnit->lock_cnt = 0;
}
Irq_Restore(state);
canHw = GetController(controller);
canHwConfig = CAN_GET_CONTROLLER_CONFIG(Can_Global.channelMap[controller]);
if( canHwConfig->CanRxProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
/* Turn on the rx interrupt */
CAN_ITConfig(canHw, CAN_IT_FMP0, ENABLE);
}
if( canHwConfig->CanTxProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
/* Turn on the tx interrupt mailboxes */
CAN_ITConfig(canHw, CAN_IT_TME, ENABLE);
}
// BusOff here represents all errors and warnings
if( canHwConfig->CanBusOffProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
/* Turn on the bus off/tx warning/rx warning and error and rx */
CAN_ITConfig(canHw, CAN_IT_BOF | CAN_IT_ERR | CAN_IT_WKU, ENABLE);
}
return;
}
示例14: PIOS_CAN_RxStart
static void PIOS_CAN_RxStart(uintptr_t can_id, uint16_t rx_bytes_avail)
{
struct pios_can_dev *can_dev = (struct pios_can_dev *)can_id;
bool valid = PIOS_CAN_validate(can_dev);
PIOS_Assert(valid);
CAN_ITConfig(can_dev->cfg->regs, CAN_IT_FMP1, ENABLE);
}
示例15: InitCAN
void InitCAN(void)
{
// Setup CAN Pins
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Alternate functions
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
// Setup CAN-modules
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* CAN register init */
CAN_DeInit(CAN1);
/* CAN cell init */
CAN_InitTypeDef CAN_InitStructure;
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_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_3tq;
/* CAN Baudrate = 500 KBps (CAN clocked at 42 MHz) */
CAN_InitStructure.CAN_BS1 = CAN_BS1_4tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler = (42000000 / 7) / 500000;
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* Enable FIFO 0 message pending Interrupt */
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}