Overview
The 25AA010A is 1Kbit SPI bus serial EEPROM. It could handle up to 10MHz clock frequency with a high endurance of 1M erase/write cycles. Its memory space is organized into 128x8-bit.
Simulating Program in Proteus |
It has various device's package including a DIP-8 package for hobbyists prototyping.
Device Selection Table |
I don't have a physical device of this chip. So I just take a model of this chip to simulate in Proteus.
Package Types and Pin Function Table |
The SPI transfer and receive must have the following data bytes, instruction, address, and data.
Block Diagram, Instructions, and SPI Read Sequence |
The read command is 0x03 follows by the EEPROM address. The EEPROM 8-bit data will shift out by the SPI read routine issued by the microprocessor.
Writing data to the EEPROM requires around 5ms. It requires a write enable instruction before the data writing sequence able to process.
Write Enable and Disable Commands |
Write-enable command is 0x06 while the Write-disable command is 0x04. Additionally the Write Protect (WP) pin must pull high to enable data writing.
Byte write sequence instruction is 0x02 follows by the EEPROM address and the 8-bit data. It also has a page write sequence to write a burst of 16 bytes data package. The microprocessor needs to wait around 5ms to complete data writing.
Byte and Page Write Sequences |
The Read Status Register Instruction is optional you can read the device datasheet for more detail.
PIC16F887 MPLABX IDE and XC8 Programming
I use a PIC16F887 micro-controller from Microchip Technology. It has the SPI module inside along with the I2C module. The XC8 C compiler is free to use without registering or buy a software license.
Screen Shot of This Example Program |
In this example, the microprocessor write and read the EEPROM data from this SPI chip. It will show on a 20x2 character LCD and PORTB of PIC16F887 micro-controller.
/* * File: main.c * Author: Admin * * Created on February 13, 2024, 3:49 PM */ #include <xc.h> #include "config.h" #include "LCD4Bits.h" #include "spi.h" #define _XTAL_FREQ 8000000UL void write_25AA010(uint8_t address, uint8_t data){ /*Write Enable Command*/ nCS=0; spi_send(0x06); nCS=1; /*Write Process*/ nCS=0; spi_send(0x02); spi_send(address); spi_send(data); nCS=1; /*EEPROM Write Time*/ __delay_ms(10); } void write_text(uint8_t start, uint8_t *txt){ uint8_t addr=0; while(*txt){ write_25AA010(start+addr,*txt++); addr++; } } uint8_t read_25AA010(uint8_t address){ uint8_t data; nCS=0; spi_send(0x03); spi_send(address); data=spi_receive(); nCS=1; return data; } void main(void) { OSCCONbits.IRCF=7; lcdInit(); spi_init(); uint8_t data; uint8_t txt[]="PIC16F887 24AA010A"; write_text(0,txt); for(uint8_t i=0;i<sizeof(txt)-1;i++){ data=read_25AA010(i); lcdData(data); } PORTB=0; TRISB=0; ANSELH=0; while(1){ for(uint8_t i=0;i<8;i++){ write_25AA010(20+i,1<<i); PORTB=read_25AA010(20+i); __delay_ms(100); } __delay_ms(1000); for(int8_t i=7;i>=0;i--){ write_25AA010(40-i,1<<i); PORTB=read_25AA010(40-i); __delay_ms(100); } __delay_ms(1000); } return; }
I wrote an SPI driver that it's putted in one package.
The SPI.h header file:
/* * File: spi.h * Author: Admin * * Created on February 9, 2024, 9:13 AM */ #include <xc.h> #define nCS RC2 void spi_init(void); void spi_send(uint8_t data); uint8_t spi_receive(void);
The SPI.c source file:
#include "spi.h" void spi_init(void){ /*SPI Mode Clock Low To High*/ SSPCONbits.CKP=0; SSPSTATbits.CKE=1; SSPSTATbits.SMP=0; /*SPI Master Mode Clock = Fosc/4*/ SSPCONbits.SSPM=2; /*Turn On The Module*/ SSPCONbits.SSPEN=1; SSPSTATbits.BF=1; PORTC=0; TRISC=0; /*SPI SDI Pin Input*/ TRISC4=1; } void spi_send(uint8_t data){ SSPSTATbits.BF==1; SSPBUF=data; while(SSPSTATbits.BF==0); SSPSTATbits.BF==1; } uint8_t spi_receive(void){ uint8_t data; spi_send(0x00); data=SSPBUF; return data; }
If you wonder about using the SPI communication interface of PIC16F887 you can see this post.
See Also:
- PIC16F887 Serial Peripheral Interface Example
- PIC16F887 SPI and MCP23S17 XC8 Example
- PIC16F887 SPI MCP23S17 and Character LCD XC8 Example
- PIC16F887 SPI MCP23S17 Character LCD and KeyPad XC8 Example
- PIC16F887 SPI SN74HC165 LCD XC8 Example
Click here to download this example from GitHub.
No comments:
Post a Comment