用STM32 FSMC驱动液晶,卡住快一个星期了,用示波器看WR,RD时序都是一个低电平,100-300毫秒,感觉不对啊! LCD_DATA 写后读出来都是 0XFF, LCD_CMD读出来是0XE3。搞不懂啊。 调试fsmc_BCR1,fsmc_BTR1后两值还是默认值,不见变化,是FSMC就没驱动对麽?新手,贴上程序大家帮忙看看吧?!
#define Bank1_LCD_D ((u32)0x60000001)//Disp Data ADDR
#define Bank1_LCD_C ((u32)0x60000000)
#define LCD_DATA (*((volatile u8 *) 0x60000001))
#define LCD_CMD (*((volatile u8 *) 0x60000000))
void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 使能FSMC时钟*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* 使能FSMC对应相应管脚时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOF , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/* 配置LCD背光控制管脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* 配置LCD复位控制管脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* 配置FSMC相对应的数据线,FSMC-D0~D7: PD 14 15 0 1,PE 7 8 9 10 */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 |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_Init(GPIOE, &GPIO_InitStructure);
/* 配置FSMC相对应的控制线
* PD4-FSMC_NOE :LCD-RD 读使能
* PD5-FSMC_NWE :LCD-WR 写使能
* PD7-FSMC_NE1 :LCD-CS
* PF0-FSMC_A0 :LCD-D/I 相当于片内地址信号,决定是写命令还是写数据
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_Init(GPIOF, &GPIO_InitStructure);
/* tft control gpio init */
// GPIO_SetBits(GPIOD, GPIO_Pin_13); // 背光打开
GPIO_ResetBits(GPIOB, GPIO_Pin_6);
GPIO_SetBits(GPIOD, GPIO_Pin_11); //fuwei
nor=(*(volatile u16 *)(0xa0000000+8)); //fsmc_BCR1
cs=(*(volatile u32 *)(0xa0000000+8+4)); //fsmc_BTR1
}
void LCD_FSMC_Config(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
p.FSMC_AddressSetupTime = 0x02; //地址建立时间
p.FSMC_AddressHoldTime = 0x00; //地址保持时间
p.FSMC_DataSetupTime = 0x05; //数据建立时间
p.FSMC_BusTurnAroundDuration = 0x00;
p.FSMC_CLKDivision = 0x00;
p.FSMC_DataLatency = 0x00;
p.FSMC_AccessMode = FSMC_AccessMode_B; // 一般使用模式B来控制LCD
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; //NOR FLASH的BANK1
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //数据线与地址线不复用
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR; //存储器类型NOR FLASH
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; //数据宽度为16位
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; //本成员配置仅在突发模式下有效。NWAIT信号在什么时期产生
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; //本成员的配置只在突发模式下有效,禁用NWAIT信号
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //禁止突发写操作
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; //写使能
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; //禁止扩展模式,扩展模式可以使用独立的读、写模式
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; //配置读写时序
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; //配置写时序
FSMC_NORSRAMStructInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* 使能 FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
nor=(*(volatile u16 *)(0xa0000000+8)); //fsmc_BCR1
cs=(*(volatile u32 *)(0xa0000000+8+4)); //fsmc_BTR1
}
|