NXP

LPC4088片内EEPROM使用方法

2019-07-12 12:11发布

1.写在前面   LPC4088是NXP出的Cortex M4内核MCU,带硬件浮点运算,主频高达120MHz。其中一个优势是片内集成4KB EEPROM,省去外挂EERPOM的成本。 2.使用片内EEPROM   NXP亦提供了类似ST的硬件库,但没有ST做得人性化,但我们也可以直接使用其硬件库,省去配置寄存器的琐碎。使用片内EEPROM,与之相关的是“lpc_eeprom.c”原文件。

2.1 写EEPROM   NXP硬件库提供的写函数为: void EEPROM_Write(uint16_t page_offset, uint16_t page_address, void* data, EEPROM_Mode_Type mode, uint32_t count) 封装为常用的函数接口: void WriteToEeprom(short Addr,char *Buff,short Size) { short Pageaddr,Offsetaddr,Remainsize,Writesize; short WritedataAddr; Pageaddr = Addr / 64; /*页地址*/ Offsetaddr = Addr % 64; /*页偏移地址*/ Remainsize = Size; WritedataAddr = 0; EEPROM_PowerDown(DISABLE); /*开启使能*/ while(Remainsize > 0) { if((Offsetaddr + Remainsize) > 64) Writesize = 64 - Offsetaddr; else Writesize = Remainsize; EEPROM_Write(Offsetaddr,Pageaddr, &Buff[WritedataAddr], MODE_8_BIT, Writesize); WritedataAddr += Writesize; Offsetaddr = 0; Pageaddr += 1; Remainsize -=Writesize; } EEPROM_PowerDown(ENABLE); }
2.2 读EEPROM   NXP硬件库提供的读函数为: void EEPROM_Read(uint16_t page_offset, uint16_t page_address, void* data, EEPROM_Mode_Type mode, uint32_t count) 封装为常用的函数接口: void ReadFromEeprom(short Addr,char *Buff,short Size) { short Pageaddr,Offsetaddr,Remainsize,Readsize; short ReaddataAddr; Pageaddr = Addr / 64; /*页地址*/ Offsetaddr = Addr % 64; /*页偏移地址*/ Remainsize = Size; ReaddataAddr = 0; EEPROM_PowerDown(DISABLE); /*开启使能*/ while(Remainsize > 0) { if((Offsetaddr + Remainsize) > 64) Readsize = 64 - Offsetaddr; else Readsize = Remainsize; EEPROM_Read(Offsetaddr,Pageaddr, &Buff[ReaddataAddr], MODE_8_BIT, Readsize); ReaddataAddr += Readsize; Offsetaddr = 0; Pageaddr += 1; Remainsize -=Readsize; } EEPROM_PowerDown(ENABLE); }