Browse Source

increased pulse length (caused problems before), added macros for Controllino MAXI

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 12 months ago
parent
commit
e9149a181d
  1. 21
      SoftRS485.cpp

21
SoftRS485.cpp

@ -12,7 +12,7 @@
// Pins // Pins
int _RO, _RE, _DE, _DI; int _RO, _RE, _DE, _DI;
const long _pulse_len = 616; const long _pulse_len = 1000;
const long _break = _pulse_len * 20; const long _break = _pulse_len * 20;
boolean _line = LOW; // current state of the transmission line boolean _line = LOW; // current state of the transmission line
long _last_flip = 0; // timestamp since last flip of line state 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 _now = 0; // current time
long _count = 0; // helper for bit iteration long _count = 0; // helper for bit iteration
#if defined CONTROLLINO_MAXI
ISR(PCINT1_vect){
#else
void interrupt485(){ void interrupt485(){
#endif
_line = !digitalRead(_RO); // HIGH level = logical zero and vice versa _line = !digitalRead(_RO); // HIGH level = logical zero and vice versa
_now = micros(); // get current time _now = micros(); // get current time
_diff = _now - _last_flip; // duration of the _previous_ bit _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){ void init485(int RO, int nRE, int DE, int DI){
_RO=RO; // save the pin numbers _RO=RO; // save the pin numbers
_RE=nRE; _RE=nRE;
@ -123,7 +127,18 @@ void init485(int RO, int nRE, int DE, int DI){
pinMode(_DI,OUTPUT); pinMode(_DI,OUTPUT);
digitalWrite(_DI,LOW); // output line = LOW 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<<PCIE1);
// enable bit for pin change interrupt 9 (PCINT9)
// in pin change mask 1
PCMSK1 |= (1<<PCINT9);
#else
attachInterrupt(digitalPinToInterrupt(_RO),interrupt485,CHANGE);
#endif
_last_flip = micros(); _last_flip = micros();
} }

Loading…
Cancel
Save