使用STM32F429,SN65HVD230芯片,8脚接1K电阻。用5块板子测试,A机轮询查看其它四台机子数据,每一台都有120欧终端电阻,机子之间2m距离。
目前,如果是4台机子测试时,A机能够轮询其它3台机子数据,同时也能正常FIFO0的接收中断。但如果将第4台接上,A机就无法轮询了,无法进入接收中断。
请问下各位大侠,可能是哪方面出了问题,有点急,谢谢各位了!
下面是CAN1的主要配置:
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
uint16_t mask = 0x7FF, temp;
//显示屏、主副机要关注的报文ID
uint16_t FilterIDDISP[]={NUMASENDDATA, NUMBSENDDATA, NUMCSENDDATA,
NUMDSENDDATA, NUMESENDDATA, NUMFSENDDATA
};
uint16_t FilterIDA[]={DISPCLEANOUT,DISPSENDTEMPLIMIT, DISPSENDDELAYLIMIT, DISPSENDRESTORE,
REQUEST_NUMADATA
};
uint16_t FilterIDB[]={DISPCLEANOUT,DISPSENDTEMPLIMIT, DISPSENDDELAYLIMIT, DISPSENDRESTORE,
NUMASENDFANCMD, NUMASENDVIRUSCMD,
REQUEST_NUMADATA
};
uint16_t FilterIDC[]={DISPCLEANOUT,DISPSENDTEMPLIMIT, DISPSENDDELAYLIMIT, DISPSENDRESTORE,
NUMASENDFANCMD, NUMASENDVIRUSCMD,
REQUEST_NUMADATA
};
uint16_t FilterIDD[]={DISPCLEANOUT, DISPSENDTEMPLIMIT, DISPSENDDELAYLIMIT, DISPSENDRESTORE,
NUMASENDFANCMD, NUMASENDVIRUSCMD,
REQUEST_NUMADATA
};
uint16_t FilterIDE[]={DISPCLEANOUT, DISPSENDTEMPLIMIT, DISPSENDDELAYLIMIT, DISPSENDRESTORE,
NUMASENDFANCMD, NUMASENDVIRUSCMD,
REQUEST_NUMADATA
};
uint16_t FilterIDF[]={DISPCLEANOUT, DISPSENDTEMPLIMIT, DISPSENDDELAYLIMIT, DISPSENDRESTORE,
NUMASENDFANCMD, NUMASENDVIRUSCMD,
REQUEST_NUMADATA
};
/* CAN GPIOs 配置*/
/* 使能GPIO时钟 */
RCC_AHB1PeriphClockCmd(CAN_GPIO_TX_CLK|CAN_GPIO_RX_CLK, ENABLE);
/* 引脚映射为CAN功能 */
GPIO_PinAFConfig(CAN_GPIO_RX_PORT, CAN_RX_SOURCE, CAN_AF_PORT);
GPIO_PinAFConfig(CAN_GPIO_TX_PORT, CAN_TX_SOURCE, CAN_AF_PORT);
/* 配置 CAN RX 和 TX 引脚 */
GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(CAN_GPIO_RX_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CAN_TX_PIN;
GPIO_Init(CAN_GPIO_TX_PORT, &GPIO_InitStructure);
/* CAN配置*/
/* 使能CAN时钟 */
RCC_APB1PeriphClockCmd(CAN_CLK, ENABLE);
/* 复位CAN寄存器 */
CAN_DeInit(CANx);
/*
TTCM = time triggered communication mode
ABOM = automatic bus-off management
AWUM = automatic wake-up mode
NART = no automatic retransmission
RFLM = receive FIFO locked mode
TXFP = transmit FIFO priority
*/
CAN_InitStructure.CAN_TTCM = DISABLE; /* 禁止时间触发模式(不生成时间戳), T */
CAN_InitStructure.CAN_ABOM = DISABLE; /* 禁止自动总线关闭管理 */
CAN_InitStructure.CAN_AWUM = ENABLE; /* 禁止自动唤醒模式 */
CAN_InitStructure.CAN_NART = DISABLE; /* 禁止仲裁丢失或出错后的自动重传功能 */
CAN_InitStructure.CAN_RFLM = DISABLE; /* 禁止接收FIFO加锁模式 */
CAN_InitStructure.CAN_TXFP = DISABLE; /* 禁止传输FIFO优先级 */
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal; /* 设置CAN为正常工作模式 */
/*
CAN 波特率 = RCC_APB1Periph_CAN1 / Prescaler / (SJW + BS1 + BS2);
SJW = synchronisation_jump_width
BS = bit_segment
本例中,设置CAN波特率为0.5Mbsp
CAN 波特率 = 420000000 / 7 / (1 + 9 + 2) / = 0.5Mbsp,采样点为83.3%
另外尽可能的把采样点设置为 CiA 推荐的值:
75% when 波特率 > 800K
80% when 波特率 > 500K
87.5% when 波特率 <= 500K
采样点=(CAN_SJW+CAN_BS1)/(CAN_SJW+CAN_BS1+CAN_BS2)
*/
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_9tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler = 7;
CAN_Init(CANx, &CAN_InitStructure);
/* 设置CAN滤波器0 */
CAN_FilterInitStructure.CAN_FilterNumber = 2; /* 滤波器序号,0-13,共14个滤波器 */
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; /* 滤波器模式,设置ID掩码模式 */
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; /* 32位滤波 */
if(MACHINEDISP == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDDISP)/sizeof(FilterIDDISP[0]); i++)
{
temp = FilterIDDISP[i] ^ (~FilterIDDISP[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = (FilterIDDISP[0]<<5); /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
else if(MACHINENUMA == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDA)/sizeof(FilterIDA[0]); i++)
{
temp = FilterIDA[i] ^ (~FilterIDA[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = (FilterIDA[0]<<5); /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
else if(MACHINENUMB == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDB)/sizeof(FilterIDB[0]); i++)
{
temp = FilterIDB[i] ^ (~FilterIDB[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = (FilterIDB[0]<<5); /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
else if(MACHINENUMC == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDC)/sizeof(FilterIDC[0]); i++)
{
temp = FilterIDC[i] ^ (~FilterIDC[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = FilterIDC[0]<<5; /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
else if(MACHINENUMD == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDD)/sizeof(FilterIDD[0]); i++)
{
temp = FilterIDD[i] ^ (~FilterIDD[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = FilterIDD[0]<<5; /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
else if(MACHINENUME == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDE)/sizeof(FilterIDE[0]); i++)
{
temp = FilterIDE[i] ^ (~FilterIDE[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = FilterIDE[0]<<5; /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
else if(MACHINENUMF == MachineNum)
{
mask = 0x7FF;
for(uint32_t i =0; i < sizeof(FilterIDF)/sizeof(FilterIDF[0]); i++)
{
temp = FilterIDF[i] ^ (~FilterIDF[0]);
mask &= temp;
}
CAN_FilterInitStructure.CAN_FilterIdHigh = FilterIDF[0]<<5; /* 掩码后ID的高16bit */
CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask<<5); /* ID掩码值高16bit */
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
}
// CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; /* 掩码后ID的高16bit */
// CAN_FilterInitStructure.CAN_FilterIdLow = 0; /* 掩码后ID的低16bit */
// CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; /* ID掩码值高16bit */
// CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; /* 滤波器绑定FIFO 0 */
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; /* 使能滤波器 */
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 13; /* 滤波器序号,0-13,共14个滤波器 */
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO1; /* 滤波器绑定FIFO 0 */
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; /* 使能滤波器 */
CAN_FilterInit(&CAN_FilterInitStructure);
can_NVIC_Config(); /* 配置CAN中断 */
中断配置如下;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX1_IRQn;;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* CAN FIFO0 消息接收中断使能 */
CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CANx, CAN_IT_FMP1, ENABLE);
应该是终端电阻问题。
一周热门 更多>