单步调试中,寄存器TSR和ESR值如下:
0: TSR: 0x1C00 0009 //发送请求已执行,但邮箱0发送失败
ESR: 0x0008 0030 //传输错误,错误计数器+8,错误类型:011 == 确认(ACK)错误
1: TSR: 0x1C00 0909 //发送请求已执行,但邮箱1、邮箱0发送失败
ESR: 0x0010 0040 //传输错误,错误计数器+8,错误类型:100 == 位隐性错误
2: TSR: 0x1C00 0909 //发送请求已执行,但邮箱1、邮箱0发送失败
ESR: 0x0018 0040 //传输错误,错误计数器+8,错误类型: 100 == 位隐性错误
3: TSR: 0x1C00 0909
ESR: 0x0020 0040
.
.
.
10:TSR: 0x1C00 0903 //成功发送的一帧
ESR: 0x004F 0000
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
u8 CAN1_Mode_Init(u8 tsjw,u8 tbs2,u8 tbs1,u16 brp,u8 mode)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
#if CAN1_RX0_INT_ENABLE
NVIC_InitTypeDef NVIC_InitStructure;
#endif
//使能相关时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能PORTA时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);//使能CAN1时钟
//初始化GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11| GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用功能
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA11,PA12
//引脚复用映射配置
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_CAN1); //GPIOA11复用为CAN1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_CAN1); //GPIOA12复用为CAN1
//CAN单元设置
CAN_InitStructure.CAN_TTCM = DISABLE; //非时间触发通信模式
CAN_InitStructure.CAN_ABOM = DISABLE; //软件自动离线管理
CAN_InitStructure.CAN_AWUM = DISABLE; //睡眠模式通过软件唤醒(清除CAN->MCR的SLEEP位)
CAN_InitStructure.CAN_NART = ENABLE; //禁止报文自动传送 marvin 1: ENABLE->DISABLE
CAN_InitStructure.CAN_RFLM = DISABLE; //报文不锁定,新的覆盖旧的
CAN_InitStructure.CAN_TXFP = DISABLE; //优先级由报文标识符决定
CAN_InitStructure.CAN_Mode = mode; //模式设置
CAN_InitStructure.CAN_SJW = tsjw; //重新同步跳跃宽度(Tsjw)为tsjw+1个时间单位 CAN_SJW_1tq~CAN_SJW_4tq
CAN_InitStructure.CAN_BS1 = tbs1; //Tbs1范围CAN_BS1_1tq ~CAN_BS1_16tq
CAN_InitStructure.CAN_BS2 = tbs2; //Tbs2范围CAN_BS2_1tq ~ CAN_BS2_8tq
CAN_InitStructure.CAN_Prescaler = brp; //分频系数(Fdiv)为brp+1
CAN_Init(CAN1, &CAN_InitStructure); // 初始化CAN1
//配置过滤器
CAN_FilterInitStructure.CAN_FilterNumber = 0; //过滤器0
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; //32位
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; ////32位ID
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; //32位MASK
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;//过滤器0关联到FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; //激活过滤器0
CAN_FilterInit(&CAN_FilterInitStructure); //滤波器初始化
return 0;
}
/************************* PLL Parameters *************************************/
/* Select the PLL clock source */
//#define PLL_SOURCE_HSI // HSI (~16 MHz) used to clock the PLL, and the PLL is used as system clock source
#define PLL_SOURCE_HSE // HSE used to clock the PLL, and the PLL is used as system clock source
//#define PLL_SOURCE_HSE_BYPASS // HSE bypassed with an external clock (8MHz, coming from ST-Link) used to clock
// the PLL, and the PLL is used as system clock source
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
#if defined (PLL_SOURCE_HSI)
#define PLL_M 16
#else
#define PLL_M 16 //marvin 1: 8->16
#endif
#define PLL_N 168 //marvin 2: 360->168
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 2
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
#define PLL_Q 48 //marvin 4: 7->48
1 常温下是正常的吗?
2 CAN收发器后外接了CAN测试工具或其他CAN节点了吗?
3 测试时波特率是1M? 可以降速为500K测试下?
4 LookBack模式下肯定是正常的。这只是说明这个问题与CAN控制器外部连接的部分有关。
1. 常温下正常;(高温也没问题,低温-30°没有问题,过了-30开始出错);
2. CAN收发器外接了CAN调试盒子(型号是:广州致远电子的 USBCAN-II);
3. 测试时波特率是500kbps;
4. 嗯,我当时也是猜想可能是控制器外面的电路的问题,所以做了回环测试。
PS: 谢谢您的回复
建议用示波器查看CAN_TX脚的波形与CAN总线上的波形。对比常温正常下与低温异常时有什么差异?
期望分享结果。
一周热门 更多>