ili9341不适用于STM32f4发现

时间:2017-10-09 07:25:50

标签: microcontroller stm32 lcd stm32f4discovery stm32f4

我正在测试stm32F4-discovery上的IlI9341 3.2 TFT LCD。我根据Discovery数据表连线。我还阅读了ILI9341数据表并浏览了所有寄存器。 但我一无所获。此外,LD7,LD5和LD6继续指示电流溢出。使用Coocox IDE编译。 SETCURSORPOSITION和FILL功能进一步下降。 如果有人可以帮助我,这是我的代码。谢谢。

#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_fsmc.h"
#include "LCD.h"

#define LCD_REG     (*((volatile unsigned short *) 0x60000000))//address
#define LCD_RAM     (*((volatile unsigned short *) 0x60020000))//data

#define MAX_X       320//landscape mode
#define MAX_Y       240//landscape mode
#define ILI9341_PIXEL 76800

#define Green    0x07E0

void LCD_PinsConfiguration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD,&GPIO_InitStructure);

GPIO_ResetBits(GPIOD,GPIO_Pin_7);

RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource11,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);

GPIO_PinAFConfig(GPIOE,GPIO_PinSource2,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FSMC);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|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_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);

Delay(5000);

RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;

FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 0x0F;
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 5;
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration =0;
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency =0;
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;

FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
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_AsynchronousWait = FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;

FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1,ENABLE);

}

void LCD_Initialization(void)
{
LCD_PinsConfiguration();

LCD_ILI9341_SendCommand(0x01);
Delay(50000);

LCD_ILI9341_SendCommand(0xcb);
LCD_ILI9341_SendData(0x39);
LCD_ILI9341_SendData(0x2C);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x34);
LCD_ILI9341_SendData(0x02);
LCD_ILI9341_SendCommand(0xcf);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0xC1);
LCD_ILI9341_SendData(0x30);
LCD_ILI9341_SendCommand(0xe8);
LCD_ILI9341_SendData(0x85);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x78);
LCD_ILI9341_SendCommand(0xea);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendCommand(0xed);
LCD_ILI9341_SendData(0x64);
LCD_ILI9341_SendData(0x03);
LCD_ILI9341_SendData(0x12);
LCD_ILI9341_SendData(0x81);
LCD_ILI9341_SendCommand(0xf7);
LCD_ILI9341_SendData(0x20);
LCD_ILI9341_SendCommand(0xc0);
LCD_ILI9341_SendData(0x23);
LCD_ILI9341_SendCommand(0xc1);
LCD_ILI9341_SendData(0x10);
LCD_ILI9341_SendCommand(0xc5);
LCD_ILI9341_SendData(0x3E);
LCD_ILI9341_SendData(0x28);
LCD_ILI9341_SendCommand(0xc7);
LCD_ILI9341_SendData(0x86);
LCD_ILI9341_SendCommand(0x36);
LCD_ILI9341_SendData(0x48);
LCD_ILI9341_SendCommand(0x3a);
LCD_ILI9341_SendData(0x55);
LCD_ILI9341_SendCommand(0xb1);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x18);
LCD_ILI9341_SendCommand(0xb6);
LCD_ILI9341_SendData(0x08);
LCD_ILI9341_SendData(0x82);
LCD_ILI9341_SendData(0x27);
LCD_ILI9341_SendCommand(0xf2);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendCommand(0x2a);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0xEF);
LCD_ILI9341_SendCommand(0x2b);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x01);
LCD_ILI9341_SendData(0x3F);
LCD_ILI9341_SendCommand(0x26);
LCD_ILI9341_SendData(0x01);
LCD_ILI9341_SendCommand(0xe0);
LCD_ILI9341_SendData(0x0F);
LCD_ILI9341_SendData(0x31);
LCD_ILI9341_SendData(0x2B);
LCD_ILI9341_SendData(0x0C);
LCD_ILI9341_SendData(0x0E);
LCD_ILI9341_SendData(0x08);
LCD_ILI9341_SendData(0x4E);
LCD_ILI9341_SendData(0xF1);
LCD_ILI9341_SendData(0x37);
LCD_ILI9341_SendData(0x07);
LCD_ILI9341_SendData(0x10);
LCD_ILI9341_SendData(0x03);
LCD_ILI9341_SendData(0x0E);
LCD_ILI9341_SendData(0x09);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendCommand(0xe1);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x0E);
LCD_ILI9341_SendData(0x14);
LCD_ILI9341_SendData(0x03);
LCD_ILI9341_SendData(0x11);
LCD_ILI9341_SendData(0x07);
LCD_ILI9341_SendData(0x31);
LCD_ILI9341_SendData(0xC1);
LCD_ILI9341_SendData(0x48);
LCD_ILI9341_SendData(0x08);
LCD_ILI9341_SendData(0x0F);
LCD_ILI9341_SendData(0x0C);
LCD_ILI9341_SendData(0x31);
LCD_ILI9341_SendData(0x36);
LCD_ILI9341_SendData(0x0F);
LCD_ILI9341_SendCommand(0x11);

