打印
[STM32F4]

ltdc驱动8位串行8位RGB

[复制链接]
2568|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lzandyc|  楼主 | 2016-3-15 17:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我目前遇到一个LTDC的问题:
1.我这边有一个串行8bit的RGB显示屏,我将数据总线接在LTDC驱动器的B端口上,同时按照LCD规格书上设置了参数,但是实际显示的就是花屏。请问是否有人遇到同样问题???
沙发
ideafor| | 2016-3-15 20:33 | 只看该作者
驱动程序是怎么写的呢?是不是上电顺序有问题

使用特权

评论回复
板凳
zhuomuniao110| | 2016-3-16 08:54 | 只看该作者
你用的是那个开发板吗,上面带个小液晶屏的,那个例程里不是有用法嘛,按照那个随便改改就行了。

使用特权

评论回复
地板
zhuomuniao110| | 2016-3-16 08:57 | 只看该作者

为了方便以后快速查阅代码,提高开发效率,在这里特将LTDC驱动的初始化代码贴上来。本代码是基于ST官方STM32F429 Discovery Demo板的,学习LTDC驱动时参考了Demo板的官方例程,但是总觉得官方例程写得有点繁琐,不简洁明了,于是在此基础上重新整理代码得到如下初始化模板。


说明:本测试例程只使用了Layer1,显示缓冲区为FrameBuffer,颜色格式为RGB565,初始时缓冲区为0,所以显示Layer1时是全黑色,如果不使能Layer1只显示background,则屏幕显示为红色。

void LCD_Init(void)
{
  LTDC_InitTypeDef               LTDC_InitStruct;
   
  /* Configure the LCD Control pins ------------------------------------------*/
  LCD_CtrlLinesConfig();
  
  /* Configure the LCD_SPI interface -----------------------------------------*/
  LCD_SPI_Config();
  
  /* Power on the LCD --------------------------------------------------------*/
  LCD_PowerOn();
  
  /* Enable the LTDC Clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
  
  /* Configure the LCD Control pins */
  LCD_GPIO_Config();  
   
  /* Enable Pixel Clock ------------------------------------------------------*/
  
  /* Configure PLLSAI prescalers for LCD */
  /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
  /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */
  /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */
  /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */
  RCC_PLLSAIConfig(192, 7, 3);
  RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8);
  
  /* Enable PLLSAI Clock */
  RCC_PLLSAICmd(ENABLE);
  /* Wait for PLLSAI activation */
  while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
  {
  }
  
  /* LTDC Initialization -----------------------------------------------------*/
  
  /* Initialize the horizontal synchronization polarity as active low*/
  LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;     
  /* Initialize the vertical synchronization polarity as active low */  
  LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;     
  /* Initialize the data enable polarity as active low */
  LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;     
  /* Initialize the pixel clock polarity as input pixel clock */
  LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
  
  /* Timing configuration */
  /* Configure horizontal synchronization width */     
  //LTDC_InitStruct.LTDC_HorizontalSync = 9;
  LTDC_InitStruct.LTDC_HorizontalSync = 9;
  /* Configure vertical synchronization height */
  LTDC_InitStruct.LTDC_VerticalSync = 1;
  /* Configure accumulated horizontal back porch */
  LTDC_InitStruct.LTDC_AccumulatedHBP = 29;
  /* Configure accumulated vertical back porch */
  LTDC_InitStruct.LTDC_AccumulatedVBP = 3;  
  /* Configure accumulated active width */  
  LTDC_InitStruct.LTDC_AccumulatedActiveW = 269;
  /* Configure accumulated active height */
  LTDC_InitStruct.LTDC_AccumulatedActiveH = 323;
  /* Configure total width */
  LTDC_InitStruct.LTDC_TotalWidth = 279;
  /* Configure total height */
  LTDC_InitStruct.LTDC_TotalHeigh = 327;
   
  /* Configure R,G,B component values for LCD background color */                  
  LTDC_InitStruct.LTDC_BackgroundRedValue = 0xff;            
  LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;         
  LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
  
  LTDC_Init(<DC_InitStruct);
}

LCD串行控制信号线配置:

