_____________________________________________________________________________________ Rev. 1.01 rev.1.01 145 Rt. 46 West E‐mail: sales@electro‐set.net Wayne, NJ 07470 Web: www.Electro‐Set.net 1 CB-029 32k x 8-bit EEPROM Module September 05, 2014 Introduction This application note will show two minimal code set ups to operate the EEPROM module CB- 029 one with an Arduino board and the other with Cardinal’s CB-026 Microchip microcontroller module. The CB-029 EEPROM has 256k bits arranged as 32k 8-bit words. This note will show how to write to and reading from the EEPROM. Arduino The Arduino example will write a text phrase to the EEPROM, read it back and count the occurrence of the letter ‘a’ in the read phrase. The Arduino serial monitor port will be used to display the result. Before proceeding any further, please have the Arduino software install to your computer. Visit Arduino’s user setup guide at http://arduino.cc/en/Guide/windows for step-by-step instructions. Hardware Parts List: Arduino Uno USB type B connector CB-I-022 Cardinal Interface Board CB-029 EEPROM module
10
Embed
CB-029 32k x 8-bit EEPROM Module - Jameco Electronics · 2014. 11. 6. · The CB-029 EEPROM has 256k bits arranged as 32k 8-bit words. This note will show how to write to and reading
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
r e v . 1 . 0 1 145 Rt. 46 West E‐mail: sales@electro‐set.net Wayne, NJ 07470 Web: www.Electro‐Set.net
1
CB-029 32k x 8-bit EEPROM Module
September 05, 2014
Introduction
This application note will show two minimal code set ups to operate the EEPROM module CB-029 one with an Arduino board and the other with Cardinal’s CB-026 Microchip microcontroller module.
The CB-029 EEPROM has 256k bits arranged as 32k 8-bit words. This note will show how to write to and reading from the EEPROM.
Arduino
The Arduino example will write a text phrase to the EEPROM, read it back and count the occurrence of the letter ‘a’ in the read phrase. The Arduino serial monitor port will be used to display the result.
Before proceeding any further, please have the Arduino software install to your computer. Visit Arduino’s user setup guide at http://arduino.cc/en/Guide/windows for step-by-step instructions.
Hardware
Parts List:
Arduino Uno USB type B connector CB-I-022 Cardinal Interface Board CB-029 EEPROM module
r e v . 1 . 0 1 145 Rt. 46 West E‐mail: sales@electro‐set.net Wayne, NJ 07470 Web: www.Electro‐Set.net
2
Connect the components as shown in the picture below
Plug the CB-I-022 interface into the Arduino Uno board and the CB-029 EEPROM module into the interface’s Electro-Set 6 pin connector. Connect the USB cable between the computer and the Arduino Uno.
The computer will supply 5 volts through the USB cable which will be regulated on the Arduino interface board to 3.3 volts to run the CB-029 EEPROM module.
Three jumpers on the CB-029 can be used to change the slave address of the EEPROM. For this code example we are using 0x57 as the 7-bit slave address so the three jumper should be populated towards the center of the board as shown in the picture above. This makes the lower three slave address bits a logic one (high), the 7 in 0x57 slave address.
r e v . 1 . 0 1 145 Rt. 46 West E‐mail: sales@electro‐set.net Wayne, NJ 07470 Web: www.Electro‐Set.net
5
Serial.println(count);
while(1); // Go no further, we are done, loop forever
} // end of loop()
Code Operation
The EEPROM module has a 7-bit I2C slave address as 0x57 which we make a #define.
The setup() function is called when sketch starts. The setup code, initializes the serial monitor baud rate at 9600, outputs a welcome message and then initializes the I2C port as a master. We compute the length of the text phrase stored in the “someText” array and output this length (‘len’) to the serial monitor which for our example turns out to be 53 bytes.
After setup has completed, sketch causes the function loop() to be repeatedly called.
The variable ‘index’ is used to access through the “someText” array and is also used as the memory address in the EEPROM. The EEPROM memory address is 16-bits wide, we use the upper byte of ‘index’ for the MSB of the EEPROM address and the lower byte of ‘index’ for the LSB of the EPROM address. In our example the MSB will always be 0x00 and LSB will range from 0x00 to 0x52. The ‘while’ loop takes one byte at a time from the ‘someText’ array and writes it to the EEPROM, looping ‘len’ (53) time to completely write the phrase.
Take special note of the ‘delay(5);’ code line. Without this the writes to EEPROM will be arriving too fast for the EEPROM and will be discarded. The write cycle time from the datasheet is specified at 5mS.
Next the code reads back the values from the EEPROM using a ‘for’ loop (just to be different). As each byte is retrieved it is compared against the character ‘a’, if matching the ‘count’ variable is incremented. Once the ‘for’ loop completes its 53 iterations, the value of the ‘count’ variable is output to the serial monitor. Lastly we execute the code ‘while(1);’, this puts the microcontroller into an endless loop doing nothing harmful and causing our code in the sketch ‘loop()’ function to execute only once. As an alternative, we could have placed all our code in the sketch ‘setup()’ function since it only executes once.
r e v . 1 . 0 1 145 Rt. 46 West E‐mail: sales@electro‐set.net Wayne, NJ 07470 Web: www.Electro‐Set.net
6
Microchip Module CB-026
The CB-026 example in PICBASIC PRO will write 10 data values into the EEPROM on the CB-029 module then read them back displaying the data values via the serial port to a terminal emulator such as hyperterminal
Before proceeding any further, please have the MicroCode Studio PICBASIC PRO suite installed on your computer.
Hardware
Parts List:
Electro-Set module CB-026 microcontroller USB type mini connector CB-029 EEPROM module
includes configuration for the programmer in the output hex file so it does not necessary to manually change the entries in the programmer configuration window every time you come to write a new version of your program to the microcontroller.
The port pins for the I2C interface are set on PORTC pins 3 and 4. The CB-026 board wires these to the Electro-Set 6 pin connector.
The microcontroller serial port pins are set on PORTC pins 6 and 7, these connect to the FTDI chip on the CB-026 which couples through to the USB and so when plugged into a PC producing a virtual COMM port where the microcontroller’s serial data can be seen on a terminal emulator such as hyperterminal. The terminal emulator should be set to connect to the virtual COMM port assigned to the FTDI driver and connect at 38400,8,N,1.
We declare the variable baud1 for use in the serout2 to set the baud rate. For a baud rate of 38400, baud1 is set to 6, see the MicroChip documentation for other rates and options.
The first parameters for the PicBasicPro functions i2cread and i2cwrite uses and 8-bit slave address which is a one bit left shift of the 7-bit slave address, so the A/D module’s 8-bit slave address as 0xAE.
The line
for eepromadd = 1 to 10
sets up a ‘for’ loop to sequentially increment the 16-bit word variable eepromadd from 1 to 10. These are the address locations we will write to in this example. In this loop we take the lower 8-bits of eepromadd, double that value and save the result in the byte variable eepromdata, this is the value we will write using the following line of code:
i2cwrite sda,scl,$AE,EEpromadd,[eepromdata],nodata ‘ write the data into the EEPROM
Between successive writes to the EEPROM we need some delay, around 5mS. Without this delay the write will be rejected by the EEPROM.