参考MAX31855板,用14位31:18给出了温度的符号值。这14位首先被送出MSB,第一位是符号位。
这些是示例值:
我想把值放在一个8插槽阵列的前两个插槽中,它将通过CAN和一个MCP2515模块发送出去。
实际上,我正在研究这段代码,这是MCP_CAN_lib:图书馆的发送示例
// CAN Send Example
//
#include <mcp_can.h>
#include <SPI.h>
MCP_CAN CAN0(10); // Set CS to pin 10
void setup()
{
Serial.begin(115200);
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
else Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
}
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
void loop()
{
// send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
if(sndStat == CAN_OK){
Serial.println("Message Sent Successfully!");
} else {
Serial.println("Error Sending Message...");
}
delay(100); // send data per 100ms
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/任何帮助,并建议最好的图书馆使用,将不胜感激!
发布于 2020-08-25 18:01:42
我不知道你所说的“已经转换成十进制格式”是什么意思,你为什么要这样做?
下面是如何从板中转换值并将其放入数组的前两个字节(fr您的1000 C示例):
unsigned char data[8] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
int temp = 0b0011'1110'1000'0000'0000'0000'0000'0000;
temp >>= 18;
data[1] = temp & 0xFF;
temp >>= 8;
data[0] = temp & 0xFF;https://stackoverflow.com/questions/63582440
复制相似问题