野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9238|回复: 1

FSMC驱动TFT测试不正常

[复制链接]
发表于 2019-5-19 19:28:18 | 显示全部楼层 |阅读模式
按照火哥视频先使用ILI9341_Write_Cmd(0x0C);测试返回值,如果返回0x6为正常,而我却一直是0x0。
我按照火哥的解决办法
#define ILI9341_CMD_ADDR (__IO uint16_t*)(0x6c000000)
#define ILI9341_DATA_ADDR (__IO uint16_t*)(0x6c000800)
还是没有解决,请问是什么问题?
头文件已经包含好了

void ILI9341_GPIO_Config()
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        RCC_APB2PeriphClockCmd(ILI9341_CS_CLK|ILI9341_BK_CLK|ILI9341_RD_CLK|ILI9341_WR_CLK|ILI9341_DC_CLK|ILI9341_D0_CLK|ILI9341_D1_CLK|ILI9341_D2_CLK|ILI9341_D3_CLK|
        ILI9341_D4_CLK|ILI9341_D5_CLK|ILI9341_D6_CLK|ILI9341_D7_CLK|ILI9341_D8_CLK|ILI9341_D9_CLK|ILI9341_D10_CLK|ILI9341_D11_CLK|ILI9341_D12_CLK|ILI9341_D13_CLK|
        ILI9341_D14_CLK|ILI9341_D15_CLK,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_BK_PIN;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(ILI9341_BK_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_CS_PIN;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(ILI9341_CS_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_RD_PIN;
        GPIO_Init(ILI9341_RD_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_WR_PIN;
        GPIO_Init(ILI9341_WR_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_DC_PIN;
        GPIO_Init(ILI9341_DC_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D0_PIN;
        GPIO_Init(ILI9341_D0_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D1_PIN;
        GPIO_Init(ILI9341_D1_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D2_PIN;
        GPIO_Init(ILI9341_D2_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D3_PIN;
        GPIO_Init(ILI9341_D3_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D4_PIN;
        GPIO_Init(ILI9341_D4_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D5_PIN;
        GPIO_Init(ILI9341_D5_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D6_PIN;
        GPIO_Init(ILI9341_D6_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D7_PIN;
        GPIO_Init(ILI9341_D7_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D8_PIN;
        GPIO_Init(ILI9341_D8_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D9_PIN;
        GPIO_Init(ILI9341_D9_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D10_PIN;
        GPIO_Init(ILI9341_D10_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D11_PIN;
        GPIO_Init(ILI9341_D11_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D12_PIN;
        GPIO_Init(ILI9341_D12_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D13_PIN;
        GPIO_Init(ILI9341_D13_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D14_PIN;
        GPIO_Init(ILI9341_D14_PORT,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = ILI9341_D15_PIN;
        GPIO_Init(ILI9341_D15_PORT,&GPIO_InitStructure);
}

void ILI9341_FSMC_Config()
{
        FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
        FSMC_NORSRAMTimingInitTypeDef readWriteTiming;
       
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);
       
        readWriteTiming.FSMC_AddressSetupTime = 0x01;
       
        readWriteTiming.FSMC_AddressHoldTime = 0x00;
       
        readWriteTiming.FSMC_DataSetupTime = 0x04;
       
        readWriteTiming.FSMC_BusTurnAroundDuration = 0x00;
       
        readWriteTiming.FSMC_CLKDivision = 0x00;
       
        readWriteTiming.FSMC_DataLatency = 0x00;
       
        readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_B;
       
        FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
       
        FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
       
        FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
       
        FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
       
        FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
       
        FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_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_Disable;
       
        FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
       
        FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming;
       
        FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &readWriteTiming;
       
        FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
       
        FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4,ENABLE);
}

void ILI9341_BackLed_Control(FunctionalState enumState)
{
        if(enumState)
                GPIO_ResetBits(ILI9341_BK_PORT,ILI9341_BK_PIN);
        else
                GPIO_SetBits(ILI9341_BK_PORT,ILI9341_BK_PIN);
}

__inline void ILI9341_Write_Cmd(uint16_t usCmd)
{
        *ILI9341_CMD_ADDR = usCmd;
}

__inline void ILI9341_Write_Data(uint16_t usData)
{
        *ILI9341_DATA_ADDR = usData;
}

__inline uint16_t ILI9341_Read_Data()
{
        return (*ILI9341_DATA_ADDR);
}

uint16_t Read_Pixel_Format()
{
        ILI9341_Write_Cmd(0x0C);
        ILI9341_Read_Data();
        return ILI9341_Read_Data();
}


头文件
#define FSMC_BANK_NORSRAMx FSMC_Bank1_NORSRAM4

#define ILI9341_CMD_ADDR (__IO uint16_t*)(0x6c000000)
#define ILI9341_DATA_ADDR (__IO uint16_t*)(0x6c000800)

#define ILI9341_CS_CLK RCC_APB2Periph_GPIOG
#define ILI9341_CS_PORT GPIOG
#define ILI9341_CS_PIN GPIO_Pin_12

#define ILI9341_BK_CLK RCC_APB2Periph_GPIOB
#define ILI9341_BK_PORT GPIOB
#define ILI9341_BK_PIN GPIO_Pin_0

#define ILI9341_RD_CLK RCC_APB2Periph_GPIOD
#define ILI9341_RD_PORT GPIOD
#define ILI9341_RD_PIN GPIO_Pin_4

#define ILI9341_WR_CLK RCC_APB2Periph_GPIOD
#define ILI9341_WR_PORT GPIOD
#define ILI9341_WR_PIN GPIO_Pin_5

#define ILI9341_DC_CLK RCC_APB2Periph_GPIOG
#define ILI9341_DC_PORT GPIOG
#define ILI9341_DC_PIN GPIO_Pin_0

#define ILI9341_D0_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D0_PORT GPIOD
#define ILI9341_D0_PIN GPIO_Pin_14

#define ILI9341_D1_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D1_PORT GPIOD
#define ILI9341_D1_PIN GPIO_Pin_15

#define ILI9341_D2_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D2_PORT GPIOD
#define ILI9341_D2_PIN GPIO_Pin_0

#define ILI9341_D3_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D3_PORT GPIOD
#define ILI9341_D3_PIN GPIO_Pin_1

#define ILI9341_D4_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D4_PORT GPIOE
#define ILI9341_D4_PIN GPIO_Pin_7

#define ILI9341_D5_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D5_PORT GPIOE
#define ILI9341_D5_PIN GPIO_Pin_8

#define ILI9341_D6_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D6_PORT GPIOE
#define ILI9341_D6_PIN GPIO_Pin_9

#define ILI9341_D7_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D7_PORT GPIOE
#define ILI9341_D7_PIN GPIO_Pin_10

#define ILI9341_D8_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D8_PORT GPIOE
#define ILI9341_D8_PIN GPIO_Pin_11

#define ILI9341_D9_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D9_PORT GPIOE
#define ILI9341_D9_PIN GPIO_Pin_12

#define ILI9341_D10_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D10_PORT GPIOE
#define ILI9341_D10_PIN GPIO_Pin_13

#define ILI9341_D11_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D11_PORT GPIOE
#define ILI9341_D11_PIN GPIO_Pin_14

#define ILI9341_D12_CLK RCC_APB2Periph_GPIOE
#define ILI9341_D12_PORT GPIOE
#define ILI9341_D12_PIN GPIO_Pin_15

#define ILI9341_D13_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D13_PORT GPIOD
#define ILI9341_D13_PIN GPIO_Pin_8

#define ILI9341_D14_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D14_PORT GPIOD
#define ILI9341_D14_PIN GPIO_Pin_9

#define ILI9341_D15_CLK RCC_APB2Periph_GPIOD
#define ILI9341_D15_PORT GPIOD
#define ILI9341_D15_PIN GPIO_Pin_10

void ILI9341_GPIO_Config(void);
void ILI9341_FSMC_Config(void);
void ILI9341_BackLed_Control(FunctionalState enumState);


int main()
{
        USART1_Config();
        ILI9341_GPIO_Config();
        ILI9341_FSMC_Config();
        ILI9341_BackLed_Control(ENABLE);
        printf("\r\n0x0C命令返回值测试:0x%x",Read_Pixel_Format());
        while(1)
        {
               
        }
}

回复

使用道具 举报

 楼主| 发表于 2019-5-19 19:36:33 | 显示全部楼层
先说一下这些引脚的宏定义是其他板子的,LCD_RST直接和NRST连在一起就没定义了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-6-3 11:05 , Processed in 0.034702 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表