Arduino CAN

相关链接
http://wiki.seeed.cc/CAN-BUS_Shield_V1.2/

APIs
Mask:

init_Mask(unsigned char num, unsigned char ext, unsigned char ulData);
Filter:

init_Filt(unsigned char num, unsigned char ext, unsigned char ulData);

num : represents which register to use. You can fill 0 or 1 for mask and 0 to 5 for filter.
ext : represents the status of the frame. 0 means it’s a mask or filter for a standard frame. 1 means it’s for a extended frame.
ulData : represents the content of the mask of filter.

  1. Check Receive
    The MCP2515 can operate in either a polled mode, where the software checks for a received frame, or using additional pins to signal that a frame has been received or transmit completed.

Use the following function to poll for received frames.

INT8U MCP_CAN::checkReceive(void);
The function will return 1 if a frame arrives, and 0 if nothing arrives.

  1. Get CAN ID
    When some data arrive, you can use the following function to get the CAN ID of the “send” node.

INT32U MCP_CAN::getCanId(void)
5. Send Data
CAN.sendMsgBuf(INT8U id, INT8U ext, INT8U len, data_buf);
It is a function to send data onto the bus. In which:

id represents where the data come from.
ext represents the status of the frame. ‘0’ means standard frame. ‘1’ means extended frame.
len represents the length of this frame.
data_buf is the content of this message.
For example, In the ‘send’ example, we have:

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
CAN.sendMsgBuf(0x00, 0, 8, stmp); //send out the message ‘stmp’ to the bus and tell other devices this is a standard frame from 0x00.
6. Receive Data
The following function is used to receive data on the ‘receive’ node:

CAN.readMsgBuf(unsigned char len, unsigned char buf);
In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.

len represents the data length.
buf is where you store the data.
Generate a New BaudRate
We had provided many frequently-used baud rate, as below:

Yet you may still can’t find the rate you want. Here we provide a software to help you to calculate the baud rate you need.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值