The device is optimized for use in many. In addition,. Table 1. Pin Configuration. Pin Name. A0 - A2.
|Published (Last):||7 April 2018|
|PDF File Size:||15.68 Mb|
|ePub File Size:||11.99 Mb|
|Price:||Free* [*Free Regsitration Required]|
The LCD is connected as explained there. First of all, there's three address pins A The memory size of the 24C16 is 16k bits! They are organised in pages with 16 bytes each. The upper three page address bits are transferred together with the slave address which is 0xA0 for writing and 0xA1 for reading. The WP pin can be used to protect certain memory areas from being overwritten calibration values for example.
If tied to Vcc, the upper half memory array is protected. We'll tie it to ground for now. Both write operations have the same structure. Here's the byte-write figure:. First of all, a start condition is generated. Then the slave address byte is transferred. Then the word address is transferred. In our case, the word address has 8 bits. The difference between byte-write and page-write is just the number of data bytes that are transferred now. For a page write, transfer up to 16 bytes.
If more than 16 bytes are transferred, the page address counter will roll over to the first address of the current page. When everything is done, the master generates a Stop condition. The first thing we'll need is some function that initiates TWI operations, such as generating Start and address transfer. TWINT is cleared by writing a 1 to it. The status codes are a good and rich source for errors.
This is not too dangerous now, but I thought it might be worth mentioning. The slave modes are not interesting now. The tables are in the mega8 datasheet print them out. When switching between these modes, it can happen that status codes get mixed up. For writing, only MT mode is used.
Here's the code for sending a Start condition and the slave address. We'll write to page 0, byte 0. The word address and data transfer is described seperately but it's similar. That's all you need for addressing a slave. On the bus side, these transfers are equal, but the status codes are different.
That's why I've divided the code into two parts. The word address and the data byte are true data transfers:. We'll use 0x Again, the expected status code is 0x If we wanted to write the whole page or parts of it , we would just write more data bytes now up to 16 byte in total plus the word address first :.
The TWI hardware does not leave any specific status code after generating the Stop condition. TWINT will also not be set. There are three different read operations: The current address read, the random read from a specific address and the sequential read.
The current address read just consists of a single read transfer without word address:. The slave responds with an ACK. Then a Stop is generated by the master. When reading from a specific address, the word address is transferred first as in a data write operation.
Then a repeated start is generated and the data is read:. Now it's important to understand which transfer modes the master is in: The first time the device address is sent, the master is in MT mode for both the address and the word address transfer. Then, after the repeated start condition, the master is is MR mode. This important, because the status codes come from different tables.
Here's the complete random read code read from address 0 :. For this to work as expected, the first memory location should hold 0x To do that, just write the desired start address after sending the slave address, and read as man bytes as you wish, each time sending an ACK. After the last byte, a NACK has to be sent:. The address pointer will roll over to address 0 after the last byte in memory has been read it does NOT roll over page-wise like in a write page operation!
You can read out all 2k bytes in one go if you want. I've put these examples in a file, with read and write functions for single bytes and pages.
Though not all functions are used by the main code, they have all been tested. The makefile has been generated with mfile. Here's the byte-write figure: First of all, a start condition is generated. Before we can do any printing, we'll have to run through some init code though:. Write Code Example The first thing we'll need is some function that initiates TWI operations, such as generating Start and address transfer.
The very first 24C16 memory location should now be ready to be verified as 0x If we wanted to write the whole page or parts of it , we would just write more data bytes now up to 16 byte in total plus the word address first : Both byte write and page write are terminated with a stop condition:. Then a repeated start is generated and the data is read: Now it's important to understand which transfer modes the master is in: The first time the device address is sent, the master is in MT mode for both the address and the word address transfer.
As you can see in this example, it's very important to look at the right status code! After the last byte, a NACK has to be sent: The address pointer will roll over to address 0 after the last byte in memory has been read it does NOT roll over page-wise like in a write page operation! The files contain connecting information.
Matrix user forums
24C08 EEPROM. Datasheet pdf. Equivalent