728x90

Showing posts with label 25AA010A. Show all posts
Showing posts with label 25AA010A. Show all posts

Tuesday, February 24, 2026

ATMega644P and 25AA010A SPI Bus Serial EEPROM

 Overview

The Microchip Technology Inc. 25XX010A is a 1-Kbit (8-bit x 127) Serial Electrically Erasable PROM (EEPROM). The memory is accessed via a simple Serial Peripheral Interface (SPI) compatible serial bus. The bus signals required are a clock input (SCK) plus separate data in (SI) and data out (SO) lines. Access to the device is controlled through a Chip Select (CS) input. 

ATMega644P and 25AA010A SPI Bus Serial EEPROM

Since it uses the SPI interface it can handle the clock rate up to 10MHz faster than other I2C(TWI) serial EEPROM. Its read/write cycles is up to 1M times.

25AA010A | Microchip Technology 

It has various device's package including a DIP-8 package for hobbyists prototyping.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
Device Selection Table


This chip also has a model in Proteus that enable the engineer to test its operation by software.

 

PIC16F887 SPI 25AA010A EEPROM XC8 Example
Package Types and Pin Function Table

The SPI transfer and receive must have the following data bytes, instruction, address, and data.
PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.
 

PIC16F887 SPI 25AA010A EEPROM XC8 Example
Byte and Page Write Sequences
 

The Read Status Register Instruction is optional you can read the device datasheet for more detail. 

ATMega644P and 25AA010A SPI Bus Serial EEPROM It's useful the for a master MCU to determine when the next read or write operation will proceed. Some programmer just use a delay function that last around 100 micro-seconds instead of using this operation.

ATMega644 and  25AA010A Interfacing

Using a dedicated SPI interface of an MCU is very fast and reliable. The internal MCU serial communication module process this serial data transmission and reception tasks.

This example show a write and read operation to the 25AA010A from a master ATMega644P SPI. Data is written to the 25AA010A prior to reading back from this chip. Then they are shown on PORTC.

ATMega644P and 25AA010A SPI Bus Serial EEPROM
Schematic

 Source Code "main.c":

  1. /*
  2. * 12-spi_25AA010A.c
  3. *
  4. * Created: 2/24/2026 2:16:04 PM
  5. * Author : Admin
  6. */

  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9. #define F_CPU 16000000UL

  10. #define DDR_SPI DDRB
  11. #define PRT_SPI PORTB

  12. #define DD_SS 4
  13. #define DD_MOSI 5
  14. #define DD_MISO 6
  15. #define DD_SCK 7

  16. void SPI_MasterInit(void)
  17. {
  18. /* Set MOSI and SCK output, all others input */
  19. DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);
  20. /* Enable SPI, Master, set clock rate fck/16 */
  21. SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
  22. }

  23. void SPI_MasterTransmit(char cData)
  24. {
  25. /* Start transmission */
  26. SPDR = cData;
  27. /* Wait for transmission complete */
  28. while(!(SPSR & (1<<SPIF)))
  29. ;
  30. }

  31. void SPI_SlaveInit(void)
  32. {
  33. /* Set MISO output, all others input */
  34. DDR_SPI = (1<<DD_MISO);
  35. /* Enable SPI */
  36. SPCR = (1<<SPE);
  37. }
  38. char SPI_SlaveReceive(void)
  39. {
  40. /* Wait for reception complete */
  41. while(!(SPSR & (1<<SPIF)))
  42. ;
  43. /* Return Data Register */
  44. return SPDR;
  45. }

  46. // 93AA46B SPI EEPROM

  47. void write_enable(void){
  48. PRT_SPI&=~(1<<DD_SS);
  49. SPI_MasterTransmit(0x06);
  50. PRT_SPI|=(1<<DD_SS);
  51. }

  52. unsigned char read_status(void){
  53. PRT_SPI&=~(1<<DD_SS);
  54. SPI_MasterTransmit(0x05);
  55. SPI_MasterTransmit(0x00);
  56. unsigned char temp=SPI_SlaveReceive();
  57. PRT_SPI|=(1<<DD_SS);
  58. return temp;
  59. }
  60. void write_93AA46B(unsigned char address, unsigned char data){
  61. unsigned char temp;
  62. PRT_SPI&=~(1<<DD_SS);
  63. SPI_MasterTransmit(0x02);
  64. SPI_MasterTransmit(address);
  65. SPI_MasterTransmit(data);
  66. PRT_SPI|=(1<<DD_SS);
  67. //Check Write Busy Flag
  68. do
  69. {
  70. temp=read_status();
  71. } while ((temp&0x01)==1);
  72. }

  73. unsigned char read_93AA46B(unsigned char address){
  74. PRT_SPI&=~(1<<DD_SS);
  75. SPI_MasterTransmit(0x03);
  76. SPI_MasterTransmit(address);
  77. SPI_MasterTransmit(0xFF);
  78. unsigned char data=SPI_SlaveReceive();
  79. PRT_SPI|=(1<<DD_SS);
  80. return data;
  81. }
  82. int main(void)
  83. {
  84. /* Replace with your application code */
  85. SPI_MasterInit();
  86. PRT_SPI|=(1<<DD_SS);
  87. unsigned char temp=0, data=0;
  88. DDRC=0xFF;
  89. write_enable();
  90. while (1)
  91. {
  92. for (unsigned char i=0;i<8;i++)
  93. {
  94. write_93AA46B(i,1<<i);
  95. PORTC=read_93AA46B(i);
  96. _delay_ms(1000);
  97. }
  98. }
  99. }






