Please show a processing example (master operation) in the case of connection to external EEPROM via the I2C bus.
- 1. Outline of processing procedure
Communication process is shown below.
- (0) Set ports. (Setting of PM32, 33 to 1, and P32, 33 to 0)
(1) Set transfer clock.
(2) Set control register. (9-clock wait mode)
(3) Set port. (Set PM32, 33 to 0)
(4) Issue stop condition and check if bus is released.(Check if interrupt or SPD0 is set.)
(5) Issue start condition and take exclusive control of bus.(Check that STD0 is set.)
(6) Transmit slave address and check existence of the slave (ACK). (Check ACKD0 at the interrupt timing. If there is no ACK, stop transfer.)
(7) Transmit the EEPROM address.
In the case of writing data to EEPROM, the following steps are then performed.
(8) Send write data and check ACK using an interrupt.(If there is no ACK, end transfer operation.)
(9) If write data remains, repeat from step (8).
(10) Issue a stop condition to stop writing.(The EEPROM then starts writing the transmitted data to its memory block.)
In the case of reading data from EEPROM, perform the following steps.
(11) Issue a start condition and set the data transfer direction to the read direction.
(12) Set 8-clock wait and enable auto ACK mode.
(13) Write dummy data (0FFH) to start transfer.
(14) If the reception completion interrupt is generated, read the data.
(15) Once all the data has been received, disable auto ACK mode and set 9-clock wait and release the wait at the timing of 8th clock.
(16) Wait the interrupt at 9th clock and issue a stop condition.
- 2. Processing flow
- The processing flow is shown in the form of a PDF file.
(Sorry, the PDF file is constructing now.)
For simplification purposes, it is assumed here that all the data can be read and written continuously.
- 3. Notes
- (1) About ACK
Loops are prohibited during ACK wait when ACK was not received.
The ACK timing in I2C is fixed, and if ACK is not received at this timing, no ACK will be perceived.
If ACK is not received, stop communication.
(2) About transfer direction
When reading data from the slave, a 2-byte address is sent as data to the slave (EEPROM).
If nothing more is done, data reception does not start.
Such an operation is not possible as the I2C bus.
After specifying the EEPROM address, restart must be performed and communication must be restarted by data read.
Please check the specifications of the EEPROM that is used.