-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
69 lines (55 loc) · 1.01 KB
/
test.c
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
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "twi.h"
int main(void)
{
twi_init(); // Initalize the TWI.
sei(); // Enable interrupts.
uint8_t sla = 0x58; // slave address
uint8_t tx[128];
uint8_t rx[128];
tx[0] = 0x30;
tx[1] = 0x01;
twi_write(sla, &tx[0], 2);
_delay_ms(100);
tx[0] = 0x00;
tx[1] = 0x00;
tx[2] = 0x00;
tx[3] = 0x00;
tx[4] = 0x00;
tx[5] = 0x00;
tx[6] = 0x00;
tx[7] = 0x90;
twi_write(sla, &tx[0], 8);
_delay_ms(100);
tx[0] = 0x07;
tx[1] = 0x00;
tx[2] = 0x41;
twi_write(sla, &tx[0], 3);
_delay_ms(100);
tx[0] = 0x1A;
tx[1] = 0x40;
tx[2] = 0x00;
twi_write(sla, &tx[0], 3);
_delay_ms(100);
tx[0] = 0x33;
tx[1] = 0x03;
twi_write(sla, &tx[0], 2);
_delay_ms(100);
tx[0] = 0x30;
tx[1] = 0x08;
twi_write(sla, &tx[0], 2);
_delay_ms(100);
while(1)
{
tx[0] = 0x37;
twi_write(sla, &tx[0], 1);
_delay_us(25);
twi_read(sla, &rx[0], 8);
_delay_us(380);
twi_read(sla, &rx[0], 4);
_delay_us(380);
}
return 0;
}