Download Reading/Writing EEPROM Using I2C Bus Interface 3 Interrupts

Transcript
SH7262/SH7264 Group
3.4
Reading/Writing EEPROM
Using I2C Bus Interface 3 Interrupts
Sample Program Listing "main.c" (3/6)
98
void main(void)
99
{
100
int i,ack;
101
102
/* ==== Clears the buffer storing the data ==== */
103
for(i=0;i<DATA_LENGTH;i++){
104
ReadData[i] = 0x00;
105
}
106
/* ==== Creates the write data ==== */
107
for(i=0;i<DATA_LENGTH;i++){
108
WriteData[i] = DATA_LENGTH+i;
109
}
110
111
/* ==== Configures IIC3 ==== */
112
io_iic3_init();
113
114
/* ==== Writes data to EEPROM ==== */
115
eeprom_write(DEVICE_CODE,
116
/* Device code */
DEVICE_ADDR,
/* Device address */
117
0x0000,
/* Write start address */
118
sizeof(WriteData), /* Write data size */
119
WriteData);
/* Buffer storing data */
120
121
/* ==== Acknowledge Polling ==== */
122
while( eeprom_ack_polling(DEVICE_CODE, DEVICE_ADDR) != E_OK){
123
/* Waits until reprogramming EEPROM internally is completed */
124
}
125
126
/* ==== Reads data from EEPROM ==== */
127
eeprom_read(DEVICE_CODE,
128
DEVICE_ADDR,
/* Device code */
/* Device address */
129
0x0000,
/* Read start address */
130
sizeof(ReadData),
/* Read data size */
131
ReadData);
/* Buffer storing data */
132
133
/* ==== Compares the result ==== */
134
for(i=0; i<DATA_LENGTH; i++){
135
if( WriteData[i] != ReadData[i] ){
136
while(1){
137
/* error */
138
}
139
}
140
}
141
while(1){
142
/* Loop */
143
144
}
}
R01AN0068EJ0101 Rev. 1.01
Feb.10, 2012
Page 21 of 38