Hooking up an I2C device, like an EEPROM, is relatively simple. I2C uses a 2-pin bus, with labels SCL (clock) and SDA (data). In case your microcontroller has a built in I2C controller, it is wise to hook these two lines to that port. However, I generally write it in software, because the hardware is slightly more complicated than needed (it handles clock skewing, master/slave configurations and multiple devices) in this case. It also does not give you the nice three byte buffer, which the UART (serial port input) does. If you do write it in software, it is best to hook the data input to the so-called "open collector" port. On most older PIC microcontrollers, like the 16F628(A), this is RA4 (port A bit 4). Note that both lines need pull up resistors. The values of these resistors depend on the speed that you wish to transmit data over. The disadvantage of low values is the current drain on the system. 1k Ohm works well. Note that the 24LCxxx (xxx indicates the memory in bits, a 512 module therefore has 64K of memory) needs its own decoupling capacitor, which as usual I chose to be 0.1uF. The write protect line and the address lines can all be grounded, unless you plan to have more than 64K of memory: you will need to configure different addresses for each of the EEPROM in that case.
Reading the EEPROM runs at 400 kHz. Not very fast, but suitable (and it seems most of them allow you to go up to 700 kHz, if needed). Writing is slower: you can send up to 256 bytes to the EEPROM without any delay, but after that a wait is needed (so-called ack-polling) until the EEPROM is available again for other operations.
Geen opmerkingen:
Een reactie posten