c_cpp CAN总线模拟器(初始)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp CAN总线模拟器(初始)相关的知识,希望对你有一定的参考价值。

#include <mcp_can.h>
#include <SPI.h>

MCP_CAN CAN(10); // Set CS to pin 10

void setup()
{
	Serial.begin(115200);
  
START_INIT:
	if (CAN.begin(CAN_500KBPS) == CAN_OK) // init can bus : baudrate = 500k
	{
		Serial.println("CAN BUS Shield init ok!");
	}
	else
	{
		Serial.println("CAN BUS Shield init fail");
		Serial.println("Init CAN BUS Shield again");
		delay(100);
		goto START_INIT;
	}
}

void loop()
{
	// CAN.sendMsgBuf(INT8U id, INT8U ext, INT8U len, data_buf);
	// - id represents where the data comes 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.

	INT8U txMsg[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; // Message we're sending
	CAN.sendMsgBuf(0x00, 0, 8, txMsg);
	delay(100); // Send message every 100ms
}

以上是关于c_cpp CAN总线模拟器(初始)的主要内容,如果未能解决你的问题,请参考以下文章

CAN总线CAN代码相关问题和注释

STM32F429 没有收到 CAN 报文

详解CAN总线:高速CAN总线和低速CAN总线的特性

详解CAN总线:高速CAN总线和低速CAN总线的特性

请问can总线在汽车一般可以分为哪几类呢?

详解CAN总线:什么是CAN总线?