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

STM32中CAN中断2

时间:11-24 来源:互联网 点击:

memcpy(ARPBUF->

memcpy(ARPBUF->

ARPBUF->

ARPBUF->

ARPBUF->

ARPBUF->

ARPBUF->

memcpy(ARPBUF->

memcpy(ARPBUF->

memcpy(ARPBUF->

switch ( HON( ARPBUF->

GPIO_Init(GPIO_CAN, &GPIO_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel = CAN1_SCE_IRQn;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

CAN_DeInit(CAN1);

CAN_SetBaudRate(uBaud);

CAN_SetAddr(addr);

CAN_ITConfig(CAN1, CAN_IT_BOF|CAN_IT_EPV |CAN_IT_EWG | CAN_IT_ERR, ENABLE);

}

void ICAN_Reset(void)

{

uint8_t param=*((uint8_t*)(0x1FFFF806));

uint8_t baud=0;

uint8_t addr=0;

GPIO_InitTypeDef GPIO_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |RCC_APB2Periph_GPIO_CAN1, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

if(param==0xff)

{

baud=4;

addr=0x1;

}

else

{

addr=0x1F¶m;

baud=param>>5;

}

CAN_DeInit(CAN1);

CAN_SetBaudRate(baud);

CAN_SetAddr(addr);

CAN_ITConfig(CAN1, CAN_IT_BOF|CAN_IT_EPV |CAN_IT_EWG | CAN_IT_ERR, ENABLE);

}

void CAN1_SCE_IRQHandler(void)

{

static uint8_t error;

if(CAN_GetFlagStatus(CAN1,CAN_FLAG_BOF) == SET)

{

CAN_ClearITPendingBit(CAN1,CAN_IT_BOF);

}

else if(CAN_GetITStatus(CAN1,CAN_IT_ERR))

{

CAN_ClearITPendingBit(CAN1,CAN_IT_ERR);

}

else if(CAN_GetFlagStatus(CAN1,CAN_FLAG_EPV) == SET)

{

CAN_ClearITPendingBit(CAN1,CAN_IT_EPV);

}

else if(CAN_GetFlagStatus(CAN1,CAN_FLAG_EWG) == SET)

{

CAN_ClearITPendingBit(CAN1,CAN_IT_EWG);

}

else

{

CAN_ClearITPendingBit(CAN1,CAN_IT_EWG);

CAN_ClearITPendingBit(CAN1,CAN_IT_EPV);

CAN_ClearITPendingBit(CAN1,CAN_IT_BOF);

CAN_ClearITPendingBit(CAN1,CAN_IT_ERR);

}

error=CAN_GetLastErrorCode(CAN1);

error=error;

ICAN_Init();

}


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

网站地图

Top