上海航芯 ACM32F070开发板+触控功能评估板评测 - 第五篇 CAN通信
[复制链接]
本评测实验是使用ACM32F070进行CAN通信。实验中采用了广成科技的USBCAN工具盒和上位机GCAN作为一个上位机CAN节点。下面是实验硬件连接图。
官方SDK中提供了CAN的例程,本实验使用这个例程进行CAN通信测试。CAN模块主要配置如下:
- 通信速率:500Kbps
- 标准帧ID:0x100
- 扩展帧ID:0x18fe0000
主要配置函数如下:
static void CAN_Mode_Config(void)
{
CAN_Handle.Instance=CANx;
CAN_Handle.Init.CAN_Mode = CAN_Mode_Normal; //CAN_Mode_Normal
CAN_Handle.Init.CAN_SJW=CAN_SJW_1tq; //CAN_SJW_1tq
CAN_Handle.Init.CAN_BRP=7; // //pclk =64M BRP=2*(7+1)=16 TQ=16*(1/64M)=1/4M
CAN_Handle.Init.CAN_TSEG1=CAN_TSEG1_3tq;
CAN_Handle.Init.CAN_TSEG2=CAN_TSEG2_4tq; //width=1+3+4=8 TQ baud=1M/(1/4*8)=1M/2=500K
CAN_Handle.Init.CAN_BOR=CAN_BOR_ENABLE; //ENABLE Bus off recover
CAN_Handle.CAN_ReceiveIT_Callback=CAN_ReceiveIT_Callback;
HAL_CAN_Init(&CAN_Handle);
}
static void CAN_Filter_Config()
{
CAN_FilterInitTypeDef CAN_FilterInitStruct;
CAN_FilterInitStruct.CAN_FilterMode=CAN_FilterMode_Dual;
CAN_FilterInitStruct.CAN_FilterId1=0x18fe0000; //Extended Id:ID28...ID0
CAN_FilterInitStruct.CAN_FilterId2=0x100<<18; //Standard Id:ID28...ID18,so need (ID<<18)
/* if want receive all data,please set the CAN_FilterMaskId = 0xFFFFFFFF*/
CAN_FilterInitStruct.CAN_FilterMaskId1=0x0000FFFF; //only receive CAN id=0x18fexxxx(only care 0x18fexxxx)
CAN_FilterInitStruct.CAN_FilterMaskId2=0x001FFFFF; //only receive CAN id=0x100 ( care ID28...ID18)
HAL_CAN_ConfigFilter(&CAN_Handle, &CAN_FilterInitStruct);
}
标准帧测试:上位机节点发送不同数据长度数据,ACM32F070收到后,将数据再发送回来。下面是测试结果截图。
扩展帧测试采样同样的方式,上位机节点发送不同数据长度数据,ACM32F070收到后,将数据再发送回来。
|