10#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || \
11 defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RENESAS)
28 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
38 this->SWSerial.flush();
39 while (this->SWSerial.available())
40 this->SWSerial.read();
43 #if !defined(ARDUINO_ARCH_RENESAS)
44 this->SWSerial.stopListening();
52 digitalWrite(this->pinTx, this->inverseLogic ? HIGH : LOW);
55 this->startBreak = micros();
81 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
91 if ((micros() - this->startBreak) > this->durationBreak)
94 digitalWrite(this->pinTx, this->inverseLogic ? LOW : HIGH);
97 delayMicroseconds(50);
100 #if defined(ARDUINO_ARCH_STM32)
101 this->SWSerial.listen();
105 this->SWSerial.write(this->
bufTx+1, this->
lenTx-1);
113 #if !defined(ARDUINO_ARCH_RENESAS) && !defined(ARDUINO_ARCH_STM32)
114 this->SWSerial.listen();
143 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
153#if defined(ARDUINO_ARCH_RENESAS)
156 if (this->SWSerial.available() >= this->lenRx)
159 this->SWSerial.readBytes(this->
bufRx, this->
lenRx);
162#elif defined(ARDUINO_ARCH_STM32)
165 if (this->SWSerial.available() >= this->lenRx-1)
168 this->SWSerial.readBytes(this->
bufRx+1, this->
lenRx-1);
177 if (this->SWSerial.available() >= this->lenRx - this->lenTx) {
202 DEBUG_PRINT(1,
"Rx timeout");
232#if defined(ARDUINO_ARCH_RENESAS)
245 this->inverseLogic = InverseLogic;
266 this->SWSerial.end();
267 #if defined(ARDUINO_ARCH_RENESAS)
268 this->SWSerial.begin(this->
baudrate, SERIAL_8N1, this->inverseLogic);
270 this->SWSerial.begin(this->
baudrate);
277 DEBUG_PRINT(2,
"ok");
293 this->SWSerial.end();
LIN master emulation library for SoftwareSerial.
uint8_t lenRx
receive buffer length (max. 12)
virtual void begin(uint16_t Baudrate=19200)
Open serial interface.
uint16_t baudrate
communication baudrate [Baud]
uint8_t bufTx[12]
send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
LIN_Master_Base::error_t _checkFrame(void)
Check received LIN frame.
LIN_Master_Base::error_t error
error state. Is latched until cleared
void _enableTransmitter(void)
Enable RS485 transmitter (DE=high)
uint32_t timeStart
starting time [us] for frame timeout
uint8_t lenTx
send buffer length (max. 12)
LIN_Master_Base::state_t state
status of LIN state machine
void _disableTransmitter(void)
Disable RS485 transmitter (DE=low)
error_t
LIN error codes. Use bitmasks, as error is latched. Use same as LIN_slave_portable.
@ ERROR_STATE
error in LIN state machine
@ ERROR_TIMEOUT
frame timeout error
uint32_t timePerByte
time [us] per byte at specified baudrate
state_t
state of LIN master state machine. Use bitmasks for fast checking multiple states
@ STATE_BODY
rest of frame is being sent/received
@ STATE_BREAK
sync break is being transmitted
@ STATE_IDLE
no LIN transmission ongoing
@ STATE_DONE
frame completed
virtual void end(void)
Close serial interface.
uint8_t bufRx[12]
receive buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
LIN_Master_Base(const char NameLIN[]="Master", const int8_t PinTxEN=INT8_MIN)
LIN master node constructor.
uint32_t timeoutFrame
max. frame duration [us]
LIN_master_SoftwareSerial(uint8_t PinRx, uint8_t PinTx, bool InverseLogic=false, const char NameLIN[]="Master", const int8_t PinTxEN=INT8_MIN)
Class constructor.
LIN_Master_Base::state_t _sendBreak(void)
Send LIN break.
LIN_Master_Base::state_t _sendFrame(void)
Send LIN bytes (request frame: SYNC+ID+DATA[]+CHK; response frame: SYNC+ID)
void end(void)
Close serial interface.
LIN_Master_Base::state_t _receiveFrame(void)
Read and check LIN frame.
void begin(uint16_t Baudrate=19200)
Open serial interface.