How the Convers+ firmware accesses the external EEPROM
Posted: 28 Dec 2019, 13:31
This topic is used to get familar with the way the Convers+ firmware reads, processes and writes the content of the external EEPROM. It contains some important informations like the type of car, engine and of course the total and trip mileages.
Here is a picture of it on the board which shows the part an it's pins:
It is a "Atmel 24C16A" and before start looking into the firmware, we need to get familar of how it's work and how to access or write data into it.
EEPROM data transfer logic (I2C)
The chip uses an I2C interface to communicate (here i describe the basics of I2C communication: viewtopic.php?f=40&t=106) I2C is primarily made of two signals, SCL for a clock and SDA for data, the other pins are used to preset a special mode of the chip:
PB0, PB1, PRE are used to hardware-protect some regions of the data. Both pins are fixed to GND on the mainboard, so they are both "0" what means "no protection at all".
The MODE/WC pin is used to decide on write-operations if a full page of data is written (MODE=1), or just a bunch of bytes as multibyte (MODE=0) in the initial START-sequence. The pin follows the SCL signal level by a 4,7k resistor. This way MODE is HIGH if clock is HIGH and vice versa.
To start communication the uC which acts as a master must initiate a START condition. The 8 bits sent after a START condition are made up of 4 bits device ID (static "1010"), followed by 3 block select bits and one bit for a READ (RW = 1) or WRITE (RW = 0) operation.
In the "Byte Write mode" the master sends one data byte, then terminates the transfer by generating a STOP condition. This mode is independant of the state of the MODE pin which could be left floating if only this mode was to be used.
For the "Multibyte Write mode", the MODE pin must be HIGH. The Multibyte Write mode can be started from any address in the memory. The master sends from one up to 8 bytes of data.
For the "Page Write mode", the MODE pin must be at LOW. The Page Write mode allows up to 16 bytes to be written in a single write cycle, provided that they are all located in the same ’row’ in the memory: that is the same Block Address bits (b3, b2, b1 of Device Select code in Table 3) and the same 4 MSBs in the Byte Address. After each byte is transfered, the internal byte address counter (4 Least Significant Bits only) is incremented.
All modes need a lower address byte to be sent first, then the corresponding data bytes follows (1 up to 16, depending pn choosen mode).
I2C Bus controlled by Microcontroller
The firmware uses the integrated I2C bus module of the MAC7116 to communicate with this part:
The register address range of the I2C module is 0xFC0A C000 - 0xFC0A FFFF. But only the first 8 bytes are used. The memory map from the datasheet:
Meaning of IO registers
The IBAD register is only used if the uC is setup as I2C slave, which in the Convers+ is not the case.
IBFD registers setup the bus signal timings.
IBCR register keeps track of some settings: The IBSR is used to check for bus status and ACK and other signals: A write to IBDR issues the byte to be sent via I2C to the EEPROM. Received data can also be read from this register: For more informations read the datasheet of the MAC7116 from chapter 24 onwards.
Here is a picture of it on the board which shows the part an it's pins:
It is a "Atmel 24C16A" and before start looking into the firmware, we need to get familar of how it's work and how to access or write data into it.
EEPROM data transfer logic (I2C)
The chip uses an I2C interface to communicate (here i describe the basics of I2C communication: viewtopic.php?f=40&t=106) I2C is primarily made of two signals, SCL for a clock and SDA for data, the other pins are used to preset a special mode of the chip:
PB0, PB1, PRE are used to hardware-protect some regions of the data. Both pins are fixed to GND on the mainboard, so they are both "0" what means "no protection at all".
The MODE/WC pin is used to decide on write-operations if a full page of data is written (MODE=1), or just a bunch of bytes as multibyte (MODE=0) in the initial START-sequence. The pin follows the SCL signal level by a 4,7k resistor. This way MODE is HIGH if clock is HIGH and vice versa.
To start communication the uC which acts as a master must initiate a START condition. The 8 bits sent after a START condition are made up of 4 bits device ID (static "1010"), followed by 3 block select bits and one bit for a READ (RW = 1) or WRITE (RW = 0) operation.
In the "Byte Write mode" the master sends one data byte, then terminates the transfer by generating a STOP condition. This mode is independant of the state of the MODE pin which could be left floating if only this mode was to be used.
For the "Multibyte Write mode", the MODE pin must be HIGH. The Multibyte Write mode can be started from any address in the memory. The master sends from one up to 8 bytes of data.
For the "Page Write mode", the MODE pin must be at LOW. The Page Write mode allows up to 16 bytes to be written in a single write cycle, provided that they are all located in the same ’row’ in the memory: that is the same Block Address bits (b3, b2, b1 of Device Select code in Table 3) and the same 4 MSBs in the Byte Address. After each byte is transfered, the internal byte address counter (4 Least Significant Bits only) is incremented.
All modes need a lower address byte to be sent first, then the corresponding data bytes follows (1 up to 16, depending pn choosen mode).
I2C Bus controlled by Microcontroller
The firmware uses the integrated I2C bus module of the MAC7116 to communicate with this part:
The register address range of the I2C module is 0xFC0A C000 - 0xFC0A FFFF. But only the first 8 bytes are used. The memory map from the datasheet:
Meaning of IO registers
Code: Select all
I2C Offset Register Description Access
0xFC0A C000 I2C Bus Address Register (IBAD) R/W
0xFC0A C001 I2C Bus Frequency Divider Register (IBFD) R/W
0xFC0A C002 I2C Bus Control Register (IBCR) R/W
0xFC0A C003 I2C Bus Status Register (IBSR) R/W
0xFC0A C004 I2C Bus Data I/O Register (IBDR) R/W
IBFD registers setup the bus signal timings.
IBCR register keeps track of some settings: The IBSR is used to check for bus status and ACK and other signals: A write to IBDR issues the byte to be sent via I2C to the EEPROM. Received data can also be read from this register: For more informations read the datasheet of the MAC7116 from chapter 24 onwards.