【Blue Bridge Cup MCU】AT2C02 EEPROM

Publisher:数字火花Latest update time:2020-07-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is also the iic bus structure!


Here is a summary of the program structure of iic


Read and write operations in the same function (taking reading eeprom as an example)


(1) Open the bus


(2) Write address word and wait for response (write command)


(3) Write the address to be read and wait for a response


(4) Turn on the bus again


(5) Write address word and wait for response (read command)


(6) Read the address you want to read


(7) Send a response


(8) End the bus


Put the code:


unsigned char read_eeprom(unsigned char add)

{

unsigned char dat;

IIC_Start(); //(1)Start the bus

IIC_SendByte(SlaveAddrW); //(2)Write address word, wait for response (write command)

IIC_WaitAck();

IIC_SendByte(add); //(3)Write the address to be read and wait for response

IIC_WaitAck();

 

IIC_Start(); //(4)Start the bus again

IIC_SendByte(SlaveAddrR); //(5)Write address word, wait for response (read command)

IIC_WaitAck();

dat = IIC_RecByte(); //(6)Read the address to be read

IIC_Ack(0); //(7)Send a response

IIC_Stop(); //(8)End the bus

return dat;

 

}





The process of writing eeprom is the same as PCF8591

void write_eeprom(unsigned char add,unsigned char dat)

{

IIC_Start();

IIC_SendByte(SlaveAddrW); //Address word

IIC_WaitAck();

IIC_SendByte(add); //Transmit the address to be written

IIC_WaitAck();

IIC_SendByte(dat); //Number to be written

IIC_WaitAck();

IIC_Stop(); //End

somedelay(10); // appropriate delay

}


Now let's summarize the pitfalls in the I2C official driver:


(1) The delay needs to be changed to 33 nops


(2) After reading the data, the host sends a response of ack(0)

Reference address:【Blue Bridge Cup MCU】AT2C02 EEPROM

Previous article:[Bluebridge Cup MCU Group] PCF8591 Complaints about Bluebridge Cup's I2C
Next article:【Blue Bridge Cup MCU Group】(3)Keyboard

Recommended ReadingLatest update time:2024-11-16 22:34

STC C51 MCU EEPROM
   1.   STC series microcontrollers all have built-in EEPROM units, and the operation mode of the EEPROM unit is similar to that of NOR FLASH, with the Sector unit for erasing and writing. At the same time, when rewriting the Flash data, the internal EEPROM data is not affected. This is different from the EEPROM operat
[Microcontroller]
51 MCU——EEPROM
24C02: 256-byte EEPROM. Generally, EEPROM has a lifespan of 300,000 to 1 million times. Devices based on the I2C communication protocol. I2C is a communication protocol with strict communication timing logic requirements, while EEPROM is a device that only samples the interface of the I2C protocol and is connected to
[Microcontroller]
AVR EEPROM Experiment
System functions   Write data to the EEPROM inside the AVR, then read the data from the EEPROM, use LED to indicate, and observe whether the read data is consistent with the written data.   hardware design     AVR main control circuit schematic diagram   LED control circuit schematic diagram  
[Microcontroller]
AVR EEPROM Experiment
AT93C46/56/55 Serial EEPROM and MCU Program
16-bit single-chip microcomputers have occupied a certain market in the field of industrial control due to their advantages such as being suitable for high-speed control occasions and having multiple functions. Since EEPROM can modify the contents of its storage unit without leaving the system, its application in 16
[Microcontroller]
AT93C46/56/55 Serial EEPROM and MCU Program
Reading and writing of EEPROM inside STM32 microcontroller
The STM32L series MCU provides an EEPROM storage area, but in fact, its FLASH is also an EEPROM type, but there is an area that is opened up for EEPROM operation. The STM32L EEPROM service life is designed to be more than 100,000 erase and write times, and the capacity is 2K-4K, which is ideal for parameter storage of
[Microcontroller]
ATMEGA16 drives internal EEPROM program
// 8MHZ crystal running on ATMEGA16 // Display effect: Display the number set by the button #include iom16v.h #include macros.h #define uchar unsigned char #define uint unsigned int #pragma data:code             const uchar table ="I LIKE AVR !"; const uchar table1 ="WWW*FUMANCHE*COM"; const uchar table_num
[Microcontroller]
The road to learning MCU for beginners (Twenty-six) --- Understanding EEPROM-IIC bus (I)
Objective: Understanding EEPROM-IIC bus (I) 1. Introduction to IIC bus IIC (Inter-Integrated Circuit) bus is a two-wire serial bus developed by PHILIPS, which is used to connect microcontrollers and their peripherals. It is a bus standard widely used in the field of microelectronic communication control. It is a spe
[Microcontroller]
The road to learning MCU for beginners (Twenty-six) --- Understanding EEPROM-IIC bus (I)
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号