Hallo, kann sich einer von euch mal den Code angucken und mir nen Tip geben was ich falsch mache? Möchte den DS1307 auslesen. Der MC soll mir die Daten seriell ausgeben und auf dem Display. Ich benutze die I2C lib von Peter Fleury und bekomms nicht hinn. Das Display zeigt 53:53:53 an :p
1 | #include "uart.h" |
2 | #include "i2cmaster.h" |
3 | #include <util/delay.h> |
4 | #include "lcd.h" |
5 | #include "rtc2.h" |
6 | #define BAUDRATE 9600UL
|
7 | |
8 | |
9 | |
10 | #define DS1307 0xD0 // Device Adresse des DS2307
|
11 | |
12 | |
13 | unsigned char time_s; |
14 | unsigned char time_m; |
15 | unsigned char time_h; |
16 | unsigned char time_dayofweek; |
17 | unsigned char time_day; |
18 | unsigned char time_month; |
19 | unsigned char time_year; |
20 | unsigned char buffer1[10]; // Buffer für itoa RTC |
21 | |
22 | |
23 | void uart_init (void) |
24 | {
|
25 | uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/(16*BAUDRATE) - 1); |
26 | |
27 | UBRR0H = (uint8_t) (ubrr>>8); |
28 | UBRR0L = (uint8_t) (ubrr); |
29 | |
30 | // UART Receiver und Transmitter anschalten
|
31 | // Data mode 8N1, asynchron
|
32 | UCSR0B = (1 << RXEN0) | (1 << TXEN0); |
33 | //UCSR0C = (1 << URSEL) | (1 << UCSZ01) | (1 << UCSZ00);
|
34 | |
35 | // Flush Receive-Buffer (entfernen evtl. vorhandener ungültiger Werte)
|
36 | do
|
37 | {
|
38 | UDR0; |
39 | }
|
40 | while (UCSR0A & (1 << RXC0)); |
41 | }
|
42 | |
43 | char set_clock (unsigned char reg, unsigned char val) |
44 | {
|
45 | if (i2c_start(DS1307+I2C_WRITE) != 0) return 1; |
46 | i2c_write(reg); |
47 | i2c_write(val); |
48 | i2c_stop(); |
49 | return 0; |
50 | }
|
51 | |
52 | char get_time(unsigned char reg) |
53 | {
|
54 | unsigned char val; |
55 | |
56 | i2c_start(DS1307+I2C_WRITE); |
57 | i2c_write(reg); |
58 | i2c_stop(); |
59 | i2c_start(DS1307+I2C_READ); |
60 | val = i2c_readNak(); |
61 | i2c_stop(); |
62 | }
|
63 | |
64 | |
65 | |
66 | void uart_puts (const char *s) |
67 | {
|
68 | do
|
69 | {
|
70 | uart_putc (*s); |
71 | }
|
72 | while (*s++); |
73 | }
|
74 | |
75 | |
76 | |
77 | int main() |
78 | {
|
79 | lcd_init(LCD_DISP_ON); |
80 | |
81 | |
82 | uart_init(); |
83 | |
84 | i2c_init(); |
85 | |
86 | _delay_ms(300); |
87 | |
88 | ds1307_init; |
89 | |
90 | _delay_ms(300); |
91 | lcd_clrscr(); |
92 | |
93 | lcd_gotoxy(0,0); |
94 | |
95 | lcd_puts("Bereit"); |
96 | _delay_ms(300); |
97 | |
98 | set_clock(0x07, 0x00); |
99 | set_clock(0x02, 0x00); |
100 | set_clock(0x01, 0x00); |
101 | set_clock(0x00, 0x00); |
102 | |
103 | |
104 | while (1){ |
105 | |
106 | |
107 | get_time(0x00); |
108 | time_s = get_time; |
109 | uart_puts(time_s); |
110 | |
111 | get_time(0x01); |
112 | time_m = get_time; |
113 | uart_puts(time_s); |
114 | |
115 | get_time(0x02); |
116 | time_h = get_time; |
117 | uart_puts(time_s); |
118 | |
119 | |
120 | lcd_clrscr(); |
121 | |
122 | sprintf(buffer1, "Zeit: %02x:%02x:%02x", time_h, time_m, time_s); |
123 | lcd_puts(buffer1); |
124 | |
125 | |
126 | |
127 | }
|
128 | }
|