目前用到MM32SPIN06PF,仿真查看的数据配置的帧ID和写书数据都是对的,但是发送到总线上帧ID就对不上,但是数据包的数据都是对的,这是哪里配置还不对吗。帧类型扩展帧
static void CAN_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*ÍâÉèʱÖÓÉèÖÃ*/
RCC_APB2PeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Configure CAN pin: RX PA11*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // ÉÏÀÊäÈë
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure CAN pin: TX PA12 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // ¸´ÓÃÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_4);
}
static void CAN_Mode_Config(void)
{
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, 50000);
//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);
}
static void CAN_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*ÖжÏÉèÖÃ*/
NVIC_InitStructure.NVIC_IRQChannel = CAN_IRQn; //CAN1 RX0ÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPriority = 0; //ÇÀÕ¼ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
static void CAN_Mode_Config(void)
{
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, 50000);
//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);
}
static void CAN_Filter_Config(CAN_Mode ID, u32 idCode1, u32 idCode2, u32 mask1, u32 mask2)
{
CAN_Peli_FilterInitTypeDef CAN_Peli_FilterInitStructure;
u32 idCodeTemp1, idMaskTemp1;
u32 idCodeTemp2, idMaskTemp2;
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);
}
void CAN_Config(void)
{
CAN_GPIO_Config();
CAN_NVIC_Config();
CAN_Mode_Config();
CAN_Filter_Config(ExtendedFrame_SingleFilter,0xff,0xff,0x00,0x00);
}
|