-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSat_I2C.ino
More file actions
65 lines (55 loc) · 985 Bytes
/
Sat_I2C.ino
File metadata and controls
65 lines (55 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Wire.h>
//Timer offset between frames
long t;
//Frame data
byte data[14];
//Frame byte Index, default out of range to wait for header
int readIndex = 99;
//Ready indicator
bool ready = false;
void setup()
{
//RX Sat at 115.2K baud
Serial.begin(115200);
//Setup wire to listen to id 2
Wire.begin(2);
Wire.onRequest(requestEvent);
//Wait for first frame
t = millis();
}
void loop()
{
//Wait for tx data pair to be available
while(Serial.available())
{
long t2 = millis();
byte val = Serial.read();
//If more then 10 mSec since last byte it is the new frame
if(t2 - t > 10)
{
//reset index
readIndex = 0;
}
if(readIndex >= 2 && readIndex < 16) //safety check to avoid array overrun
{
//store value
data[readIndex - 2] = val;
if(readIndex == 15)
{
ready = true;
}
}
//Sync timer
t = t2;
//next index
readIndex++;
}
}
void requestEvent()
{
if(ready)
{
//Send all data
Wire.write(data, 14);
}
}