本帖最后由 george3023 于 2019-5-24 17:33 编辑
大家好,我最近在用STM32F407做一个Profibus-DP从站卡,一方面STM32F407通过FSMC跟西门子DP从站协议芯片SPC3LV之间交互数据,得到DP主站(eg:PLC)的指令,同时反馈状态给DP主站,另一方面STM32F407通过SCI跟变频器交互数据,传达DP主站指令,同时收集变频器状态反馈,DP从站卡相当于一个网关负责Profibus-DP跟MODBUS协议的转换。
现在碰到的问题是主循环执行写数据指令(*(volatile unsigned short int *)(0x60000AAA)=0xABCD;)FSMC_NOE跟FSMC_NWE以及数据端口通过示波器测量都能检测到信号,NADV(SPC_NL,对应SPC3的ALE)一直检测不到信号,不知道是什么原因,请大家帮忙分析一下,谢谢。
我的硬件资源配置如下:
我的软件配置如下:
void FSMC_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(
/*控制信号*/
SPC3_RST_CLK|SPC3_INT_CLK|SPC3_NOE_CLK|
SPC3_NWE_CLK |SPC3_NWAIT_CLK|SPC3_NL_CLK|
/*地址信号*/
SPC3_A0_CLK|SPC3_A1_CLK|SPC3_A2_CLK|SPC3_A3_CLK|
SPC3_A4_CLK|SPC3_A5_CLK|SPC3_A6_CLK|SPC3_A7_CLK|
/*数据信号*/
SPC3_D0_CLK|SPC3_D1_CLK|SPC3_D2_CLK|
SPC3_D3_CLK|SPC3_D4_CLK|SPC3_D5_CLK|
SPC3_D6_CLK|SPC3_D7_CLK, ENABLE );
/*-- GPIO Configuration ------------------------------------------------------*/
/* SRAM Data lines configuration */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = SPC3_D0_PIN;
GPIO_Init(SPC3_D0_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D0_PORT,SPC3_D0_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D1_PIN;
GPIO_Init(SPC3_D1_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D1_PORT,SPC3_D1_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D2_PIN;
GPIO_Init(SPC3_D2_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D2_PORT,SPC3_D2_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D3_PIN;
GPIO_Init(SPC3_D3_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D3_PORT,SPC3_D3_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D4_PIN;
GPIO_Init(SPC3_D4_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D4_PORT,SPC3_D4_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D5_PIN;
GPIO_Init(SPC3_D5_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D5_PORT,SPC3_D5_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D6_PIN;
GPIO_Init(SPC3_D6_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D6_PORT,SPC3_D6_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_D7_PIN;
GPIO_Init(SPC3_D7_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_D7_PORT,SPC3_D7_PinSource,FSMC_AF);
/* SRAM Address lines configuration */
GPIO_InitStructure.GPIO_Pin = SPC3_A0_PIN;
GPIO_Init(SPC3_A0_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A0_PORT,SPC3_A0_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A1_PIN;
GPIO_Init(SPC3_A1_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A1_PORT,SPC3_A1_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A2_PIN;
GPIO_Init(SPC3_A2_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A2_PORT,SPC3_A2_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A3_PIN;
GPIO_Init(SPC3_A3_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A3_PORT,SPC3_A3_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A4_PIN;
GPIO_Init(SPC3_A4_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A4_PORT,SPC3_A4_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A5_PIN;
GPIO_Init(SPC3_A5_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A5_PORT,SPC3_A5_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A6_PIN;
GPIO_Init(SPC3_A6_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A6_PORT,SPC3_A6_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_A7_PIN;
GPIO_Init(SPC3_A7_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_A7_PORT,SPC3_A7_PinSource,FSMC_AF);
/* NOE, NWE, NWAIT and NL configuration */
GPIO_InitStructure.GPIO_Pin = SPC3_NOE_PIN;
GPIO_Init(SPC3_NOE_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_NOE_PORT,SPC3_NOE_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_NWE_PIN;
GPIO_Init(SPC3_NWE_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_NWE_PORT,SPC3_NWE_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_NWAIT_PIN;
GPIO_Init(SPC3_NWAIT_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_NWAIT_PORT,SPC3_NWAIT_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = SPC3_NL_PIN;
GPIO_Init(SPC3_NL_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPC3_NL_PORT,SPC3_NL_PinSource,FSMC_AF);
/* RST configuration */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = SPC3_RST_PIN;
GPIO_Init ( SPC3_RST_PORT, & GPIO_InitStructure );
/* INT configuration */
/* 选择INT的引脚 */
GPIO_InitStructure.GPIO_Pin = SPC3_INT_PIN;
/* 设置引脚为输入模式 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
/* 设置引脚不上拉也不下拉 */
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
/* 使用上面的结构体初始化SPC3复位引脚 */
GPIO_Init(SPC3_INT_PORT, &GPIO_InitStructure);
/* 连接 EXTI 中断源 到INT引脚 */
SYSCFG_EXTILineConfig(FSMC_INT_EXTI_PORTSOURCE,FSMC_INT_EXTI_PINSOURCE);
/* 选择 EXTI 中断源 */
EXTI_InitStructure.EXTI_Line = FSMC_INT_EXTI_LINE;
/* 中断模式 */
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
/* 下降沿触发 */
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
/* 使能中断/事件线 */
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void FSMC_SRAM_Config(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
/*使能FSMC外设时钟*/
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
/*-- FSMC Configuration ------------------------------------------------------*/
p.FSMC_AddressSetupTime = 15; /*ADDSET 地址建立时间*/
p.FSMC_AddressHoldTime = 15; /*ADDHOLD 地址保持时间*/
p.FSMC_DataSetupTime = 15; /*DATAST 数据建立时间*/
p.FSMC_BusTurnAroundDuration = 0xFF; /*BUSTURN 总线返转时间*/
p.FSMC_CLKDivision = 0; /*CLKDIV 时钟分频*/
p.FSMC_DataLatency = 0; /*DATLAT 数据保持时间*/
p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_D; /*ACCMOD FSMC 访问模式*/
/*选择设置的BANK及片选信号*/
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
/*设置是否数据地址总线分时复用*/
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;//FSMC_DataAddressMux_Disable;
/*设置存储器类型*/
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
/*设置数据宽度*/
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;//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_Enable;//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);
/* Enable FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
|
|