发新帖我要提问
12
返回列表
打印
[应用相关]

FSMC工程 ILI9325驱动LCD

[复制链接]
楼主: internally
手机看帖
扫描二维码
随时随地手机跟帖
21
internally|  楼主 | 2020-7-22 20:35 | 只看该作者 |只看大图 回帖奖励 |倒序浏览
需要注意的是在标准库中和在HAL库中FSMC的配置有不小的不同,首先是FSMC相关结构体和标准库中不同,有一些在标准库中可以配置的选项在HAL库中并不存在,还有FSMC配置完成后初始化FSMC的函数和标准库中也有很大不同,如果使用了两个FSMC_NORSRAM_TimingTypeDef,则要使用HAL_SRAM_Init()函数进行初始化。还需要注意的是要使能BANK1。

使用特权

评论回复
22
internally|  楼主 | 2020-7-22 20:37 | 只看该作者
修改复位函数

还有其他一些修改,改动不大

使用特权

评论回复
23
internally|  楼主 | 2020-7-22 20:38 | 只看该作者
rebuild工程,如果没有错误,在main函数中调用LCD初始化函数,就可以直接使用标准库中可以使用的绘制函数了。

使用特权

评论回复
24
internally|  楼主 | 2020-7-22 20:38 | 只看该作者
修改后的GPIO初始化函数

void LCD_GPIOInit(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

//FSMC_NORSRAM_InitTypeDef  FSMC_NORSRAMInitStructure;

FSMC_NORSRAM_TimingTypeDef  readWriteTiming;

FSMC_NORSRAM_TimingTypeDef  writeTiming;

hsram2.Instance = FSMC_NORSRAM_DEVICE;

hsram2.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;

__HAL_RCC_FSMC_CLK_ENABLE();//ʹÄÜFSMCʱÖÓ

//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);        //ʹÄÜFSMCʱÖÓ

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOB_CLK_ENABLE();

__HAL_RCC_GPIOG_CLK_ENABLE();

__HAL_RCC_GPIOE_CLK_ENABLE();

__HAL_RCC_GPIOD_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO,ENABLE);//ʹÄÜPORTB,D,E,GÒÔ¼°AFIO¸´Óù¦ÄÜʱÖÓ

/*Configure GPIO pin : PC5 */

GPIO_InitStruct.Pin = GPIO_PIN_5;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;

HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : PB0 */

GPIO_InitStruct.Pin = GPIO_PIN_0;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* GPIO_InitStruct */

GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_12;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

/* GPIO_InitStruct */

GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10

|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14

|GPIO_PIN_15;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

/* GPIO_InitStruct */

GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14

|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4

|GPIO_PIN_5;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

readWriteTiming.AddressSetupTime = 0x01;        //µØÖ·½¨Á¢Ê±¼ä£¨ADDSET£©Îª2¸öHCLK 1/36M=27ns

readWriteTiming.AddressHoldTime = 0x00;        //µØÖ·±£³Öʱ¼ä£¨ADDHLD£©Ä£Ê½AδÓõ½

readWriteTiming.DataSetupTime = 0x0f;        // Êý¾Ý±£´æʱ¼äΪ16¸öHCLK,ÒòΪҺ¾§Çý¶¯ICµÄ¶ÁÊý¾ÝµÄʱºò£¬ËٶȲ»ÄÜÌ«¿ì£¬ÓÈÆä¶Ô1289Õâ¸öIC¡£

readWriteTiming.BusTurnAroundDuration = 0x00;

readWriteTiming.CLKDivision = 0x00;

readWriteTiming.DataLatency = 0x00;

readWriteTiming.AccessMode = FSMC_ACCESS_MODE_A;        //ģʽA

writeTiming.AddressSetupTime = 0x02;        //0x01 µØÖ·½¨Á¢Ê±¼ä£¨ADDSET£©Îª1¸öHCLK

writeTiming.AddressHoldTime = 0x00;        //µØÖ·±£³Öʱ¼ä£¨A

writeTiming.DataSetupTime = 0x05;        ////0x03 Êý¾Ý±£´æʱ¼äΪ4¸öHCLK

writeTiming.BusTurnAroundDuration = 0x00;

writeTiming.CLKDivision = 0x00;

writeTiming.DataLatency = 0x00;

writeTiming.AccessMode = FSMC_ACCESS_MODE_A;        //ģʽA

hsram2.Init.NSBank = FSMC_NORSRAM_BANK4;//  ÕâÀïÎÒÃÇʹÓÃNE4 £¬Ò²¾Í¶ÔÓ¦BTCR[6],[7]¡£

hsram2.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE; // ²»¸´ÓÃÊý¾ÝµØÖ·

hsram2.Init.MemoryType =FSMC_MEMORY_TYPE_SRAM;// FSMC_MemoryType_SRAM;  //SRAM

hsram2.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;//´æ´¢Æ÷Êý¾Ý¿í¶ÈΪ16bit

