Real Time Clock Module with I2C Interface
0.3
⇒ back to Project Page
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Macros
Pages
src
isr.c
Go to the documentation of this file.
1
/****************************************************************************/
36
/******************************************
37
\internal
38
Include files
39
*******************************************/
40
41
#include <avr/io.h>
42
#include <avr/interrupt.h>
43
44
#include "
rtc_control.h
"
45
#include "
port_definitions.h
"
46
#include "
i2c.h
"
47
#include "dcf77.h"
48
49
#if RTC_LCD_DEBUG == 1
50
#include <stdlib.h>
51
#include "
lcd.h
"
52
#endif
53
54
55
/******************************************
56
\internal
57
Global variables
58
*******************************************/
59
60
extern
volatile
uint8_t
time_scale
;
// counter triggered by timer
61
62
extern
volatile
uint8_t
i2c_slave_data_arrived
;
// indicates new arrived data from I2C master in buffer
63
extern
volatile
uint8_t
slave_number_bytes
;
// number of bytes sent by I2C master
64
extern
volatile
uint8_t
i2c_slave_mode_blocked
;
// device is blocked an can not receive any data from I2C master
65
extern
volatile
uint8_t
ctrl_data
[10];
// buffer for data I/O with an external master (via interrupt)
66
67
extern
volatile
dcf77_config_data
dcf77_config
;
68
extern
volatile
real_time_data
dcf77_time
;
69
70
71
72
/****************************************************************************/
89
/****************************************************************************/
90
91
ISR
(TIMER0_COMPA_vect) {
92
93
//set time scale
94
if
(
time_scale
>=
MAX_TIME_SCALE
) {
95
time_scale
= 0;
96
}
else
{
97
time_scale
++;
98
}
99
100
//update DCF77 sync
101
if
(dcf77_config.
dcf_enabled
> 0) {
102
103
dcf77_config.
current_dcf_signal
= (ACSR >> ACO) & 0x01;
104
105
if
(dcf77_config.
current_dcf_signal
== 1) {
//comparator input below bandgap reference
106
DCF_LED_PORT
=
DCF_LED_PORT
& ~(1 <<
DCF_LED_ADDR
);
107
}
else
{
108
DCF_LED_PORT
=
DCF_LED_PORT
| (1 <<
DCF_LED_ADDR
);
109
}
110
111
//sync only if sync is not completed
112
if
(dcf77_config.
dcf_state
!= DCF77_TIMESYNC_COMPLETED) {
113
dcf77_config.
dcf_state
=
dcf77_sync
(dcf77_config.
current_dcf_signal
, DCF77_ACTIVE_LOW,
114
&
dcf77_time
,
DCF77_SAMPLE_TIME
, DCF77_GET_TIME);
115
116
}
117
}
118
119
120
}
121
122
123
/****************************************************************************/
136
/****************************************************************************/
137
138
139
ISR
(TWI_vect) {
140
141
uint8_t status;
142
#if RTC_LCD_DEBUG == 1
143
static
char
tmp_char[10];
144
#endif
145
146
status =
i2c_slave_data_io
(
ctrl_data
, &
slave_number_bytes
,
I2C_SLAVE_MODE_CONTINUE
);
147
148
if
((status ==
I2C_STO_REPSTART_COND
) ||
149
(status ==
I2C_DATA_NOACK_RCVD
) ||
150
(status ==
I2C_GCA_DATA_NOACK_RCVD
)) {
151
i2c_slave_mode_blocked
=
FALSE
;
//Transmission completed
152
if
(
slave_number_bytes
> 1) {
//more than only register address set?
153
i2c_slave_data_arrived
=
TRUE
;
154
}
155
}
else
if
(status ==
I2C_DATA_NOACK_TRANS
|| status ==
I2C_LAST_DATA_ACK_TRANS
) {
156
i2c_slave_mode_blocked
=
FALSE
;
//Transmission completed
157
}
else
if
((status ==
I2C_SLAW_ACK_RCVD
) ||
158
(status ==
I2C_SLAW_ACK_ARB_LOST
) ||
159
(status ==
I2C_GCA_ACK_RCVD
) ||
160
(status ==
I2C_GCA_ACK_ARB_LOST
) ||
161
(status ==
I2C_DATA_ACK_RCVD
) ||
162
(status ==
I2C_GCA_DATA_ACK_RCVD
) ||
163
(status ==
I2C_SLAR_ACK_RCVD
) ||
164
(status ==
I2C_SLAR_ACK_ARB_LOST
) ||
165
(status ==
I2C_DATA_ACK_TRANS
)) {
166
i2c_slave_mode_blocked
=
TRUE
;
//Transmission NOT completed
167
}
else
if
(status ==
I2C_IO_BUS_ERROR
) {
168
i2c_slave_mode_blocked
=
FALSE
;
//Transmission aborted or no transmission
169
}
else
{
170
#if RTC_LCD_DEBUG == 1
171
lcd_set_cursor
(14, 3);
172
lcd_send_string
(
"!R"
,
FALSE
);
173
itoa(status, tmp_char, 16);
174
lcd_send_string
(tmp_char,
FALSE
);
175
#endif
176
}
177
178
}
179
Generated on Mon Mar 25 2013 14:30:41 for Real Time Clock Module with I2C Interface by
1.8.2