LIN_master  0.1
Arduino LIN master emulation with preemptive background operation
LIN_blocking.ino
Go to the documentation of this file.
1 
10 // include files
11 #include "LIN_master3.h" // muDuino LIN via Serial3
12 
13 // pin to demonstrate background operation
14 #define PIN_TOGGLE 30
15 
16 // pause between LIN frames
17 #define LIN_PAUSE 250
18 
19 
20 void setup(void)
21 {
22  // show background operation
23  pinMode(PIN_TOGGLE, OUTPUT);
24 
25  // for user interaction via console
26  Serial.begin(115200); while(!Serial);
27 
28  // initialize LIN master (blocking operation)
29  LIN_master3.begin(19200, LIN_V2, false);
30 
31 } // setup()
32 
33 
34 
35 void loop(void)
36 {
37  static uint32_t lastCall = LIN_PAUSE;
38  static uint8_t count = 0;
39  uint8_t Tx[2] = {0,0};
40  uint8_t Rx[8];
41 
42  // toggle pin to show background operation
43  digitalWrite(PIN_TOGGLE, !digitalRead(PIN_TOGGLE));
44 
45  // simple LIN scheduler
46  if (millis() - lastCall > LIN_PAUSE) {
47  lastCall = millis();
48 
49  // send master request
50  if (count == 0) {
51  count++;
52 
53  // dummy master request (blocking)
54  LIN_master3.sendMasterRequest(0x3B, 2, Tx);
55 
56  } // count == 0
57 
58  // receive slave response
59  else {
60  count=0;
61 
62  // receive slave response (blocking)
63  LIN_master3.receiveSlaveResponse(0x1B, 8, Rx);
64 
65  // print status and data
66  Serial.print(millis()); Serial.println("ms");
67  Serial.print("status: "); Serial.println(LIN_master3.flagRxComplete);
68  Serial.print("error: "); Serial.println(LIN_master3.error);
69  Serial.println("data:");
70  for (uint8_t i=0; i<8; i++)
71  {
72  Serial.print(" "); Serial.print(i); Serial.print("\t0x"); Serial.println(Rx[i], HEX);
73  }
74  Serial.println();
75 
76  // clear pending error and flag for received data
79 
80  } // count == 1
81 
82  } // scheduler
83 
84 } // loop()
bool flagRxComplete
flag to indicate that data reception is complete. Must be cleared manually
Definition: LIN_master.h:142
void begin(uint16_t Baudrate, LIN_version_t Version, bool Background)
setup UART and LIN framework
Definition: LIN_master.cpp:24
LIN master emulation library for Serial3.
LIN_error_t receiveSlaveResponse(uint8_t id, uint8_t numData, void(*Rx_handler)(uint8_t, uint8_t *))
receive a slave response frame with callback function
Definition: LIN_master.cpp:253
no error
Definition: LIN_master.h:68
LIN_error_t error
error state. Is latched until cleared
Definition: LIN_master.h:143
LIN protocol version 2.
Definition: LIN_master.h:51
LIN_error_t sendMasterRequest(uint8_t id, uint8_t numData, uint8_t *data)
send a master request frame
Definition: LIN_master.cpp:146
LIN_Master_3 LIN_master3
instance of LIN master via Serial3
Definition: LIN_master3.cpp:17