Hallo Forumgemeinde,
ich will mir eine Digitaluhr bauen und habe deshalb einen 0815 PIC (haha
;-) ) bestellt, dazu die DS1307. Nur kann ich keine Daten aus ihr
abfragen. Der µC hängt dann in der ACK-Schleife.
Pullup: 5,6k
Spannung: 5V (via USB)
Anschluss an RB4 & RB6
Wenn ich eine bestimmte Delay-Zeit mache, kommt lustigerweise immer 95
heraus.
Abfrage:
1 | unsigned char read_ds1307(unsigned char address)
|
2 | {
|
3 | unsigned char data;
|
4 | SSP1CON2bits.SEN = 1;
|
5 |
|
6 | SSPBUF = 0xD0;
|
7 | while(SSP1CON2bits.ACKSTAT);
|
8 |
|
9 | SSPBUF = address;
|
10 | while(SSP1CON2bits.ACKSTAT);
|
11 |
|
12 | SSP1CON2bits.RSEN = 1;
|
13 |
|
14 | SSPBUF = 0xD1;
|
15 | while(SSP1CON2bits.ACKSTAT);
|
16 |
|
17 | SSP1CON2bits.RCEN = 1;
|
18 |
|
19 | data = SSPBUF;
|
20 | while (!BF);
|
21 |
|
22 | SSPCON2bits.ACKDT = 1;
|
23 | SSP1CON2bits.ACKEN = 1;
|
24 | SSP1CON2bits.PEN = 1;
|
25 |
|
26 | return(data);
|
27 | }
|
28 |
|
29 | void write_ds1307(unsigned char address, unsigned char value)
|
30 | {
|
31 | SSP1CON2bits.SEN = 1;
|
32 |
|
33 | SSPBUF = 0xD1;
|
34 | while(SSP1CON2bits.ACKSTAT);
|
35 |
|
36 | SSPBUF = address;
|
37 | while(SSP1CON2bits.ACKSTAT);
|
38 |
|
39 | SSPBUF = value;
|
40 | while(SSP1CON2bits.ACKSTAT);
|
41 |
|
42 | SSP1CON2bits.PEN = 1;
|
43 | }
|
Aufruf:
1 | void readTime(void)
|
2 | {
|
3 | unsigned char res1 = read_ds1307(minutes);
|
4 | unsigned char res2 = read_ds1307(hours);
|
5 |
|
6 | ledMinutes = (res1 % 16) + (((char) res1 / 16) * 10);
|
7 | ledHours = (res2 % 16) + (((char) res2 / 16) * 10);
|
8 | }
|
9 |
|
10 | void writeTime(void)
|
11 | {
|
12 | unsigned char send1 = ((char) ledMinutes / 10) * 16 + ledMinutes % 10;
|
13 | unsigned char send2 = ((char) ledHours / 10) * 16 + ledHours % 10;
|
14 |
|
15 | write_ds1307(minutes, send1);
|
16 | write_ds1307(hours, send2);
|
17 | }
|
Defines:
1 | #define minutes 0x01
|
2 | #define hours 0x02
|
3 | #define ctrl 0x07
|
Kennt jemand dieses Problem, bzw. kann vielleicht jemand mit dem
Zaunpfahl auf meinen Fehler klopfen?
Quarz ist dran, Knopfzelle auch...
Vielen Dank im Voraus,
Freddy