From e9149a181d8b95a69b767f5c4f2d451a7f9d3d33 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Tue, 21 Nov 2023 16:25:15 +0100 Subject: [PATCH] increased pulse length (caused problems before), added macros for Controllino MAXI Signed-off-by: Stephan Richter --- SoftRS485.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/SoftRS485.cpp b/SoftRS485.cpp index d512761..1f7ed4f 100644 --- a/SoftRS485.cpp +++ b/SoftRS485.cpp @@ -12,7 +12,7 @@ // Pins int _RO, _RE, _DE, _DI; -const long _pulse_len = 616; +const long _pulse_len = 1000; const long _break = _pulse_len * 20; boolean _line = LOW; // current state of the transmission line long _last_flip = 0; // timestamp since last flip of line state @@ -29,7 +29,12 @@ long _diff = 0; // time difference between last flips long _now = 0; // current time long _count = 0; // helper for bit iteration + +#if defined CONTROLLINO_MAXI +ISR(PCINT1_vect){ +#else void interrupt485(){ +#endif _line = !digitalRead(_RO); // HIGH level = logical zero and vice versa _now = micros(); // get current time _diff = _now - _last_flip; // duration of the _previous_ bit @@ -85,7 +90,6 @@ void interrupt485(){ - void init485(int RO, int nRE, int DE, int DI){ _RO=RO; // save the pin numbers _RE=nRE; @@ -123,7 +127,18 @@ void init485(int RO, int nRE, int DE, int DI){ pinMode(_DI,OUTPUT); digitalWrite(_DI,LOW); // output line = LOW - attachInterrupt(digitalPinToInterrupt(_RO),interrupt485,CHANGE); + #if defined CONTROLLINO_MAXI + Serial.println("Setting up for Controllino MAXI!"); + // https://forum.arduino.cc/t/enable-interrupt/259014/2 + // pin change interrupt enable (PCIE) port 1 + // in pin change interrupt control register (PCICR) + PCICR |= (1<