STM32單片機(jī)用FSMC接口控制SRAM
環(huán)境:
主機(jī):WIN7
開發(fā)環(huán)境:MDK4.72
MCU:STM32F103ZE
說明:
sram型號:IS62WV51216BLL
連接方式:FSMC
大小:1M字節(jié).512K * 16
源代碼:
inf_sram.h
/*********************************************************************
*sram接口層頭文件
*(c)copyright2013,jdh
*AllRightReserved
*文件名:inf_sram.h
*程序員:jdh
*修改日期:2013/10/10
*2013/10/11
**********************************************************************/
/*********************************************************************
*說明
*sram型號:IS62WV51216BLL
*連接方式:FSMC
*大小:1M字節(jié).512K*16
**********************************************************************/
#ifndef_INF_SRAM_H_
#define_INF_SRAM_H_
/*********************************************************************
*頭文件
**********************************************************************/
#include"stm32f10x.h"
#include"stm32f10x_fsmc.h"
/*********************************************************************
*宏定義
**********************************************************************/
/*********************************************************************
*SRAM2的BANK1起始地址
**********************************************************************/
#defineBank1_SRAM2_ADDR((uint32_t)0x64000000)
/*********************************************************************
*函數(shù)
**********************************************************************/
/*********************************************************************
*初始化sram
**********************************************************************/
voidinf_init_sram(void);
/*********************************************************************
*寫入數(shù)據(jù)包
*輸入:pBuffer:數(shù)據(jù)指針
*WriteAddr:寫入數(shù)據(jù)地址
*NumHalfwordToWrite:數(shù)據(jù)長度
*返回:無
**********************************************************************/
voidFSMC_SRAM_WriteBuffer(uint16_t*pBuffer,uint32_tWriteAddr,uint32_tNumHalfwordToWrite);
/*********************************************************************
*讀取數(shù)據(jù)包
*輸入:pBuffer:存放數(shù)據(jù)的指針
*ReadAddr:讀取數(shù)據(jù)地址
*NumHalfwordToRead:讀取數(shù)據(jù)長度,單位半字,即2字節(jié)
*返回:無
**********************************************************************/
voidFSMC_SRAM_ReadBuffer(uint16_t*pBuffer,uint32_tReadAddr,uint32_tNumHalfwordToRead);
/*********************************************************************
*寫入半字?jǐn)?shù)據(jù)
*輸入:WriteAddr:寫入數(shù)據(jù)地址
*data:數(shù)據(jù)
*返回:無
**********************************************************************/
voidFSMC_SRAM_WriteHalfWord(uint32_tWriteAddr,uint16_tdata);
/*********************************************************************
*讀取半字?jǐn)?shù)據(jù)
*輸入:ReadAddr:讀取數(shù)據(jù)地址
*返回:讀取的數(shù)據(jù)
**********************************************************************/
uint16_tFSMC_SRAM_ReadHalfWord(uint32_tReadAddr);
#endif
inf_sram.c
/*********************************************************************
*sram接口層頭文件
*(c)copyright2013,jdh
*AllRightReserved
*文件名:inf_sram.c
*程序員:jdh
*修改日期:2013/10/10
*2013/10/11
**********************************************************************/
/*********************************************************************
*說明
*sram型號:IS62WV51216BLL
*連接方式:FSMC
*大小:1M字節(jié).512K*16
**********************************************************************/
/*********************************************************************
*頭文件
**********************************************************************/
#include"inf_sram.h"
/*********************************************************************
*函數(shù)
**********************************************************************/
/*********************************************************************
*初始化sram
**********************************************************************/
voidinf_init_sram(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
FSMC_NORSRAMTimingInitTypeDefp;
FSMC_NORSRAMInitTypeDefFSMC_NORSRAMInitStructure;
//開啟FSMC時鐘
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);
//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC|RCC_AHBPeriph_SRAM,ENABLE);
//開啟FSMC相關(guān)的IO時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|
RCC_APB2Periph_GPIOF|RCC_APB2Periph_GPIOG|
RCC_APB2Periph_AFIO,ENABLE);
//FSMC相關(guān)的IO配置