资源简介

The Adesto® AT25SF081 is a serial interface Flash memory device designed for use in a wide variety of high-volume consumer based applications in which program code is shadowed from Flash memory into embedded or external RAM for execution

资源截图

代码片段和文件信息

#include “hal_defs.h“
#include “hal_cc8051.h“
#include “hal_mcu.h“
#include “hal_uart.h“
#include “AT25SF081.h“
#include “define.h“

#define  FLASH_CS_H        MCU_IO_OUTPUT(011)
#define  FLASH_CS_L        MCU_IO_OUTPUT(010)
#define  FLASH_MOSI_H      MCU_IO_OUTPUT(041)
#define  FLASH_MOSI_L      MCU_IO_OUTPUT(040)
#define  FLASH_SCL_H       MCU_IO_OUTPUT(051)
#define  FLASH_SCL_L       MCU_IO_OUTPUT(050)
#define  FLASH_MISO_IN     MCU_IO_INPUT(0 6MCU_IO_PULLUP)
#define  FLASH_MISO_VALUE  MCU_IO_GET(06)


#define  FLASH_WRITE_ENABLE     FLASH_CS_L;\
                                halMcuWaitUs(1);\
                                flash_spi_write(0x06);\
                                FLASH_CS_H;   
                                
#define  FLASH_WRITE_Disable    FLASH_CS_L;\
                                halMcuWaitUs(1);\
                                flash_spi_write(0x04);\
                                FLASH_CS_H;                                  
                                

uint8 id1id2id3;
uint8 flash_spi_init(){
    FLASH_CS_H;
    FLASH_MISO_IN;
    FLASH_MOSI_L;
    FLASH_SCL_L;
    ReadID(&id1&id2&id3);
    if(id1==0x1F&&id2==0x85&&id3==0x01)
        return 1;
    return 0;
}
//MSB
void flash_spi_write(uint8 value){
    uint8 i;
    for(i=0;i<8;i++){
        FLASH_SCL_L;
        if((value<            FLASH_MOSI_H;
        }else{
            FLASH_MOSI_L;
        }
        halMcuWaitUs(1);
        FLASH_SCL_H;
        halMcuWaitUs(1);
    }
}
//MSB
uint8 flash_spi_read(){
    uint8 ivalue=0;
    for(i=0;i<8;i++){
        FLASH_SCL_L;
        halMcuWaitUs(1);
        if(FLASH_MISO_VALUE){
            value|=1<<(7-i);
        }else{
            value|=0<<(7-i);
        }
        FLASH_SCL_H;
        halMcuWaitUs(1);
    }
    return value;
}

void ReadID(uint8 *id1 uint8 *id2uint8 *id3)
{
    FLASH_SCL_H;
    FLASH_CS_L;
    halMcuWaitUs(1);
    flash_spi_write(0x9F);  // 读ID的指令
    flash_spi_write(0x00);  
    flash_spi_write(0x00);
    flash_spi_write(0x00);
    *id1 = flash_spi_read();
    *id2 = flash_spi_read();
    *id3 = flash_spi_read();
    FLASH_CS_H;
}

//从任意内存地址写入(地址范围0x000000-0xFFFFFF)每一块的长度为256字节,写入长度不能超过写入地址的地址块长度
uint8 flashWriteDatas(uint32 addr uint8 *pdata uint16 len){
    uint16 i;
    uint32 addr_16 addr_8 addr_0;
    addr_16 = addr/65536;
    addr_8 = addr/256;
    addr_0 = addr%256;
    if(len == 0 || addr_0+len > 256)
        return 0;
    FLASH_WRITE_ENABLE;
    FLASH_SCL_H;
    FLASH_CS_L;
    halMcuWaitUs(1);
    flash_spi_write(0x02);  // 写数据的指令
    flash_spi_write((addr_16)&0xFF);  // 24位写入的地址
    flash_spi_write((addr_8)&0xFF);  // 24位写入的地址
    flash_spi_write((addr_0));  // 24位写入的地址   

    for(i=0; i    {
        flash_spi_write(pdata[i]);
    }
    FLASH_CS_H;
    WaiteNotBusy();
    return len;
}

uint8 flashReadDatas(uint32 addr uint8

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4375  2018-12-05 18:08  AT25SF081\AT25SF081.c

     文件        374  2018-12-05 18:02  AT25SF081\AT25SF081.h

     文件    3427016  2018-12-05 14:25  AT25SF081\DS-AT25SF081_045.pdf

     文件          0  2018-12-05 18:20  AT25SF081\新建文本文档.txt

     目录          0  2018-12-05 18:20  AT25SF081

----------- ---------  ---------- -----  ----

              3431765                    5


评论

共有 条评论