资源简介

stm32 spi方式读写EEPROM,有c源码。完成对at25128芯片的基本配置,实现对at25128的单字节的读和写以及多字节的读写。

资源截图

代码片段和文件信息

/***************************************** (C) COPYRIGHT 2014 Lianfly ************************************************
* FileName : EEPROM.c
* Author : G. 
* Version : V1.01
* Date : 2015/10/11
* Description     : 永久保存数据
**********************************************************************************************************************/
#include “includes.h“

//=====================================================================================================================
// 函数名称 : SPI_FLASH_SendByte()
// 函数功能 : Sends a byte through the SPI interface and return the byte 
// 输    入 : 无
// 输    出 : 无
// 返    回 : 无
//=====================================================================================================================
u8 SPI2_FLASH_SendByte(u8 byte)
{
while(SPI_I2S_GetFlagStatus(SPI2 SPI_I2S_FLAG_TXE) == RESET);   // Loop while DR register in not emplty 
SPI_I2S_SendData(SPI2 byte);   // Send byte through the SPI1 peripheral 
while(SPI_I2S_GetFlagStatus(SPI2 SPI_I2S_FLAG_RXNE) == RESET);  // Wait to receive a byte 
return SPI_I2S_ReceiveData(SPI2);  // Return the byte read from the SPI bus 
}

//=====================================================================================================================
// 函数名称 : SPI_FLASH_WaitForWriteEnd()
// 函数功能 : 
// 输    入 : 无
// 输    出 : 无
// 返    回 : 无
//=====================================================================================================================
void SPI_FLASH_WaitForWriteEnd(void)
{
u8 FLASH_Status = 0;
SPI_FLASH_CS_LOW();   // Select the FLASH: Chip Select low 
SPI2_FLASH_SendByte(RDSR);   // Send “Read Status Register“ instruction 
do
{
FLASH_Status = SPI2_FLASH_SendByte(Dummy_Byte);
} while((FLASH_Status & WIP_Flag) == SET);  // Write in progress 
SPI_FLASH_CS_HIGH();  // Deselect the FLASH: Chip Select high 
}

//=====================================================================================================================
// 函数名称 : SPI_FLASH_WriteEnable()
// 函数功能 : Enables the write access to the FLASH.
// 输    入 : 无
// 输    出 : 无
// 返    回 : 无
//=====================================================================================================================
void SPI_FLASH_WriteEnable(void)
{
SPI_FLASH_CS_LOW();  // Select the FLASH: Chip Select low 
SPI2_FLASH_SendByte(0x06);   // Send “Write Enable“ instruction 
SPI_FLASH_CS_HIGH();  // Deselect the FLASH: Chip Select high 
}
//=====================================================================================================================
// 函数名称 : SPI2_FLASH_ReadByte()
// 函数功能 : Reads a byte from the SPI Flash.
// 输    入 : 无
// 输    出 : 无
// 返    回 : 无
//========================================

评论

共有 条评论