STM32F103ZET6通过FSMC挂IS62WV51216BLL SRAM。
数据宽度为FSMC_MemoryDataWidth_16b。初始化代码如下:
/*******************************************************************************
* Function Name : FSMC_SRAM_Init
*******************************************************************************/
void FSMC_SRAM_Init(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/*-- ----------------------------------- GPIO Configuration -------------------------------------------------*/
/* SRAM Data lines configuration*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
GPIO_Pin_10 | GPIO_Pin_14 |GPIO_Pin_15;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* SRAM Address lines configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 |
GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* NOE and NWE configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* NE3 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOG, &GPIO_InitStructure);
/* NBL0, NBL1 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/*-- FSMC Configuration ------------------------------------------------------*/
p.FSMC_AddressSetupTime = 0; /*ADDSET 地址建立时间*/
p.FSMC_AddressHoldTime = 0; /*ADDHOLD 地址保持时间*/
p.FSMC_DataSetupTime = 1; /*DATAST 数据建立时间*/
p.FSMC_BusTurnAroundDuration = 0; /*BUSTURN 总线返转时间*/
p.FSMC_CLKDivision = 0; /*CLKDIV 时钟分频*/
p.FSMC_DataLatency = 0; /*DATLAT 数据保持时间*/
p.FSMC_AccessMode = FSMC_AccessMode_A; /*ACCMOD FSMC 访问模式*/
/*选择设置的BANK及片选信号*/
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
/*设置是否数据地址总线分时复用(禁用)*/
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
/*设置存储器类型*/
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
/*设置数据宽度*/
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
/*设置是否使用突发访问模式(连续读写模式)*/
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
/*设定是否使用异步等待信号*/
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
/*设置WAIT信号的有效电平*/
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
/*设置是否使用环回模式*/
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
/*设置WAIT信号有效时机*/
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
/*设定是否使能写操作*/
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
/*设定是否使用WAIT信号*/
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
/*设定是否使用单独的写时序*/
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
/*设定是否使用迸发写模式*/
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
/*设定读写时序*/
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/*打开SRAM控制权 */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
}
--------------------------------------------------------------------------------------------------------------------------------------
现在用以下代码对两不同地址空间进行写操作再串口读出:
#define Bank1_SRAM3_ADDR ((uint32_t)0x68000000)
#define temp1 (*(vu8 *)(Bank1_SRAM3_ADDR+0x1000))//定义temp1变量
#define temp2 (*(vu8 *)(Bank1_SRAM3_ADDR+0x2000))//定义temp2变量
temp1=0x12; //对偏移地址1000写入0x12
USART1_Transmit(temp1 ); //串口读出0x1000地址
temp2=0x34;; //对偏移地址2000写入0x34
USART1_Transmit(temp2); //串口读出0x2000地址
这样串口输出是正确的,为0x12,0x34。但如果以上几条程序换一下位置,如下
temp1=0x12; //对偏移地址1000写入0x12
temp2=0x34;; //对偏移地址2000写入0x34
USART1_Transmit(temp1); //串口读出0x1000地址
USART1_Transmit(temp2); //串口读出0x2000地址
程序是先对两地址进行写操作,再分别输出。但输出两个不同地址里的值都是0x34,
两个地址的偏移量都不一样的,但为什么0x34会写到temp1里面去呢,求高人指点
|