Arduino 通讯总线方案 PJON
PJON (Padded Jittering Operative Network) 是一个简单的连线、多 master 通讯总线系统。是 i2c 、1-Wire、串口以及其他 Arduino 兼容协议的替代方案。特性单个物理层连接,可支持高达 50 个节点实现了设备编码来支持高达 254 个设备通讯
循环冗余校验 (CRC).确保数据包发送的正确多 master 支持中的避免冲突提供广播功能包管理机制来跟踪和重新发送失败的数据包发送错误处理性能传输速率: 32256 baud/s or 4.32kB/s带宽: 2.7kB/s精确度: 99.95%兼容性Arduino Diecimila / DuemilanoveArduino MiniArduino UnoArduino NanoArduino Mega
示例代码:
#include<PJON.h>//Transmitterboardcode PJONnetwork(12,45);//Busconnectiontopin12,deviceid45voidsetup(){
network.send(44,"B",1,1000000);
//Sendtodevice44,"B"contentof1bytelengthevery1000000microseconds(1second)
}voidloop(){
network.update();
}/----------------------------------------------------------------------------/
#include<PJON.h>//Receiverboardcode
PJONnetwork(12,44);//Busconnectiontopin12,deviceid45voidsetup(){
network.set_receiver(receiver_function);//Setthefunctionusedtoreceivemessages
};staticvoidreceiver_function(uint8_tlength,uint8_t*payload){
if(payload[]=='B'){//IfthefirstletterofthereceivedmessageisB
digitalWrite(13,HIGH);
delay(30);
digitalWrite(13,LOW);
}
}voidloop(){
network.receive(1000);
}