Report abuse

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
#include <Wire.h>

#define BAUD_RATE 19200
#define statusLED 12

// Addr. |Mode (162 + Read)
#define RTCAddressW 0xA2
#define RTCAddressR 0xA3

    volatile int blinkStatus = LOW;

void setup(void)
{
// initialize inputs/outputs

// start serial
    Serial.begin(BAUD_RATE);

    Wire.begin();

    Wire.beginTransmission(RTCAddressW);
    Wire.send(0);
    Wire.endTransmission();

// Registers

    Wire.beginTransmission(RTCAddressW);
    Wire.send(B00000000); // 00H    Test mode
    Wire.send(B00000000); // 01H    Alarm mode
    Wire.send(B00000001); // 02H    Seconds
    Wire.send(30);      // 03H  Minutes:p
    Wire.send(19);      // 04H  Hours
    Wire.send(11);      // 05H  Date
    Wire.send(2);           // 06H  Day of the week
    Wire.send(B00000000); // 07H    Century bit 19XX = 1 | 20XX = 0
    Wire.send(7);           // 08H  year
    Wire.send(B00000000); // 09H    Minute alarm
    Wire.send(B00000000); // 0AH    Hour alarm
    Wire.send(B10000000); // 0BH    Day alarm
    Wire.send(B10000000); // 0CH    Weekday alarm
    Wire.send(B10000011); // 0DH    CLKOUT control (00: 32.768Khz 11: 1Hz)
    Wire.send(B00000000); // 0EH    Timer control
    Wire.send(B00000000); // 0FH    Timer
    Wire.endTransmission();

    reportAVRState(3,0);
}

char i = 0;
#define numberOfRegisters 16
char c[numberOfRegisters];

void loop()
{
    Wire.beginTransmission(RTCAddressR);
    Wire.send(0);
    Wire.endTransmission();

    Wire.beginTransmission(RTCAddressR);
    Wire.requestFrom(RTCAddressR, numberOfRegisters);         // request 1 bytes from slave device #32
    
    i = 0;
    while(Wire.available())         // slave may send less than requested
    {
        c[i] = Wire.receive();
        i++;
    }
    Wire.endTransmission();
    
    for(i=0;i<numberOfRegisters;i++)
    {
        Serial.print(i);
        Serial.print(":\t");
        Serial.println(c, BIN);          // receive a byte as character
    }
    
    Serial.println("Waiting a little");
    delay(2000);
}

// Reports the state of the controller via pin 13's led and serial
void reportAVRState(int howManyTimes, int leaveOn)
{
    int i;

    pinMode(statusLED, OUTPUT);

    for (i=0; i < howManyTimes; i++) {
        digitalWrite(statusLED, HIGH);
        delay(200);
        digitalWrite(statusLED, LOW);
        delay(200);  
    }

    if (leaveOn) { 
        digitalWrite(statusLED, HIGH); 
    }

    Serial.println();
    Serial.println("AVR Initialized");
}