STM32L系列单片机内部EEPROM的读写(4)
- UID
- 1029342
- 性别
- 男
|
STM32L系列单片机内部EEPROM的读写(4)
- /*------------------------------------------------------------
- Func: EEPROM数据按字写入
- Note: 字当半字用
- -------------------------------------------------------------*/
- void EEPROM_WriteWords(uint16 Addr,uint16 *Buffer,uint16 Length)
- {
- uint32 *wAddr;
- wAddr=(uint32 *)(EEPROM_BASE_ADDR+Addr);
- DIS_INT
- FLASH->PEKEYR=PEKEY1; //unlock
- FLASH->PEKEYR=PEKEY2;
while(FLASH->PECR&FLASH_PECR_PELOCK); - FLASH->PECR|=FLASH_PECR_FTDW; //not fast write
while(Length--){ - *wAddr++=*Buffer++;
while(FLASH->SR&FLASH_SR_BSY); - }
- FLASH->PECR|=FLASH_PECR_PELOCK;
- EN_INT
- }
/*------------------------------------------------------------ Func: EEPROM数据按字写入 Note: 字当半字用-------------------------------------------------------------*/void EEPROM_WriteWords(uint16 Addr,uint16 *Buffer,uint16 Length){ uint32 *wAddr; wAddr=(uint32 *)(EEPROM_BASE_ADDR+Addr); DIS_INT FLASH->PEKEYR=PEKEY1; //unlock FLASH->PEKEYR=PEKEY2; while(FLASH->PECR&FLASH_PECR_PELOCK); FLASH->PECR|=FLASH_PECR_FTDW; //not fast write while(Length--){ *wAddr++=*Buffer++; while(FLASH->SR&FLASH_SR_BSY); } FLASH->PECR|=FLASH_PECR_PELOCK; EN_INT} 以上代码中,在写入数据之前先关闭系统中断DIS_INT,写入完成之后打开系统中断EN_INT,这样避免在执行写操作的过程中被中断过程所打断,引起CPU异常或锁死,在在使用中一定要注意。在MDK环境中,两个可以这样定义:
- #define EN_INT __enable_irq(); //系统开全局中断
- #define DIS_INT __disable_irq(); //系统关全局中断
|
|
|
|
|
|