以前使用51的时候可以定义外部接口地址,方便已寻址的方式访问外部器件,在STM32中,FSMC功能类似,方便搭载多种外部芯片,如使用FSMC模拟8080并口,interl模式并口等。
FSMC工作模式较多,以复用模式为例来说明:
复用模式可以很方便模拟8080并口,以及驱动Intel模式并口器件,配置好引脚后,需要根据驱动芯片手册确定读写时序,如果时序太大或太小,都会导致读写数据不正确。
以下是100pin STM32F103MCU FSMC初始化程序:
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef pr;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);//使能FSMC时钟 必须
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);//使能引脚时钟,并使能复用功能时钟
//PORT 初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_14|GPIO_Pin_15; /
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//PORT 初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10; //
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
pr.FSMC_AddressSetupTime = 5; //(+1)*27ns
pr.FSMC_AddressHoldTime = 2;
pr.FSMC_DataSetupTime = 5; //(+1)*27ns
pr.FSMC_BusTurnAroundDuration = 3;
pr.FSMC_AccessMode = FSMC_AccessMode_A; //此处有疑问
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;//复用功能开启
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; //复用模式必须为使能
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = ≺
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = ≺
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); //
在复用模式时,如果不选定FSMC_AccessMode_A\B\C\D中的一种,会导致FSMC无法工作,原因未明
该配置程序基本能够满足FSMC模拟8080并口,