-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlphieCard.ino
127 lines (105 loc) · 2.19 KB
/
AlphieCard.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Simple sketch to read out BMA020 using SoftI2C
#define SDA_PORT PORTD
#define SDA_PIN 0
#define SCL_PORT PORTD
#define SCL_PIN 1
#define I2C_SLOWMODE 1
#include <SoftI2CMaster.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <TKLCD.h>
TKLCD_Local lcd = TKLCD_Local();
void upload_configuration() {
i2c_start(0x22);
i2c_write(0xA0);
i2c_write(0x2F);
i2c_write(0x3B);
i2c_write(0x38);
i2c_write(0x37);
i2c_write(0x2D);
i2c_write(0x32);
i2c_write(0x3A);
i2c_write(0x32);
i2c_write(0x3F);
i2c_write(0x34);
i2c_stop();
i2c_start(0x22);
i2c_write(0xA1);
i2c_write(0x4D);
i2c_write(0x48);
i2c_write(0x47);
i2c_write(0x48);
i2c_write(0x4D);
i2c_write(0x4B);
i2c_write(0x48);
i2c_write(0x4B);
i2c_write(0x4F);
i2c_write(0x4C);
i2c_stop();
i2c_start(0x22);
i2c_write(0xA2);
i2c_write(0x8B);
i2c_write(0x88);
i2c_write(0x88);
i2c_write(0x88);
i2c_write(0x8B);
i2c_write(0x8A);
i2c_write(0x88);
i2c_write(0x8A);
i2c_write(0x8C);
i2c_write(0x8A);
i2c_stop();
}
void setup(void) {
Serial.begin(115200);
lcd.begin();
i2c_init();
// First Read goodness
i2c_start(0x23);
i2c_write(0xE0);
lcd.clear();
lcd.print(i2c_read(true), HEX); // Should be 0x4A
i2c_stop();
delay(500); // So I can read the above
lcd.clear();
lcd.println(F("Uploading configuration"));
upload_configuration();
i2c_start(0x23);
lcd.print(i2c_read(false), HEX); // F1
lcd.print(i2c_read(false), HEX); // Checksum for config data
lcd.print(i2c_read(true), HEX); // 00
i2c_stop();
delay(500);
}
void loop(void){
int card1 = 0;
int card2 = 0;
i2c_start(0x22);
i2c_write(0x30);
i2c_stop();
// From the logic dump
delay(70);
lcd.clear();
i2c_start(0x23);
i2c_write(0x20);
card1 = i2c_read(false);
card2 = i2c_read(true);
i2c_stop();
card1 = card2 << 8 | card1;
switch (card1) {
case -1:
lcd.print(F("Unable to read"));
break;
case -6:
lcd.print(F("No card"));
break;
case -16:
lcd.print(F("Insert / Eject"));
break;
default:
lcd.print(F("ID: "));
lcd.print(card1);
}
// From logic dump
delay(100);
}