单片机FSMC配置复用模式
//FSMC初始化
//STM32F407 FSMC管脚接线信息
// *W5100S *STM32F407
// DAT0 FSMC_D0 PD14 //数据
// DAT1 FSMC_D1 PD15
// DAT2 FSMC_D2 PD0
// DAT3 FSMC_D3 PD1
// DAT4 FSMC_D4 PE7
// DAT5 FSMC_D5 PE8
// DAT6 FSMC_D6 PE9
// DAT7 FSMC_D7 PE10
// WRn FSMC_NWE PD5 //写
// RDn FSMC_NOE PD4 //读
// CSn FSMC_NE1 PD7 //片选
// M0SI_AD0 FSMC_A16 PD11 //地址线
// MISO_AD1 FSMC_A17 PD12
void FSMC_Init(void) //2018-07-17 //FSMC初始化13个引脚 D0~7 A16/17 NOE NWE NE1
{
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef Timing;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE,ENABLE);//使能PD,PE时钟
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);//使能FSMC时钟
/* Data lines configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14| GPIO_Pin_15| GPIO_Pin_0| GPIO_Pin_1;//D0 D1 D2 D3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_9| GPIO_Pin_10;//D4 D5 D6 D7
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化
/* Address lines configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11| GPIO_Pin_12;//A16 A17
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化
/* NOE and NWE configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4| GPIO_Pin_5;//NOE NWE
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始
/* NE1 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;// NE1
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC);// D0
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC);// D1
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);// D2
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);// D3
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);// D4
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC);// D5
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC);// D6
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC);// D7
GPIO_PinAFConfig(GPIOD,GPIO_PinSource11,GPIO_AF_FSMC);// A16
GPIO_PinAFConfig(GPIOD,GPIO_PinSource12,GPIO_AF_FSMC);// A17
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC);// NOE 读信号
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC);// NWE 写信号
GPIO_PinAFConfig(GPIOD,GPIO_PinSource7,GPIO_AF_FSMC);// NE1 片选
//寄存器FSMC_BTR*配置 读取时序
//寄存器FSMC_BWTR*配置 写入时序
Timing.FSMC_AddressSetupTime = 8;//10 //0~15 //地址建立时间(ADDSET)T:1个HCLK 1/168M=6ns //W5100s需要1个SYS_CLK=1/25M=40ns
Timing.FSMC_AddressHoldTime = 0; //0~15 //地址保持时间(ADDHLD)仅模式D使用
Timing.FSMC_DataSetupTime = 16; //16 //1~256 //数据建立时间为16个HCLK 6ns*16=96ns //W5100S最大需要3个SYS_CLK+5ns=125ns
Timing.FSMC_BusTurnAroundDuration = 0; //0~15 //总线周转时间
Timing.FSMC_CLKDivision = 0; //2~16 //时钟分频比
Timing.FSMC_DataLatency = 0; //2~17 //数据延迟
Timing.FSMC_AccessMode = FSMC_AccessMode_A; //模式A //位29:28 ACCMOD 模式A/B/C/D
//寄存器FSMC_BCR1
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;// 这里我们使用NE
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //位1 MUXEN 不复用数据地址
FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM; //位3:2 MTYP FSMC_MemoryType_SRAM; //存储器类型SRAM
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; //位5:4 MWID 存储器数据宽度为16bit
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable; //位8 BURSTEN 禁止突发使能位 (仅对同步突发有效)
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; //位9 WAITPOL NWAIT低电平有效(仅对突发模式有效)
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable; //位15 ASYNCWAIT异步协议时不考虑NWAIT信号
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; //位10 WRAPMOD 环回突发模式/未使能 (仅在突发模式下有效)
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;//位11 WAITCFG NWAIT在等待周期之前有效
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; //位12 WREN FSMC写使能
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; //位13 WAITEN 禁止NWAIT信号
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; //位14 EXTMOD 不考虑FSMC_BWTR(写入时序寄存),即读写使用相同时序
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //位19 CBURSTRW 在异步模式下进行写入操作
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &Timing; //读写时序 //寄存器FSMC_BTR*配置 读取时序
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &Timing; //写时序 //寄存器FSMC_BWTR*配置 写入时序
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC配置
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); // 使能BANK1
}
|