Download Final report - Atomic Rhubarb
Transcript
return (ACK);
else if ((I2CSTAT & RECEIVED_NACK) == RECEIVED_NACK) {
I2CCTL |= FLUSH_TXD;
I2C_start ();
I2C_stop ();
data = I2C_read_byte ();
// Clear I2C Receive buffer
printf ("\n\n\rI2C Error - NACK Received");
return (NACK);
}}}
void I2C_Send_NACK (void) {
I2CCTL |= SEND_NACK;
// Send NOT Acknowledge
}
void I2C_Receive_Data_Full (void) {
while ((I2CSTAT & RECEIVE_DATA_REG_FULL) == 0x00) //Wait for Receive Buffer Full
;
}
3.3.2 Data Transfer
The DS1307 device address is 7-bit, 1101000. The last bit is for direction, 0 for write and
1 for read. The definition of the device identification code in the program is as follows,
#define EEPROM_Read_Address 0xD1
#define EEPROM_Write_Address 0xD0
//I2C EEPROM Read Address
//I2C EEPROM Write Address
The data transfer between Z8 and RTC is followed by 2-wire serial data bus. That is, the
bus is controlled by Z8 microcontroller that generates the serial clock (SCL), controls the
bus access, and generates the START and STOP conditions. The DS1307 operates as a
slave device on the serial bus. Access is obtained by implementing a START condition
and providing a device identification code followed by a register address. Subsequent
registers can be accessed sequentially until STOP condition is executed. Each receiving
device, when addressed, is obliged to generate an acknowledge after reception of each
byte. The DS1307 data write and read are shown in Figure 17.
(a) Data Read
(b) Data Write
Figure 17: DS1307 Data Transfer
24