Browse Source

fixed comment in Sender.ino

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
nano-5
Stephan Richter 11 months ago
parent
commit
e04a2bc202
  1. 129
      Sender/Sender.ino
  2. 9
      Software/Sender/Sender.ino

129
Sender/Sender.ino

@ -1,129 +0,0 @@
// Breadboard
//int enable = 2;
//int sTx = 4;
//int sRx = 5;
// RS485-Nano Revision 1.0
int enable = 9;
int sTx = 8;
int sRx = 3;
// Für Controllino könnte man benutzen: sRx = 20, sTx = 21, enable = 53
int in1 = 4; // o
int in2 = 5; // |o
int in3 = 6; // ||o
int in4 = 7; // |||o
// ↓↓↓↓
int irq = 2;// ←++++
long base = 1000;
int id = 0;
int baud = 115200;
char c;
int counter = 0;
bool reg1=false,reg2=false,reg3=false,reg4=false;
void setup(){
Serial.begin(baud);
pinMode(A0,INPUT);
id = analogRead(A0);
pinMode(enable,OUTPUT);
digitalWrite(enable,LOW);
pinMode(sTx,OUTPUT);
digitalWrite(sTx,LOW);
pinMode(in1,INPUT);
pinMode(in2,INPUT);
pinMode(in3,INPUT);
pinMode(in4,INPUT);
pinMode(irq,INPUT);
attachInterrupt(digitalPinToInterrupt(irq),interrupt,RISING);
pinMode(sRx,INPUT);
Serial.print("Baud rate set to ");
Serial.println(baud);
Serial.print("Initialized Arduino #");
Serial.println(id);
}
void interrupt(){
Serial.println("Interrupt");
reg1 = digitalRead(in1);
reg2 = digitalRead(in2);
reg3 = digitalRead(in3);
reg4 = digitalRead(in4);
}
bool sendBit(bool bt){
digitalWrite(sTx,bt);
delayMicroseconds(80);
if (digitalRead(sTx) != bt) return false;
delayMicroseconds(base-80);
return true;
}
bool sendChar(char c){
return sendBit(c & 0x01)
&& sendBit(c & 0x02)
&& sendBit(c & 0x04)
&& sendBit(c & 0x08)
&& sendBit(c & 0x10)
&& sendBit(c & 0x20)
&& sendBit(c & 0x40)
&& sendBit(c & 0x80);
}
bool sendString(String s){
Serial.print("Sending '"+s+"'…");
boolean busy = false;
for (int i = 0; i<11; i++){
if (!digitalRead(sRx)) {
if (!busy){
Serial.print("busy…");
busy = true;
}
i = 0; // wait for free line
}
delayMicroseconds(base);
}
digitalWrite(enable,HIGH);
bool success = sendBit(0); // erste Flanke erzeugen
if (success) {
for (char c : s){
if (!sendChar(c)){
success = false;
break;
}
}
}
success = success && sendChar(13);
success = success && sendBit(1); // letzte Flanke erzeugen
digitalWrite(enable,LOW);
Serial.println(success ? "success" : "failed");
return success;
}
void loop(){
if (reg1){
reg1 = false;
sendString("t:02:01");
}
if (reg2){
reg2 = false;
sendString("t:02:02");
}
if (reg3){
reg3 = false;
sendString("t:02:03");
}
if (reg4){
reg4 = false;
sendString("t:02:04");
}
}

9
Software/Sender/Sender.ino

@ -1,8 +1,9 @@
/* /*
* Demonstrates how to use LCDisplay in conjunction with SoftRS485: * Demonstrates how to use Read Buttons in conjunction with SoftRS485:
* *
* The main _loop_ of this program listens on the RS485 bus. * If a button is pressed, a corresponding flag is set.
* Whenever a message is received from the bus, it is displayed on the LCD. * The main loop checks for the state of those flags and
* sends a message on the RS485 bus whenever a flag is set.
*/ */
// include the library code: // include the library code:
@ -31,7 +32,7 @@ unsigned long times[8];
void setup() { void setup(){
Serial.begin(115200); Serial.begin(115200);
init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization: init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization:
pinMode(BTN_INT,INPUT_PULLUP); pinMode(BTN_INT,INPUT_PULLUP);

Loading…
Cancel
Save