arduino使用SPIFlash库 读写Flash芯片

SPIFlash库为Arduino平台提供华邦串行闪存芯片的支持。具备芯片识别、自动地址分配等功能,支持多种数据类型读写操作,并兼容多个ArduinoIDE版本及控制板。

SPIFlash库 – SPI华邦电子闪存Flash芯片arduino库 GITHUB 工程地址:SPIFlash

该库是用于华邦串行闪存芯片的库。目前的形式支持识别闪存芯片和它的各种功能;自动地址分配管理;在不同位置读写数据类型bytes/chars/ints/longs/floats/Strings;读写页面字节;连续读写字节/字符数组;扇区,块或整个芯片的擦除,关闭低功率操作。

支持arduino IDE 版本:

  • IDE v1.5.x
  • IDE v1.6.0-v1.6.5
  • IDE v1.6.9-v1.6.11

支持控制板:

  • Arduino Uno
  • Arduino Leonardo
  • Arduino Micro
  • Arduino Fio
  • Arduino Mega
  • Arduino Due
  • ESP8266 (On the Arduino IDE)
  • ATTiny85


示例


- Diagnostics: For a full diagnostics rundown - with error codes and details of the errors./有关完整诊断程序 - 包含错误代码和错误详细信息
- Struct_writer: This program writes a struct to a random location on your flash memory chip and reads it back./这个程序写一个struct到闪存芯片的随机位置然后读取它。
- TestFlash: The Test program show all most function./测试程序演示大部分功能函数
- getAddressEx: This program shows the method to use the getAddress() function to automate the process of address allocation when using a flash memory module. Please note the special function used to get the size of the String object./这个程序演示了使用getAddress()函数自动地址配置的过程在使用闪存模块。 请注意特殊函数使用字符串对象的大小。

- readWriteString: This program shows the method of reading a string from the console and saving it to flash memory./这个程序演示了阅读一个字符串从控制台并保存到闪存



SPIFlash

SPIFlash 函数。


- begin() – 初始化
参数:无
返回:无


- error() – 检查错误
参数:无
返回:uint8_t


- getCapacity() – 获取芯片容量
参数:无
返回:uint32_t


- getMaxPage() – 获取最大页数
参数:无
返回:uint32_t


- getChipName() – 获取芯片识别名称
参数:无
返回:uint16_t



- getManID() – 检查和启动芯片并获取16位int型制造商ID
参数:无
返回:uint16_t


- getJEDECID() – 检查和启动芯片并获取32位int型 JEDEC ID
参数:无
返回:uint32_t



– 获取下一个可用地址使用: – A.以数据的大小作为参数,并返回一个32位的地址 – B.3个参数,数据大小、页数及位置 – 所有地址的素描必须获得通过该函数或不

- getAddress(uint16_t size) – A
参数:size - 数据大小
返回:uint32_t


- getAddress(uint16_t size, uint16_t &page_number, uint8_t &offset) – B
参数:
  • size -
  • &page_number -
  • &offset -


返回:bool



- sizeofStr(String &inputStr) – 函数返回字符串的大小(仅用于getAddress()函数)
参数:inputStr - 字符串
返回:uint16_t



– 从一个页面的特定位置读一个字节的数据 – A & B

- readByte(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:uint8_t



- readByte(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:uint8_t




– 从一个页面的特定位置读一个字符的数据 – A & B

- readChar(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:int8_t



- readChar(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:int8_t




– 从一个页面的特定位置读一个字节数组的数据 – A & B

- readByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • data_buffer - 读取的数据
  • bufferSize - 读取数据大小
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:bool



- readByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • data_buffer - 读取的数据
  • bufferSize - 读取数据大小
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:bool




– 从一个页面的特定位置读一个字符数组的数据 – A & B

- readCharArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • data_buffer - 读取的数据
  • bufferSize - 读取数据大小
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:bool



- readCharArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • data_buffer - 读取的数据
  • bufferSize - 读取数据大小
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:bool




– 从一个页面的特定位置读一个无符号整型(unsigned int)数据 – A & B

- readWord(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:uint16_t



- readWord(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:uint16_t




– 从一个页面的特定位置读一个整型(int)数据 – A & B

- readShort(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:int16_t



- readShort(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:int16_t




– 从一个页面的特定位置读一个无符号长整型(unsigned long)数据 – A & B

- readULong(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:uint32_t



- readULong(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:uint32_t




– 从一个页面的特定位置读一个长整型(long)数据 – A & B

- readLong(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:int32_t



- readLong(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:int32_t




– 从一个页面的特定位置读一个浮点(float)数据 ?? – A & B

- readFloat(uint32_t address, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:float



- readFloat(uint16_t page_number, uint8_t offset, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:float




– 从一个页面的特定位置读一个字符串(string)数据 – A & B

- readStr(uint32_t address, String &outStr, bool fastRead) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • outputString –> 字符串
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:bool



- readStr(uint16_t page_number, uint8_t offset, String &outStr, bool fastRead) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • outputString –> 字符串
  • fastRead - 默认为false( 如果设置为true将执行 _beginFastRead() )


返回:bool




– 写一个字节(byte)数据到一个页面的特定位置 – A & B – 提示:写数据之前需要清除存储位置

- writeByte(uint32_t address, uint8_t data, bool errorCheck) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • data - 写入的数据(0-255)
  • errorCheck - 默认true,检查是否写入


返回:bool



- writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • data - 写入的数据(0-255)
  • errorCheck - 默认true,检查是否写入


返回:bool




– 写一个字符(char)数据到一个页面的特定位置 – A & B – 提示:写数据之前需要清除存储位置

- writeChar(uint32_t address, int8_t data, bool errorCheck) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • data - 写入的数据(0-255)
  • errorCheck - 默认true,检查是否写入


返回:bool



- writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • data - 写入的数据(0-255)
  • errorCheck - 默认true,检查是否写入


返回:bool



– 写一组字节数组数据从一个页面的特定位置 – A & B – 提示:写数据之前需要清除存储位置

- writeByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck) – A
参数:
  • address - 地址(0 - 最大存储地址)
  • data - 写入的数据(0-255)
  • errorCheck - 默认true,检查是否写入


返回:bool



- writeByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck) – B
参数:
  • page_number - 页数(0-最大页数)
  • offset - 页面中的地址(0-255)
  • data - 写入的数据(0-255)
  • errorCheck - 默认true,检查是否写入


返回:bool














评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值