Delay(50000);

LCD_ILI9341_SendCommand(0x29);
LCD_ILI9341_SendCommand(0x22);

}

void LCD_ILI9341_SendCommand(uint16_t index)
{
    LCD_REG = index;
}

void LCD_ILI9341_SendData(uint16_t data)
{
    LCD_RAM = data;
}


void LCD_ILI9341_SetCursorPosition(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
LCD_ILI9341_SendCommand(0x2A);
LCD_ILI9341_SendData(x1 >> 8);
LCD_ILI9341_SendData(x1 & 0xFF);
LCD_ILI9341_SendData(x2 >> 8);
LCD_ILI9341_SendData(x2 & 0xFF);

LCD_ILI9341_SendCommand(0x2B);
LCD_ILI9341_SendData(y1 >> 8);
LCD_ILI9341_SendData(y1 & 0xFF);
LCD_ILI9341_SendData(y2 >> 8);
LCD_ILI9341_SendData(y2 & 0xFF);
}

void LCD_ILI9341_Fill(uint16_t color) {
unsigned int n, i, j;
i = color >> 8;
j = color & 0xFF;
LCD_ILI9341_SetCursorPosition(0, 0, MAX_Y - 1, MAX_X - 1);

LCD_ILI9341_SendCommand(0x0022);

for (n = 0; n < ILI9341_PIXEL; n++) {
    LCD_ILI9341_SendData(i);
    LCD_ILI9341_SendData(j);
}
}


void Delay(__IO uint32_t nCount)
{
while(nCount--)
{

}
}

2 个答案:

答案 0 :(得分:1)

我将回答我自己的问题,以明确事情得到解决。但我要感谢社区。 实际上我做了一些事情:我从配置块中删除了GPIOE 2,因为它没有被使用。我在同一个块中将GPIOD替换为GPIOE。在“LCD_ILI9341_Fill”内部,我将“LCD_ILI9341_SendCommand(0x0022)”更改为“LCD_ILI9341_SendCommand(0x002C)”。 0x002C是您在ili9341上写入数据的实际内存写入地址。我还将LCD RESET引脚连接到stm32f4 NRST引脚。 3V电源连接到LCD LED_A。 现在一切正常,我仍然得到错误的颜色,但我需要对寄存器进行一些更改,例如寄存器36h。

答案 1 :(得分:0)

那里有一个拼写错误,您根本没有配置GPIOE

将上一次GPIO_Init()电话更改为

GPIO_Init(GPIOE,&GPIO_InitStructure);

而不是再次配置GPIOD的错误引脚。

  

我根据发现数据表进行了连接。

您的意思是扩展板数据表吗?因为Discovery数据表没有提及LCD控制器。

  

LD7,LD5和LD6继续指示当前溢出

你确定吗?过流指示器为LD8(红色)。您应该期待LD5,LD6和LD8的随机点亮或闪烁,因为它们连接到LCD数据线,但不连接到LD7。