We shall explain these steps in detail below. Having done so the MCU seizes the bus and no other device can send data until the MCU releases the bus, to avoid data collisions. After that, the MCU can start sending data. In this section, we will write a function for the MCU to be a master on the two-wire serial bus. This bit is set to 1 by the hardware when the I2C module finishes its current job and is ready to get more commands from the SW.
|Published (Last):||15 December 2013|
|PDF File Size:||19.3 Mb|
|ePub File Size:||6.66 Mb|
|Price:||Free* [*Free Regsitration Required]|
What is ROM? Read-Only Memory ROM is a type of computer memory which, generally speaking, is only programmed once or very occasionally and then gets read from the rest of the time. This makes it ideal for things like firmware which need to be "remembered" by the computer, but never actually change. This was memory made up of discrete semiconductor diodes placed on a specially organized PCB.
This gave way to Mask ROM with the advent of integrated circuits. Mask ROM had to be programmed by the manufacturer and was thereafter not alterable. Unfortunately, Mask ROM was expensive and took a long time to produce because each new program required a brand new device to be manufactured by a foundry. That meant manufacturers could produce millions of the same unprogrammed device which made it cheaper and more practical. PROM, however, could only be written to once using a high-voltage programming device.
After a PROM device was programmed, there was no way to return the device to its unprogrammed state. A UV Erasable Microcontroller. The window gives it away.
This changed in with the invention of EPROM Erasable Programmable ROM which — besides adding another letter to the acronym — brought with it the ability to erase the device and return it to a "blank" state using a strong UV light source. In most applications the pros outweigh the cons, but you should be aware of them before incorporating EEPROM into your next design.
This has to do with electrons becoming trapped in the transistors that make up the ROM and building up until the charge difference between a "1" and a "0" is unrecognizable. That said, this usually occurs over the course of years although it can be accelerated by heat.
Now we can move on to the code. This should get us comfortable with the idea of using EEPROM and also give us a feeling for how much data can really fit on a small device. Once you have that downloaded and installed, we can get down to business. Heads up! Send the Least Significant Byte of the memory address that you want to write to. Send the data byte that you would like to store at this location. There are probably a few key words there that bare explaining: Memory Addresses If you imagine all of the bytes in a Kbit EEPROM standing in a line from 0 to — because there are 8 bits to a byte and therefore you can fit bytes on a Kbit EEPROM — then a memory address is the place in line where you would find a particular byte.
Page Writing Writing one byte at a time is fine, but most EEPROM devices have something called a "page write buffer" which allows you to write multiple bytes at a time the same way you would a single byte. The EEPROM uses an internal counter that automatically increases the memory location with each following data byte it receives. Once a memory address has been sent we can follow it with up to 64 bytes of data.
The EEPROM assumes rightly that an address of followed by 10 bytes will record byte 0 at address , byte 1 at address , byte 2 at address , and so on. First we send the MSB of the address. Then we send the LSB of the address. Then we send the data that we want to store. Now you should be seeing a bunch of zeros appearing in your terminal window.
For testing purposes, I suggest using the complete text of the Ghostbusters theme as written and performed by Ray Parker Jr. You can get the text file below. Ghostbusters TXT Select that file and be sure to click on the "binary" button, so that the file is written byte-for-byte over the serial port.
You can go ahead and close TeraTerm, it worked! Ask for the data byte at that location. Then we ask for the number of bytes that we want to receive. Make sure to uncheck the "Append" option and check the "Binary" option. This makes sure that the terminal will start a fresh logfile and write to it byte-for-byte what comes over the terminal. When you press "Save" another dialog window will appear but it may pop under the current window Go find it, it will come in handy in a second.
Check the logfile window and see how many bytes have been transferred. Now close everything and open up that logfile in a text editor. You should now be face to face with, you guessed it, the complete text of the Ghostbusters theme as written and performed by Ray Parker Jr. Oh yeah, plus a bunch of junk that represents the unwritten space in memory.
For instance, the Microchip 24LC can store up to Kbits! Because the memory space is so much larger, two bytes is no longer enough to represent the memory address that we want to modify. To get around this problem, the 24LC splits up the memory addresses into two separate blocks.
You can get the complete Arduino example sketches here if you want to play with it yourself: Heads up! Why stop at song lyrics? Why not store journals or bitmaps Actually, to think of it, sensor readings are probably the most practical thing to use it for
Reading and Writing Serial EEPROMs
How to Interface an External EEPROM with AVR Atmega32