I don't have a physical device for this chip. So I just tested it in a simulator.

Now I added a character LCD to display some ASCII data. 

ATMega644P and 25AA010A SPI Bus Serial EEPROM
Schematic

 

Source Code "main.c":

  1. /*
  2. * 25AA010A_1602.c
  3. *
  4. * Created: 2/24/2026 9:36:19 PM
  5. * Author : Admin
  6. */

  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9. #define F_CPU 16000000UL

  10. #define DDR_SPI DDRB
  11. #define PRT_SPI PORTB

  12. #define DD_SS 4
  13. #define DD_MOSI 5
  14. #define DD_MISO 6
  15. #define DD_SCK 7

  16. void SPI_MasterInit(void)
  17. {
  18. /* Set MOSI and SCK output, all others input */
  19. DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);
  20. /* Enable SPI, Master, set clock rate fck/16 */
  21. SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
  22. }

  23. void SPI_MasterTransmit(char cData)
  24. {
  25. /* Start transmission */
  26. SPDR = cData;
  27. /* Wait for transmission complete */
  28. while(!(SPSR & (1<<SPIF)))
  29. ;
  30. }

  31. void SPI_SlaveInit(void)
  32. {
  33. /* Set MISO output, all others input */
  34. DDR_SPI = (1<<DD_MISO);
  35. /* Enable SPI */
  36. SPCR = (1<<SPE);
  37. }
  38. char SPI_SlaveReceive(void)
  39. {
  40. /* Wait for reception complete */
  41. while(!(SPSR & (1<<SPIF)))
  42. ;
  43. /* Return Data Register */
  44. return SPDR;
  45. }

  46. // 93AA46B SPI EEPROM

  47. void write_enable(void){
  48. PRT_SPI&=~(1<<DD_SS);
  49. SPI_MasterTransmit(0x06);
  50. PRT_SPI|=(1<<DD_SS);
  51. }

  52. unsigned char read_status(void){
  53. PRT_SPI&=~(1<<DD_SS);
  54. SPI_MasterTransmit(0x05);
  55. SPI_MasterTransmit(0x00);
  56. unsigned char temp=SPI_SlaveReceive();
  57. PRT_SPI|=(1<<DD_SS);
  58. return temp;
  59. }
  60. void write_25AA010A(unsigned char address, unsigned char data){
  61. write_enable();
  62. unsigned char temp;
  63. PRT_SPI&=~(1<<DD_SS);
  64. SPI_MasterTransmit(0x02);
  65. SPI_MasterTransmit(address&0x7F);
  66. SPI_MasterTransmit(data);
  67. PRT_SPI|=(1<<DD_SS);
  68. //Check Write Busy Flag
  69. do
  70. {
  71. temp=read_status();
  72. } while ((temp&0x01)==1);
  73. }

  74. unsigned char read_25AA010A(unsigned char address){
  75. PRT_SPI&=~(1<<DD_SS);
  76. SPI_MasterTransmit(0x03);
  77. SPI_MasterTransmit(address&0x7F);
  78. SPI_MasterTransmit(0x00);
  79. _delay_us(100);
  80. unsigned char data=SPI_SlaveReceive();
  81. PRT_SPI|=(1<<DD_SS);
  82. return data;
  83. }

  84. int main(void)
  85. {
  86. /* Replace with your application code */
  87. SPI_MasterInit();
  88. PRT_SPI|=(1<<DD_SS);
  89. lcd_init();
  90. unsigned char temp[16]="ATMEGA644P SPI";
  91. for (unsigned char i=0;i<16;i++)
  92. {
  93. write_25AA010A(i,temp[i]);
  94. }
  95. for (unsigned char i=0;i<16;i++)
  96. {
  97. temp[i]=read_25AA010A(i);
  98. }
  99. lcd_text(temp);
  100. unsigned char temp_1[16]="25AA010A EEPROM";
  101. for (unsigned char i=16;i<32;i++)
  102. {
  103. write_25AA010A(i,temp_1[i]);
  104. }
  105. for (unsigned char i=16;i<32;i++)
  106. {
  107. temp_1[15-i]=read_25AA010A(i);
  108. }
  109. lcd_xy(1,2);
  110. lcd_text(temp_1);
  111. while (1)
  112. {
  113. }
  114. }

