stm8s development (nine) use of EEPROM: use EEPROM to store data!

Publisher:MysticSerenadeLatest update time:2020-09-01 Source: eefocusKeywords:stm8s  EEPROM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  EEPROM is a memory often used in microcontroller application systems. It is mainly used to save some data that needs to remain unchanged after power failure. In previous microcontroller systems, an EEPROM chip was usually added outside the microcontroller. This method not only increases costs, but also reduces reliability. Now, many microcontroller companies have launched microcontrollers with integrated small-capacity EEPROM, which is convenient to use, reduces costs, and improves reliability.


  The STM8 microcontroller chip also integrates EEPROM, with a capacity ranging from 640 bytes to 2K bytes. The most unique feature is that in the STM8 microcontroller, access to the EEPROM is just like regular RAM, which is very convenient. The address space of the EEPROM is uniformly addressed with the memory, starting from 004000H, and the size depends on the different chip models.


  For ease of management, define the address of the EEPROM

  #define EP_HEADER_ADDR 0x4000

  Operating the EEPROM requires initialization, which is FLASH unlocking. Unlocking requires two keys, and the order cannot be reversed.

  void EEPROM_init(void)

  {

  do

  {

  FLASH_CR1=0x00;

  FLASH_CR2=0x00;

  FLASH_NCR2=0xFF;

  FLASH_DUKR = 0xAE; // Write the first key

  FLASH_DUKR = 0x56; // Write the second key

  } while((FLASH_IAPSR & 0x08) == 0); // If unlocking fails, try again

  }


  There is also a locking function. Generally speaking, lock protection is required after operating the EEPROM.

  void EEPROM_lock(void)

  {

  FLASH_IAPSR=(u8)(~0x08); //Relock

  }


  Next are two basic operations of reading and writing.

  //Write a data to the specified address of EEPROM addr: relative address dat: data

  void EEPROM_write(unsigned char addr, unsigned char dat)

  {

  unsigned char *p;

  p=(unsigned char *)(EP_HEADER_ADDR + addr);

  *p=dat;

  while(!(FLASH_IAPSR&0x04)); //Wait for write operation to succeed

  }

  //Read a data from the specified address of EEPROM addr: relative address

  unsigned char EEPROM_read(unsigned char addr)

  {

  unsigned char *p;

  p=(unsigned char *)(EP_HEADER_ADDR + addr);

  return *p;

  }


  The address given here is an absolute address. There is an offset address operation in the function (offset 4000H).

  Fried chicken is simple, isn’t it?


  Introduction to EEPROM and FLASH: http://blog.csdn.net/yuanlulu/article/details/6163106

  Attached is the project of stm8s in IAR environment, including the initialization code of on-chip hardware such as SPI, IIC, PWM, AWU, USART, EEPROM, etc.

  http://download.csdn.NET/detail/devintt/9454188

Keywords:stm8s  EEPROM Reference address:stm8s development (nine) use of EEPROM: use EEPROM to store data!

Previous article:STM8-Use the timing function of TIM2 to make the light flash every 1S
Next article:Using STM8's PWM input to capture and measure infrared code program

Recommended ReadingLatest update time:2024-11-23 15:24

Summary of the process of reading and writing EEPROM using I2C in STM32
Configure I/O ports, configure mode, enable GPIO and clock Write: Check if SDA is idle. Checks whether the event was successful. Send a start signal according to the protocol Checks whether the event was successful. Issues the 7-bit device address and write mode. Checks whether the event was successful. The first ad
[Microcontroller]
Fudan Microelectronics Launches Low-Power Ultra-Wide Voltage I2C Serial EEPROM
May 12, 2022, Shanghai - Shanghai Fudan Microelectronics Group Co., Ltd. Recently launched the low-power and ultra-wide voltage FM24LNXXX series I2C serial EEPROM memory, which can meet the application needs of CCM, white goods, electric meter instruments, 5G communications, automotive and other related appl
[Embedded]
STM8S input capture learning
PWM input signal measurement This mode is a special case of input capture mode and operates the same as input capture mode except for the following differences:               Both ICi signals are mapped to the same TIi input.               The active edges of the two ICi signals have opposite polarities.        
[Microcontroller]
STM8S input capture learning
DS28E05 1-Wire EEPROM
The DS28E05 is a 112-byte user-programmable EEPROM. Memory pages can be individually protected from write or EPROM emulation mode by setting the protection byte. Each page has its own unique 64-bit ROM identification number (ROM ID) programmed into the chip at the factory. The DS28E05 communicates with Maxim's integra
[Analog Electronics]
DS28E05 1-Wire EEPROM
STC8G series storage structure RAM FLASH EEPROM
7 Memory 1. Data storage - RAM Internal RAM Internal extended RAM External expansion RAM 2. Program storage - ROM 3. EEPROM RAM is used to store the intermediate results and process data of program execution (the data disappears after p
[Microcontroller]
STC8G series storage structure RAM FLASH EEPROM
STM8S external interrupt attention
Because there is no interrupt clearing flag, this is different from other microcontrollers. The setting of the trigger edge of EXTI_CR1 can only be written when the general interrupt is not enabled! PD7 is the highest priority non-maskable hardware interrupt (TLI)  Setting order: It is best to turn off the interrupt f
[Microcontroller]
About IIC EEPROM page write loss data problem
No matter which address you write from, it cannot exceed (cross) a whole page. First understand the principle of page writing. In order to improve writing efficiency, the AT24CXX series EEPROM provides a page write function. There is a one-page write buffer RAM inside. The address range is of course from 00 to one pag
[Microcontroller]
STM8S AWU low power mode
/**   ********************************** STM8S *************** ********************   * @file name: bsp_awu.c   * @Author: strongerHuang   * @Library version: V2.2.0   * @File version: V1.0.0   * @Date: May 10, 2017   * @Summary: Automatic wakeup source file   *********************************************************
[Microcontroller]
Latest Microcontroller Articles
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号