forked from td0g/ArduinoHVP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_write.ino
More file actions
32 lines (30 loc) · 837 Bytes
/
_write.ino
File metadata and controls
32 lines (30 loc) · 837 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
//Basic HV Serial Communication with ATTINY
byte writeHV(byte sdiByte, byte siiByte){
byte in = 0;
while (!digitalRead(SDO)){};
digitalWrite(SDI, 0);
digitalWrite(SII, 0);
in = pulseClock();
for (byte i = 0; i < 8; i++){
digitalWrite(SDI, ((sdiByte >> (7-i)) & 1));
digitalWrite(SII, ((siiByte >> (7-i)) & 1));
if (i < 7){
in = in << 1;
in |= pulseClock();
}
else pulseClock();
}
digitalWrite(SDI, 0);
digitalWrite(SII, 0);
pulseClock();
pulseClock();
return in;
}
bool pulseClock(){
delayMicroseconds(8); //This only needs to be <1 microsecond, but let's just play things safe :)
digitalWrite(HVSP_SCL, 1);
delayMicroseconds(8); //Same...
byte in = digitalRead(SDO); //Reading back from target
digitalWrite(HVSP_SCL, 0);
return in;
}