網(wǎng)絡消費網(wǎng) >  5G > > 正文
stm32驅(qū)動SST25VF程序
時間:2021-12-13 18:22:03
SST25VF.h:#include "stm32f10x_lib.h"#ifndef __SST25V_H#define __SST25V_H#define BufferSize (countof(Tx_Buffer)-1)#define countof(a) (sizeof(a) / sizeof(*(a)))#define SST25V_PageSize 256#define Dummy_Byte 0xA5#define SST25V_CS_LOW() GPIO_ResetBits(GPIOA, GPIO_Pin_4)#define SST25V_CS_HIGH() GPIO_SetBits(GPIOA, GPIO_Pin_4)#define SST25V_WP_LOW() GPIO_ResetBits(GPIOC, GPIO_Pin_0)#define SST25V_WP_HIGH() GPIO_SetBits(GPIOC, GPIO_Pin_0)#define SST25V_HOLD_LOW() GPIO_ResetBits(GPIOC, GPIO_Pin_1)#define SST25V_HOLD_HIGH() GPIO_SetBits(GPIOC, GPIO_Pin_1)#define Read_Data 0x03 //讀取存儲器數(shù)據(jù)#define HighSpeedReadData 0x0B //快速讀取存儲器數(shù)據(jù)#define SectorErace_4KB 0x20 //扇區(qū)擦除#define BlockErace_32KB 0x52 //32KB塊擦除#define BlockErace_64KB 0xD8 //64KB塊擦除#define ChipErace 0xC7 //片擦除#define Byte_Program 0x02 //頁面編程--寫數(shù)據(jù)#define AAI_WordProgram 0xAD#define ReadStatusRegister 0x05 //讀狀態(tài)寄存器#define EnableWriteStatusRegister 0x50#define WriteStatusRegister 0x01 //寫狀態(tài)寄存器#define WriteEnable 0x06 //寫使能,設(shè)置狀態(tài)寄存器#define WriteDisable 0x04 //寫禁止#define ReadDeviceID 0xAB //獲取設(shè)備ID信息#define ReadJedec_ID 0x9F //JEDEC的ID信息#define EBSY 0X70 //允許AAI模式期間,SO腳輸出忙狀態(tài)命令#define DBSY 0X80 //禁止AAI模式期間,SO腳輸出忙狀態(tài)命令void SST25V_Init(void); //Flash芯片初始化u8 SST25V_ByteRead(u32 ReadAddr); //從ReadAddr地址讀取一個字節(jié)數(shù)據(jù)void SST25V_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead); //從ReadAddr地址開始讀取NumByteToRead個字節(jié)數(shù)據(jù)u8 SST25V_HighSpeedByteRead(u32 ReadAddr); //從ReadAddr高速讀取一個字節(jié)數(shù)據(jù)void SST25V_HighSpeedBufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead);//從ReadAddr開始高速讀取NumByteToRead個字節(jié)數(shù)據(jù),并存儲于pBuffer中u8 SPI_Flash_SendByte(u8 byte); //SPI發(fā)送數(shù)據(jù)u8 SPI_Flash_ReceiveByte(void); //SPI接收數(shù)據(jù)void SST25V_ByteWrite(u8 Byte, u32 WriteAddr); //寫入一個數(shù)據(jù)字節(jié)void SST25V_BufferWrite(u8 *pBuffer,u32 Addr,u16 BufferLength);//將pBuffer中的BufferLength個字節(jié)數(shù)據(jù)寫入到以Addr為起始地址的區(qū)域void SST25V_WriteBytes(u8 Byte, u32 WriteAddr,u32 ByteLength); //以WriteAddr為起始地址,寫入ByteLength個數(shù)據(jù)Byte(寫入的是同一個數(shù)據(jù)Byte)void SST25V_AAI_WriteBytes(u8 Byte, u32 Addr,u32 ByteLength); //以Addr為起始地址,用AAI模式,寫入ByteLength個數(shù)據(jù)Byte(寫入的是同一個數(shù)據(jù)Byte)ByteLength必須為偶數(shù)void SST25V_AAI_BufferProgram(u8 *pBuffer,u32 Addr,u16 BufferLength); //用AAI模式將pBuffer中的BufferLength個字節(jié)數(shù)據(jù)寫入到以Addr為起始地址的區(qū)域,ByteLength必須為偶數(shù)void SST25V_AAI_WordProgram(u8 Byte1, u8 Byte2, u32 Addr); //在AAI模式下,以Addr為起始地址,分別寫入Byte1和Byte2,必須和SST25V_AAI_WordsProgram()函數(shù)配套使用void SST25V_AAI_WordsProgram(u8 state,u8 Byte1, u8 Byte2); //在AAI模式下,繼續(xù)寫入Byte1和Byte2,必須和SST25V_AAI_WordProgram()函數(shù)配套使用,state==1退出AAI模式void SST25V_SectorErase_4KByte(u32 Addr); //擦除4KB數(shù)據(jù)空間,Addr是擦除起始地址void SST25V_BlockErase_32KByte(u32 Addr); //擦除32KB數(shù)據(jù)空間,Addr是擦除起始地址void SST25V_BlockErase_64KByte(u32 Addr); //擦除64KB數(shù)據(jù)空間,Addr是擦除起始地址void SST25V_ChipErase(void); //擦除整個芯片數(shù)據(jù)空間u8 SST25V_ReadStatusRegister(void); //讀取狀態(tài)寄存器void SST25V_WriteEnable(void); //允許對芯片寫入操作void SST25V_WriteDisable(void); //禁止對芯片寫入操作void SST25V_EnableWriteStatusRegister(void); //允許改寫狀態(tài)寄存器void SST25V_WriteStatusRegister(u8 Byte); //改寫狀態(tài)寄存器,向狀態(tài)寄存器寫入數(shù)據(jù)Bytevoid SST25V_WaitForWriteEnd(void); //等待寫入操作完成u32 SST25V_ReadJedecID(void); //讀取JEDEC IDu16 SST25V_ReadManuID_DeviceID(u32 ReadManu_DeviceID_Addr); //讀取ManufacturerID和DeviceID,ReadManu_DeviceID_Addr的狀態(tài)決定第一個字節(jié)是DeviceID還是ManufacturerIDvoid SST25V_EBSY(); //允許AAI模式期間,SO腳輸出忙狀態(tài)void SST25V_DBSY(); //禁止AAI模式期間,SO腳輸出忙狀態(tài)#endifhw_conf.c:#include"stm32f10x_lib.h"#include "hw_conf.h"ErrorStatus HSEStartUpStatus;void RCC_Configuration(void){RCC_DeInit();RCC_HSEConfig(RCC_HSE_ON);HSEStartUpStatus = RCC_WaitForHSEStartUp();if(HSEStartUpStatus == SUCCESS){FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);FLASH_SetLatency(FLASH_Latency_2);RCC_HCLKConfig(RCC_SYSCLK_Div1);RCC_PCLK2Config(RCC_HCLK_Div1);RCC_PCLK1Config(RCC_HCLK_Div2);RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);RCC_PLLCmd(ENABLE);while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){}RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);while(RCC_GetSYSCLKSource() != 0x08){}}RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);}void GPIO_Configuration(void){//PC4567分別接LED4,3,2,1,以便調(diào)試觀察GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);//PA5--SPI1_SCK PA6--SPI1--MISO PA7--SPI1--MOSIGPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; //Configure SPI1 pins: NSS, SCK, MISO and MOSIGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);//PA4--SPI1_NSSGPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //Configure PA.4 as Output push-pull, used as Flash Chip selectGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);}void SPI_configuration() //SPI1 configuration{SPI_InitTypeDef SPI_InitStructure;SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //SPI設(shè)置為雙線雙向全雙工SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //設(shè)置為主 SPI SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //SPI發(fā)送接收 8 位幀結(jié)構(gòu)SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //時鐘懸空高SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //數(shù)據(jù)捕獲于第二個時鐘沿SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //內(nèi)部 NSS 信號有 SSI位控制SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //波特率預分頻值為 4SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //數(shù)據(jù)傳輸從 MSB 位開始SPI_InitStructure.SPI_CRCPolynomial = 7; //定義了用于 CRC值計算的多項式 7SPI_Init(SPI1, &SPI_InitStructure);SPI_Cmd(SPI1, ENABLE); //Enable SPI1}void NVIC_Configuration(void){#ifdef VECT_TAB_RAM NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);#elseNVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif}void Setup_System(void){RCC_Configuration();GPIO_Configuration();SPI_configuration();NVIC_Configuration();}hw_conf.h:#ifndef _hw_conf_H_#define _hw_conf_H_extern void Setup_System(void);#endif

