-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCanzasi_I2Cblink.ino
62 lines (52 loc) · 1.45 KB
/
Canzasi_I2Cblink.ino
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
// Canzasi_I2Cblink
// A simple I2C slave receiver
// LED blinking of synchronous when slave received
// "write" data from master.
// with https://github.com/SpenceKonde/ATTinyCore
//
// License CC by 4.0 2016 D.F.Mac.
//
// +----+
// VCC| |GND
// LED PB0/A11/ D0| |D10/A0 /PA0
// ERRLED PB1/A10/ D1| |D9 /A1 /PA1
// PB3/ A9/D11| |D8 /A2 /PA2
// PB2/ A8/ D2| |D7 /A3 /PA3
// PA7/ A7/ D3| |D6 /A4 /PA4 SCL
// SDA PA6/ A6/ D4| |D5 /A5 /PA5
// +----+
//
#include "i2c841s2.h"
#define LED_PIN 0 // PB0
#define ERRLED_PIN 1 // PB1
uint8_t errorFlg = false;
void onI2CWrite(volatile uint8_t *pbuf, uint8_t size){
// The i2cs's default rx buffer is used in this sample.
// buffer length is 1 byte.
if(size == 1){ // Correct packet length
if(*pbuf == 1){
digitalWrite(LED_PIN,HIGH);
}else{
digitalWrite(LED_PIN,LOW);
}
}else{ // Incorrect packet length
errorFlg = true;
}
}
void setup() {
pinMode(LED_PIN,OUTPUT);
pinMode(ERRLED_PIN,OUTPUT);
i2cs.setOnWriteEnd(onI2CWrite);
// default rx buffer length (per packet size) is 1 byte
// if slave device specified another size, use i2cs.setRxBuffer()
// start i2c slave interrupt
i2cs.init(0x30);
}
void loop() {
if(errorFlg){
digitalWrite(ERRLED_PIN,HIGH);
delay(100);
digitalWrite(ERRLED_PIN,LOW);
delay(100);
}
}