Click here to download this example.

 

 


 

Tuesday, February 13, 2024

PIC16F887 SPI 25AA010A EEPROM XC8 Example

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.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
Simulating Program in Proteus

It has various device's package including a DIP-8 package for hobbyists prototyping.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
Package Types and Pin Function Table

The SPI transfer and receive must have the following data bytes, instruction, address, and data.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.
 

PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.

PIC16F887 SPI 25AA010A EEPROM XC8 Example
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.

  1. /*
  2.  * File: main.c
  3.  * Author: Admin
  4.  *
  5.  * Created on February 13, 2024, 3:49 PM
  6.  */
  7.  
  8. #include <xc.h>
  9. #include "config.h"
  10. #include "LCD4Bits.h"
  11. #include "spi.h"
  12.  
  13. #define _XTAL_FREQ 8000000UL
  14.  
  15. void write_25AA010(uint8_t address, uint8_t data){
  16. /*Write Enable Command*/
  17. nCS=0;
  18. spi_send(0x06);
  19. nCS=1;
  20. /*Write Process*/
  21. nCS=0;
  22. spi_send(0x02);
  23. spi_send(address);
  24. spi_send(data);
  25. nCS=1;
  26. /*EEPROM Write Time*/
  27. __delay_ms(10);
  28. }
  29.  
  30. void write_text(uint8_t start, uint8_t *txt){
  31. uint8_t addr=0;
  32. while(*txt){
  33. write_25AA010(start+addr,*txt++);
  34. addr++;
  35. }
  36. }
  37.  
  38. uint8_t read_25AA010(uint8_t address){
  39. uint8_t data;
  40. nCS=0;
  41. spi_send(0x03);
  42. spi_send(address);
  43. data=spi_receive();
  44. nCS=1;
  45. return data;
  46. }
  47.  
  48. void main(void) {
  49. OSCCONbits.IRCF=7;
  50. lcdInit();
  51. spi_init();
  52.  
  53. uint8_t data;
  54. uint8_t txt[]="PIC16F887 24AA010A";
  55. write_text(0,txt);
  56. for(uint8_t i=0;i<sizeof(txt)-1;i++){
  57. data=read_25AA010(i);
  58. lcdData(data);
  59. }
  60.  
  61. PORTB=0;
  62. TRISB=0;
  63. ANSELH=0;
  64. while(1){
  65. for(uint8_t i=0;i<8;i++){
  66. write_25AA010(20+i,1<<i);
  67. PORTB=read_25AA010(20+i);
  68. __delay_ms(100);
  69. }
  70. __delay_ms(1000);
  71. for(int8_t i=7;i>=0;i--){
  72. write_25AA010(40-i,1<<i);
  73. PORTB=read_25AA010(40-i);
  74. __delay_ms(100);
  75. }
  76. __delay_ms(1000);
  77. }
  78. return;
  79. }
  80.  

I wrote an SPI driver that it's putted in one package.

