我的CAN1的配置如下,不论怎么试都进不了中断函数。求大家帮忙看看
void My_CAN1_Init(uint32_t _baudRate)
{
//´´½¨ÉèÖýṹÌå
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 /
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else / VECT_TAB_FLASH /
/ Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
// RCC_ClocksTypeDef rcc_clocks;
// RCC_GetClocksFreq(&rcc_clocks);
// SystemInit();
//¿ªÆôGPIOºÍCAN1µÄʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉÏÀÊäÈë
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM=DISABLE; //ʱ¼ä´¥·¢Ä£Ê½
CAN_InitStructure.CAN_ABOM=ENABLE; //×Ô¶¯ÀëÏß¹ÜÀí
CAN_InitStructure.CAN_AWUM=DISABLE; //×Ô¶¯»½ÐÑģʽ
CAN_InitStructure.CAN_NART=DISABLE; //·Ç×Ô¶¯ÖØ´«Ä£Ê½
CAN_InitStructure.CAN_RFLM=DISABLE; //½ÓÊÜFIFOËø¶¨Ä£Ê½
CAN_InitStructure.CAN_TXFP=ENABLE; //·¢ËÍFIFOģʽ
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal; //Õý³£Ä£Ê½
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler= 6000000 / _baudRate; //²¨ÌØÂʹ«Ê½=72M/(2*(SJW+BS1+BS2)*Prescale)
CAN_Init(CAN1, &CAN_InitStructure);
//ÅäÖùýÂËÆ÷
CAN_FilterInitStructure.CAN_FilterNumber= 0; //Â˲¨Æ÷Ñ¡Ôñ0~13
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //Ö¸¶¨¹ýÂËÆ÷Ϊ±êʶ·ûÆÁ±Îģʽ
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //¹ýÂËÆ÷λ¿íΪ32λ
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; //Òª¹ýÂ˵ÄID¸ßλ
CAN_FilterInitStructure.CAN_FilterIdLow= 0x0000; //Òª¹ýÂ˵ÄIDµÍλ
CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0x0000; //¹ýÂËÆ÷ÆÁ±Î±êʶ·ûµÄ¸ß16λ
CAN_FilterInitStructure.CAN_FilterMaskIdLow= 0x0000; //¹ýÂËÆ÷ÆÁ±Î±êʶ·ûµÄµÍ16λ
CAN_FilterInitStructure.CAN_FilterFIFOAssignment= CAN_FilterFIFO0;//É趨ÁËÖ¸Ïò¹ýÂËÆ÷µÄFIFOΪ0
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //¹ýÂËÆ÷ʹÄÜ
CAN_FilterInit(&CAN_FilterInitStructure);
//CAN1ÖжÏÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//CAN1 FIFOʹÄÜ
CAN_ClearITPendingBit(CAN1,CAN_IT_FF0);
CAN_ClearITPendingBit(CAN1,CAN_IT_FOV0);
CAN_ITConfig(CAN1,CAN_IT_FMP0,ENABLE);
}
#define Get_Gryo_Data USB_LP_CAN1_RX0_IRQHandler
void Get_Gryo_Data(void)
{
static int16_t x_angle_data, y_angle_data, z_angle_data, z_anglespeed_data;
static float x_origin_angle, y_origin_angle, z_origin_angle, z_origin_anglespeed;
CanRxMsg rx_message;
if (CAN_GetITStatus(GRYO_CAN, CAN_IT_FMP0) != RESET)
{
CAN_Receive(GRYO_CAN, CAN_FIFO0, &rx_message);
if ((rx_message.IDE == CAN_ID_STD) && (rx_message.RTR == CAN_RTR_DATA)) //标准帧、数据帧、数据长度为8
{
if (rx_message.StdId == 0x401)
{
z_angle_data = ((rx_message.Data[1] << 8) | rx_message.Data[0]);
x_angle_data = ((rx_message.Data[3] << 8) | rx_message.Data[2]);
y_angle_data = ((rx_message.Data[5] << 8) | rx_message.Data[4]);
z_origin_angle = z_angle_data / 10000.0 * RAD2DEG;
x_origin_angle = x_angle_data / 10000.0 * RAD2DEG;
y_origin_angle = y_angle_data / 10000.0 * RAD2DEG;
gps_z_angle = z_origin_angle - gps_z_angle_offset;
gps_x_angle = x_origin_angle;
gps_y_angle = y_origin_angle;
int_gps_z_angle = (uint16_t)gps_z_angle;
int_gps_x_angle = (uint16_t)gps_x_angle;
int_gps_y_angle = (uint16_t)gps_y_angle;
}
if (rx_message.StdId == 0x402)
{
z_anglespeed_data = ((rx_message.Data[5] << 8) | rx_message.Data[4]);
z_origin_anglespeed = z_anglespeed_data / 32768.0 * GRYO_RANGE;
gps_z_anglespeed = z_origin_anglespeed - gps_z_anglespeed_offset;
int_gps_z_anglespeed = (uint16_t)gps_z_anglespeed;
}
}
CAN_FIFORelease(GRYO_CAN, CAN_FIFO0);
}