本帖最后由 oxygenzz 于 2019-4-12 10:31 编辑
实验内容:正确接收主机通过CAN总线发来的远程帧,并自动发送应答数据,此过程无需CPU/固件干预。
设计举例
目标芯片:PIC18F25K83 (带有CAN控制器)
硬件平台:HPC Curiosity Board , MCP2542 Click (CAN收发器板)
使用MCC对芯片进行配置
时钟配置
管脚配置
CAN外设配置
MCC生成代码
检查生成的代码。
在ecan.c中,
void ECAN_Initialize(void)
{
…
/**
Configure Generic Buffers to be Transmit or Receive
*/
BSEL0 = 0x04;
B0CON = 0x04;
B0D0 = 0x00;
B0D1 = 0x01;
B0D2 = 0x02;
B0D3 = 0x03;
B0D4 = 0x04;
B0D5 = 0x05;
B0D6 = 0x06;
B0D7 = 0x07;
B0DLC = 0x08;
B0SIDH = 0x24;
B0SIDL = 0x60;
…
/**
Enable Filters
*/
RXFCON0 = 0x01;
RXFCON1 = 0x00;
…
/**
Assign Filters to Buffers
*/
RXFBCON0 = 0x02;
…
/**
Initialize Receive Filters
*/
RXF0EIDH = 0x00;
RXF0EIDL = 0x00;
RXF0SIDH = 0x24;
RXF0SIDL = 0x60;
RXF1EIDH = 0x00;
RXF1EIDL = 0x00;
RXF1SIDH = 0x00;
RXF1SIDL = 0x00;
…
}
测试结果
下载程序后,运行。
PC上CAN测试软件,发送一帧远程帧后,接收到K83自动发送的8字节数据。
|