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

Publisher:WhisperingWindsLatest update time:2017-09-12 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


  1. #define EP_HEADER_ADDR 0x4000  

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


  1. void EEPROM_init(void)  

  2. {  

  3.   do  

  4.   {  

  5.     FLASH_CR1=0x00;  

  6.     FLASH_CR2=0x00;  

  7.     FLASH_NCR2=0xFF;  

  8.     FLASH_DUKR = 0xAE; // Write the first key  

  9.     FLASH_DUKR = 0x56; // Write the second key  

  10.   } while((FLASH_IAPSR & 0x08) == 0); // If unlocking is unsuccessful, try again  

  11. }  

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


  1. void EEPROM_lock(void)  

  2. {  

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

  4. }  

Next are two basic operations of reading and writing.


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

  2. void EEPROM_write(unsigned char addr, unsigned char dat)  

  3. {  

  4.   unsigned char *p;  

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

  6.   *p=dat;  

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

  8. }  

  9.   

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

  11. unsigned char EEPROM_read(unsigned char addr)  

  12. {  

  13.   unsigned char *p;  

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

  15.   return *p;   

  16. }  

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:How to write the bootloader and app for IAP upgrade of stm8
Next article:stm8s development (eight) use of IIC: IIC host communication!

Recommended ReadingLatest update time:2024-11-16 14:47

stm8s development (IV) Use of CLOCK: clock control!
STM8S has a powerful clock system, which provides a high-speed 16M RC oscillator and a low-speed 128K RC oscillator. The clock controller is powerful, flexible and easy to use. Its purpose is to enable users to obtain the best performance while ensuring the lowest power consumption. Users can manage each clock source
[Microcontroller]
stm8s development (IV) Use of CLOCK: clock control!
How to run 24M HSE crystal in STM8S
Just a few steps. Step 1: Check the STM8s.h header file configuration /**   * @brief  In the following line adjust the value of External High Speed oscillator (HSE)    used in your application    Tip: To avoid modifying this file each time you need to use different HSE, you         can define the HSE value in your
[Microcontroller]
PIC12F629 EEPROM Test
/************PIC12F629 MCU program***********************************/ /*****File Function : PIC12F629 chip EEPROM test *****/ /*****Program Author : ZhengWen(ClimberWin) *****/ /*****MCU : PIC12F629 internal RC *****/ /*****Compile Date : 2010/10/02 *****/ /*****Edition Info : V1.0 *****/ /**********************
[Microcontroller]
PIC12F629 EEPROM Test
I2C bus EEPROM implementation
The development board is fl2440 board. . Running Linux 3.0 kernel The EEPROM here is just a preliminary implementation. There is no specific analysis function. It will be analyzed in detail later. 1. Modify the kernel Change make menuconfig     Device Drivers --- * I2C support ---   --- I2C support                  
[Microcontroller]
STM8S_003_TIM timing interrupt
II. Basic knowledge of TIM In the previous article, we talked about some knowledge about TIM. This article will talk about the knowledge related to TIM interrupts. TIM block diagram: TIM4 is a basic timer and an 8-bit counting timer, which means that the UP-COUNTER and Auto-reload register are 8-bit registers and
[Microcontroller]
STM8S_003_TIM timing interrupt
STM8s(3) GPIO pin function settings
// Initialization of PXn pin // Output configuration void GPIO_Init(void) {     PX_DDR |= 1 n; // 1 -- output; 0 -- input     PX_CR1 |= 1 n; // 1 -- push completed; 0 -- open drain     PX_CR2 |= 1 n; // 1 -- high speed; 0 -- low speed          PX_ODR // Output register } // Input configuration void GPIO_Init(void)
[Microcontroller]
IAR FOR STM8S debug information
Generally speaking, those who develop embedded products will reserve a UART for Debug debugging in the early stage of the product, which should be the so-called serial port debugging. But often the chip does not have so many serial ports, so some people think of using IO to simulate the serial port. In fact, this is a
[Microcontroller]
IAR FOR STM8S debug information
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号