请大神帮忙看看 图片中peli_transmit_message的值为何不能成功赋给CAN1_PELI呢
感激不尽
我的CAN 配置函数如下
static void CAN_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1ENR_CAN, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
//CAN RX PA11
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//CAN TX PA12
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_4);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_4);
NVIC_InitStructure.NVIC_IRQChannel = CAN_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void CAN_Config(u32 CAN_Pre, CAN_Mode ID, u32 idCode1, u32 idCode2, u32 mask1, u32 mask2)
{
CAN_Peli_InitTypeDef CAN_Peli_InitStructure;
RCC_ClocksTypeDef RCC_Clocks;
u32 idCodeTemp1, idMaskTemp1;
u32 idCodeTemp2, idMaskTemp2;
CAN_Peli_FilterInitTypeDef CAN_Peli_FilterInitStructure;
//Enter reset mode
CAN_ResetMode_Cmd(CAN1, ENABLE);
//CAN enters Peli mode
CAN_Mode_Cmd(CAN1, CAN_PELIMode);
RCC_GetClocksFreq(&RCC_Clocks);
CAN_Peli_StructInit(&CAN_Peli_InitStructure);
CAN_Peli_FilterStructInit(&CAN_Peli_FilterInitStructure);
CAN_AutoCfg_BaudParam( &CAN_Peli_InitStructure, RCC_Clocks.PCLK1_Frequency, CAN_Pre);
//sampling point
CAN_Peli_InitStructure.SAM = RESET;
//Self-test mode
CAN_Peli_InitStructure.STM = DISABLE;
//Listen to model
CAN_Peli_InitStructure.LOM = DISABLE;
// CAN_Peli_InitStructure.EWLR = 0x96;
CAN_Peli_Init(&CAN_Peli_InitStructure);
switch(ID) {
case StandardFrame_SingleFilter:
idCodeTemp1 = idCode1 << (3 + 18);
idMaskTemp1 = mask1 << (3 + 18);
CAN_Peli_FilterInitStructure.AFM = CAN_FilterMode_Singal;
CAN_Peli_FilterInitStructure.CAN_FilterId0 = (idCodeTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId1 = (idCodeTemp1 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId2 = (idCodeTemp1 >> 8) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId3 = (idCodeTemp1 >> 0) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId0 = (idMaskTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId1 = ((idMaskTemp1 >> 16) & 0xff) | 0x1f;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId2 = ((idMaskTemp1 >> 8) & 0xff) | 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId3 = ((idMaskTemp1 >> 0) & 0xff) | 0xff;
break;
case ExtendedFrame_SingleFilter:
idCodeTemp1 = idCode1 << 3;
idMaskTemp1 = mask1 << 3;
CAN_Peli_FilterInitStructure.AFM = CAN_FilterMode_Singal;
CAN_Peli_FilterInitStructure.CAN_FilterId0 = (idCodeTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId1 = (idCodeTemp1 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId2 = (idCodeTemp1 >> 8) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId3 = idCodeTemp1 & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId0 = (idMaskTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId1 = ((idMaskTemp1 >> 16) & 0xff);
CAN_Peli_FilterInitStructure.CAN_FilterMaskId2 = ((idMaskTemp1 >> 8) & 0xff);
CAN_Peli_FilterInitStructure.CAN_FilterMaskId3 = ((idMaskTemp1 >> 0) & 0xff);
break;
case StandardFrame_DoubleFilter:
idCodeTemp1 = idCode1 << (3 + 18);
idMaskTemp1 = mask1 << (3 + 18);
idCodeTemp2 = idCode2 << (3 + 18);
idMaskTemp2 = mask2 << (3 + 18);
CAN_Peli_FilterInitStructure.AFM = CAN_FilterMode_Double;
CAN_Peli_FilterInitStructure.CAN_FilterId0 = (idCodeTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId1 = (idCodeTemp1 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId2 = (idCodeTemp2 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId3 = (idCodeTemp2 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId0 = (idMaskTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId1 = ((idMaskTemp1 >> 16) & 0xff) | 0x1f;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId2 = (idMaskTemp2 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId3 = ((idMaskTemp2 >> 16) & 0xff) | 0x1f;
break;
case ExtendedFrame_DoubleFilter:
idCodeTemp1 = idCode1 << (3);
idMaskTemp1 = mask1 << (3);
idCodeTemp2 = idCode2 << (3);
idMaskTemp2 = mask2 << (3);
CAN_Peli_FilterInitStructure.AFM = CAN_FilterMode_Double;
CAN_Peli_FilterInitStructure.CAN_FilterId0 = (idCodeTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId1 = (idCodeTemp1 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId2 = (idCodeTemp2 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterId3 = (idCodeTemp2 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId0 = (idMaskTemp1 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId1 = (idMaskTemp1 >> 16) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId2 = (idMaskTemp2 >> 24) & 0xff;
CAN_Peli_FilterInitStructure.CAN_FilterMaskId3 = (idMaskTemp2 >> 16) & 0xff;
break;
default:
break;
}
CAN_Peli_FilterInit(&CAN_Peli_FilterInitStructure);
CAN_Peli_ITConfig(CAN_IT_RI, ENABLE);
//Exit reset mode and enter working mode
CAN_ResetMode_Cmd(CAN1, DISABLE);
}
|