The SPI.h header file:

  1. /*
  2.  * File: spi.h
  3.  * Author: Admin
  4.  *
  5.  * Created on February 9, 2024, 9:13 AM
  6.  */
  7.  
  8. #include <xc.h>
  9.  
  10. #define nCS RC2
  11.  
  12. void spi_init(void);
  13. void spi_send(uint8_t data);
  14. uint8_t spi_receive(void);
  15.  
  16.  

The SPI.c source file:

  1.  
  2. #include "spi.h"
  3.  
  4. void spi_init(void){
  5. /*SPI Mode Clock Low To High*/
  6. SSPCONbits.CKP=0;
  7. SSPSTATbits.CKE=1;
  8. SSPSTATbits.SMP=0;
  9. /*SPI Master Mode Clock = Fosc/4*/
  10. SSPCONbits.SSPM=2;
  11. /*Turn On The Module*/
  12. SSPCONbits.SSPEN=1;
  13. SSPSTATbits.BF=1;
  14. PORTC=0;
  15. TRISC=0;
  16. /*SPI SDI Pin Input*/
  17. TRISC4=1;
  18. }
  19.  
  20. void spi_send(uint8_t data){
  21. SSPSTATbits.BF==1;
  22. SSPBUF=data;
  23. while(SSPSTATbits.BF==0);
  24. SSPSTATbits.BF==1;
  25. }
  26.  
  27. uint8_t spi_receive(void){
  28. uint8_t data;
  29. spi_send(0x00);
  30. data=SSPBUF;
  31. return data;
  32. }

If you wonder about using the SPI communication interface of PIC16F887 you can see this post.

See Also:

  1. PIC16F887 Serial Peripheral Interface Example
  2. PIC16F887 SPI and MCP23S17 XC8 Example 
  3. PIC16F887 SPI MCP23S17 and Character LCD XC8 Example 
  4. PIC16F887 SPI MCP23S17 Character LCD and KeyPad XC8 Example 
  5. PIC16F887 SPI SN74HC165 LCD XC8 Example

Click here to download this example from GitHub.





Search This Blog

Labels

23K256 (1) 24C16B (2) 25AA010A (2) 8051 (7) 93AA46B (1) ADC (34) Analog Comparator (1) Arduino (16) ARM (13) AT89C52 (7) ATMega32 (58) ATMega644P (27) AVR (87) Bootloader (1) CCS PICC (31) Change Notify Interrupt (CNI) (2) DAC (2) DHT11 (4) Display (133) Distance Sensor (3) ds1307 (10) DS18B20 (5) ds3231 (1) ds3232 (2) dsPIC (5) dsPIC30F1010 (3) dsPIC30F2010 (5) EEPROM (5) Environment Sensor (5) ESP32 (1) esp8266 (1) Graphical LCD (2) I2C (38) ILI9341 (1) Input/Output (75) Interrupt (22) Keil (5) Keypad (16) KS0108 (2) LCD (75) LM35 (3) Master/Slave (2) MAX7221 (1) MCP23017 (8) MCP23S17 (7) MCP4921 (1) MCP4922 (2) Meter (3) MikroC (2) Motor (15) MPLABX (73) Nokia 5110 LCD (4) OLED (2) One-Wire (7) Oscillator (8) PCB (10) PCD8544 (3) PCF8574 (10) PIC (108) PIC12F (3) PIC16F628A (3) PIC16F630 (2) PIC16F716 (4) PIC16F818 (11) PIC16F818/819 (3) PIC16F84A (16) PIC16F876A (2) PIC16F877A (9) PIC16F88 (2) PIC16F887 (60) PIC18 (19) PIC18F1220 (5) PIC18F2550 (5) PIC18F4550 (12) PICKit2 (1) Pin Change Interrupt (1) PWM (12) RTC (12) SBN0064G (1) Sensor (13) SH1106 (3) Shift Register (13) Shift Registers (10) Software TWI (2) SPI (39) ST7735 (1) STM32 (11) STM32 Black Pill (1) STM32 Blue Pill (12) STM32 HAL (5) STM32CubeIDE (13) STM32F103C8T6 (9) STM32F401CCU6 (1) SysTick (4) temperature sensor (13) TFT (1) TG12864A (1) Thermometer (22) Timer/Counter (32) TM1637 (2) twi (10) UART (8) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (96)