void LCD_CtrlLinesConfig(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable GPIOs clock*/
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);

  /* Configure NCS in Output Push-Pull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  /* Configure WRX in Output Push-Pull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Set chip select pin high */
  GPIO_SetBits(GPIOC, GPIO_Pin_2);
}
[code]void LCD_SPI_Config(void)
{
  SPI_InitTypeDef    SPI_InitStructure;
  GPIO_InitTypeDef   GPIO_InitStructure;

  /* Enable LCD_SPI_SCK_GPIO_CLK, LCD_SPI_MISO_GPIO_CLK and LCD_SPI_MOSI_GPIO_CLK clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);

  /* Enable LCD_SPI and SYSCFG clock  */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI5, ENABLE);
  
  /* Configure LCD_SPI SCK pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  GPIO_Init(GPIOF, &GPIO_InitStructure);

  /* Configure LCD_SPI MISO pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_Init(GPIOF, &GPIO_InitStructure);

  /* Configure LCD_SPI MOSI pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_Init(GPIOF, &GPIO_InitStructure);

  /* Connect SPI SCK */
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource7, GPIO_AF_SPI5);

  /* Connect SPI MISO */
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource8, GPIO_AF_SPI5);

  /* Connect SPI MOSI */
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource9, GPIO_AF_SPI5);
  
  SPI_I2S_DeInit(SPI5);

  /* SPI configuration -------------------------------------------------------*/
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  /* SPI baudrate is set to 5.6 MHz (PCLK2/SPI_BaudRatePrescaler = 90/16 = 5.625 MHz)
  

使用特权

评论回复
5
zhuomuniao110| | 2016-3-16 08:58 | 只看该作者
LCD上电初始化序列,请对照LCD datasheet要求进行配置,此处省略部分内容:
/**
  * @brief  Configure the LCD controller (Power On sequence as described in ILI9341 Datasheet)
  * @param  None
  * @retval None
  */
void LCD_PowerOn(void)
{
  LCD_WriteCommand(0xCA);
  LCD_WriteData(0xC3);
  LCD_WriteData(0x08);
  LCD_WriteData(0x50);
  LCD_WriteCommand(LCD_POWERB);
  LCD_WriteData(0x00);
  LCD_WriteData(0xC1);
  LCD_WriteData(0x30);
  LCD_WriteCommand(LCD_POWER_SEQ);
  LCD_WriteData(0x64);
  LCD_WriteData(0x03);
  LCD_WriteData(0x12);
  LCD_WriteData(0x81);
  
  ...


  LCD_WriteCommand(LCD_SLEEP_OUT);
  delay(200);
  LCD_WriteCommand(LCD_DISPLAY_ON);
  /* GRAM start writing */
  LCD_WriteCommand(LCD_GRAM);
}
Layer初始化:


void LCD_Layer1Init(void)
{
  LTDC_Layer_InitTypeDef         LTDC_Layer_InitStruct;

  /* Windowing configuration */
  /* In this case all the active display area is used to display a picture then:
  Horizontal start = horizontal synchronization + Horizontal back porch = 30
  Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1
  Vertical start   = vertical synchronization + vertical back porch     = 4
  Vertical stop   = Vertical start + window height -1  = 4 + 160 -1      */
  LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30;
  LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1);
  LTDC_Layer_InitStruct.LTDC_VerticalStart = 4;
  LTDC_Layer_InitStruct.LTDC_VerticalStop = 320 + 4 -1;
  
  /* Pixel Format configuration*/           
  LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
  
  /* Alpha constant (255 totally opaque) */
  LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
  
  /* Configure blending factors */      
  LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;   
  LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;  
  
  /* Default Color configuration (configure A,R,G,B component values) */         
  LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;        
  LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;      
  LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;         
  LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;   
  
  /* Input Address configuration */   
  LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (u32)FrameBuffer;
  
  /* the length of one line of pixels in bytes + 3 then :
  Line Lenth = Active high width x number of bytes per pixel + 3
  Active high width         = 240
  number of bytes per pixel = 2    (pixel_format : RGB565)
  */
  LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 2) + 3);
  
  /*  the pitch is the increment from the start of one line of pixels to the
  start of the next line in bytes, then :
  Pitch = Active high width x number of bytes per pixel     
  */
  LTDC_Layer_InitStruct.LTDC_CFBPitch = (240 * 2);  
  
  /* configure the number of lines */
  LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320;
  
  LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct);
  LTDC_LayerCmd(LTDC_Layer1, ENABLE);
  LTDC_ReloadConfig(ENABLE);
}
主程序:

int main(void)
{
  LCD_Init();
  LCD_Layer1Init();
  LTDC_Cmd(ENABLE);

  while(1);
}


使用特权

评论回复
6
lzandyc|  楼主 | 2016-3-16 10:19 | 只看该作者
你们上面所提到的都是并行的RGB通信方式,这个没有问题是可以的,目前我们用的是串行RGB的方式,不知道这个怎么弄?

使用特权

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

本版积分规则

1

主题

2

帖子

0

粉丝