hsram2.Init.BurstAccessMode =FSMC_BURST_ACCESS_MODE_DISABLE;// FSMC_BurstAccessMode_Disable;

hsram2.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;

hsram2.Init.AsynchronousWait=FSMC_ASYNCHRONOUS_WAIT_DISABLE;

hsram2.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;

hsram2.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;

hsram2.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;        //  ´æ´¢Æ÷дʹÄÜ

hsram2.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;

hsram2.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE; // ¶ÁдʹÓò»Í¬µÄʱÐò

hsram2.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;

//FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming; //¶ÁдʱÐò

//FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming;  //дʱÐò

if (HAL_SRAM_Init(&hsram2, &readWriteTiming, &writeTiming) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

__FSMC_NORSRAM_ENABLE(FSMC_NORSRAM_DEVICE,FSMC_NORSRAM_BANK4);

}

使用特权

评论回复
25
internally|  楼主 | 2020-7-22 20:39 | 只看该作者
修改后的LCD初始化函数

void LCD_Init(void)

{

LCD_GPIOInit();

LCD_RESET();

//************* Start Initial Sequence **********//

LCD_WriteReg(0x00E5,0x78F0);

LCD_WriteReg(0x0001,0x0100);

LCD_WriteReg(0x0002,0x0700);

LCD_WriteReg(0x0003,0x1030);

LCD_WriteReg(0x0004,0x0000);

LCD_WriteReg(0x0008,0x0202);

LCD_WriteReg(0x0009,0x0000);

LCD_WriteReg(0x000A,0x0000);

LCD_WriteReg(0x000C,0x0000);

LCD_WriteReg(0x000D,0x0000);

LCD_WriteReg(0x000F,0x0000);

//power on sequence VGHVGL

LCD_WriteReg(0x0010,0x0000);

LCD_WriteReg(0x0011,0x0007);

LCD_WriteReg(0x0012,0x0000);

LCD_WriteReg(0x0013,0x0000);

LCD_WriteReg(0x0007,0x0000);

//vgh

LCD_WriteReg(0x0010,0x1690);

LCD_WriteReg(0x0011,0x0227);

//delay_ms(100);

//vregiout

LCD_WriteReg(0x0012,0x009D); //0x001b

//delay_ms(100);

//vom amplitude

LCD_WriteReg(0x0013,0x1900);

//delay_ms(100);

//vom H

LCD_WriteReg(0x0029,0x0025);

LCD_WriteReg(0x002B,0x000D);

//gamma

LCD_WriteReg(0x0030,0x0007);

LCD_WriteReg(0x0031,0x0303);

LCD_WriteReg(0x0032,0x0003);// 0006

LCD_WriteReg(0x0035,0x0206);

LCD_WriteReg(0x0036,0x0008);

LCD_WriteReg(0x0037,0x0406);

LCD_WriteReg(0x0038,0x0304);//0200

LCD_WriteReg(0x0039,0x0007);

LCD_WriteReg(0x003C,0x0602);// 0504

LCD_WriteReg(0x003D,0x0008);

//ram

LCD_WriteReg(0x0050,0x0000);

LCD_WriteReg(0x0051,0x00EF);

LCD_WriteReg(0x0052,0x0000);

LCD_WriteReg(0x0053,0x013F);

LCD_WriteReg(0x0060,0xA700);

LCD_WriteReg(0x0061,0x0001);

LCD_WriteReg(0x006A,0x0000);

//

LCD_WriteReg(0x0080,0x0000);

LCD_WriteReg(0x0081,0x0000);

LCD_WriteReg(0x0082,0x0000);

LCD_WriteReg(0x0083,0x0000);

LCD_WriteReg(0x0084,0x0000);

LCD_WriteReg(0x0085,0x0000);

//

LCD_WriteReg(0x0090,0x0010);

LCD_WriteReg(0x0092,0x0600);

LCD_WriteReg(0x0007,0x0133);

LCD_WriteReg(0x00,0x0022);//

LCD_SetParam();//ÉèÖÃLCD²ÎÊý

//LCD_LED=1;//µãÁÁ±³¹â

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);

LCD_Clear(WHITE);

}

使用特权

评论回复
26
internally|  楼主 | 2020-7-22 20:42 | 只看该作者
修改后在main函数中使用绘图函数时要注释掉原有的GPIO和FSMC初始化函数。

使用特权

评论回复
27
internally|  楼主 | 2020-7-22 20:43 | 只看该作者
测试结果:



使用特权

评论回复
28
internally|  楼主 | 2020-7-22 20:43 | 只看该作者
修改后即可以在STM32CubeMX中配置后就可以将之前修改好的文件直接添加到工程中使用,这样即可在LCD上显示其他功能的状态信息。

使用特权

评论回复
29
internally|  楼主 | 2020-7-22 20:44 | 只看该作者

作者:停下浮躁的心
链接:https://www.jianshu.com/p/ab082c9290f7
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则