關(guān)鍵詞: stm32SST25V

版權(quán)聲明:
    凡注明來網(wǎng)絡消費網(wǎng)的作品,版權(quán)均屬網(wǎng)絡消費網(wǎng)所有,未經(jīng)授權(quán)不得轉(zhuǎn)載、摘編或利用其它方式使用上述作品。已經(jīng)本網(wǎng)授權(quán)使用作品的,應在授權(quán)范圍內(nèi)使用,并注明"來源:網(wǎng)絡消費網(wǎng)"。違反上述聲明者,本網(wǎng)將追究其相關(guān)法律責任。
    除來源署名為網(wǎng)絡消費網(wǎng)稿件外,其他所轉(zhuǎn)載內(nèi)容之原創(chuàng)性、真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考并自行核實。
熱文

網(wǎng)站首頁 |網(wǎng)站簡介 | 關(guān)于我們 | 廣告業(yè)務 | 投稿信箱
 

Copyright © 2000-2020 m.netfop.cn All Rights Reserved.
 

中國網(wǎng)絡消費網(wǎng) 版權(quán)所有 未經(jīng)書面授權(quán) 不得復制或建立鏡像
 

聯(lián)系郵箱:920 891 263@qq.com

備案號:京ICP備2022016840號-15

營業(yè)執(zhí)照公示信息