started development of Rs485 lib
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
35
SoftRS485.cpp
Normal file
35
SoftRS485.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
Library for Software Serial over RS485 connection
|
||||||
|
Created by Stepan Richter, November 2023
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "SoftRS485.h"
|
||||||
|
|
||||||
|
SoftRS485 SoftRS485::instance;
|
||||||
|
|
||||||
|
SoftRS485 SoftRS485::singleton(){
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftRS485::isr(){
|
||||||
|
instance.bam();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftRS485::begin(int RO, int nRE, int DE, int DI){
|
||||||
|
_RO = RO;
|
||||||
|
_RE = nRE;
|
||||||
|
_DE = DE;
|
||||||
|
_DI = DI;
|
||||||
|
Serial.begin(115200);
|
||||||
|
pinMode(_RE, OUTPUT);
|
||||||
|
pinMode(_DE, OUTPUT);
|
||||||
|
pinMode(_DI, OUTPUT);
|
||||||
|
pinMode(_RO, INPUT);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_RO),isr,CHANGE);
|
||||||
|
Serial.println("attached to interrupt!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftRS485::bam(){
|
||||||
|
Serial.println("bam!");
|
||||||
|
}
|
||||||
22
SoftRS485.h
Normal file
22
SoftRS485.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Library for Software Serial over RS485 connection
|
||||||
|
Created by Stepan Richter, November 2023
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SoftRS485_h
|
||||||
|
#define SoftRS485_h
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
class SoftRS485{
|
||||||
|
public:
|
||||||
|
void begin(int RO, int nRE, int DE, int DI);
|
||||||
|
void bam();
|
||||||
|
static SoftRS485 singleton();
|
||||||
|
private:
|
||||||
|
static void isr();
|
||||||
|
static SoftRS485 instance;
|
||||||
|
int _RO, _RE, _DE, _DI;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user