LIN_master  0.1
Arduino LIN master emulation with preemptive background operation
LIN_blocking.ino

Simple LIN master node emulation with blocking operation Simple emulation of a LIN master node via Serial3 (+ LIN transceiver) for DAI MRA2 FED1.0 with blocking operation. Status is printed periodically.

Author
Georg Icking-Konert
Date
2020-03-15
// include files
#include "LIN_master3.h" // muDuino LIN via Serial3
// pin to demonstrate background operation
#define PIN_TOGGLE 30
// pause between LIN frames
#define LIN_PAUSE 250
void setup(void)
{
// show background operation
pinMode(PIN_TOGGLE, OUTPUT);
// for user interaction via console
Serial.begin(115200); while(!Serial);
// initialize LIN master (blocking operation)
LIN_master3.begin(19200, LIN_V2, false);
} // setup()
void loop(void)
{
static uint32_t lastCall = LIN_PAUSE;
static uint8_t count = 0;
uint8_t Tx[2] = {0,0};
uint8_t Rx[8];
// toggle pin to show background operation
digitalWrite(PIN_TOGGLE, !digitalRead(PIN_TOGGLE));
// simple LIN scheduler
if (millis() - lastCall > LIN_PAUSE) {
lastCall = millis();
// send master request
if (count == 0) {
count++;
// dummy master request (blocking)
} // count == 0
// receive slave response
else {
count=0;
// receive slave response (blocking)
// print status and data
Serial.print(millis()); Serial.println("ms");
Serial.print("status: "); Serial.println(LIN_master3.flagRxComplete);
Serial.print("error: "); Serial.println(LIN_master3.error);
Serial.println("data:");
for (uint8_t i=0; i<8; i++)
{
Serial.print(" "); Serial.print(i); Serial.print("\t0x"); Serial.println(Rx[i], HEX);
}
Serial.println();
// clear pending error and flag for received data
} // count == 1
} // scheduler
} // loop()