[STM32F4] ltdc驱动8位串行8位RGB

[复制链接]
 楼主| 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,则屏幕显示为红色。

  1. void LCD_Init(void)
  2. {
  3.   LTDC_InitTypeDef               LTDC_InitStruct;
  4.    
  5.   /* Configure the LCD Control pins ------------------------------------------*/
  6.   LCD_CtrlLinesConfig();
  7.   
  8.   /* Configure the LCD_SPI interface -----------------------------------------*/
  9.   LCD_SPI_Config();
  10.   
  11.   /* Power on the LCD --------------------------------------------------------*/
  12.   LCD_PowerOn();
  13.   
  14.   /* Enable the LTDC Clock */
  15.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
  16.   
  17.   /* Configure the LCD Control pins */
  18.   LCD_GPIO_Config();  
  19.    
  20.   /* Enable Pixel Clock ------------------------------------------------------*/
  21.   
  22.   /* Configure PLLSAI prescalers for LCD */
  23.   /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
  24.   /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */
  25.   /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */
  26.   /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */
  27.   RCC_PLLSAIConfig(192, 7, 3);
  28.   RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8);
  29.   
  30.   /* Enable PLLSAI Clock */
  31.   RCC_PLLSAICmd(ENABLE);
  32.   /* Wait for PLLSAI activation */
  33.   while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
  34.   {
  35.   }
  36.   
  37.   /* LTDC Initialization -----------------------------------------------------*/
  38.   
  39.   /* Initialize the horizontal synchronization polarity as active low*/
  40.   LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;     
  41.   /* Initialize the vertical synchronization polarity as active low */  
  42.   LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;     
  43.   /* Initialize the data enable polarity as active low */
  44.   LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;     
  45.   /* Initialize the pixel clock polarity as input pixel clock */
  46.   LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
  47.   
  48.   /* Timing configuration */
  49.   /* Configure horizontal synchronization width */     
  50.   //LTDC_InitStruct.LTDC_HorizontalSync = 9;
  51.   LTDC_InitStruct.LTDC_HorizontalSync = 9;
  52.   /* Configure vertical synchronization height */
  53.   LTDC_InitStruct.LTDC_VerticalSync = 1;
  54.   /* Configure accumulated horizontal back porch */
  55.   LTDC_InitStruct.LTDC_AccumulatedHBP = 29;
  56.   /* Configure accumulated vertical back porch */
  57.   LTDC_InitStruct.LTDC_AccumulatedVBP = 3;  
  58.   /* Configure accumulated active width */  
  59.   LTDC_InitStruct.LTDC_AccumulatedActiveW = 269;
  60.   /* Configure accumulated active height */
  61.   LTDC_InitStruct.LTDC_AccumulatedActiveH = 323;
  62.   /* Configure total width */
  63.   LTDC_InitStruct.LTDC_TotalWidth = 279;
  64.   /* Configure total height */
  65.   LTDC_InitStruct.LTDC_TotalHeigh = 327;
  66.    
  67.   /* Configure R,G,B component values for LCD background color */                  
  68.   LTDC_InitStruct.LTDC_BackgroundRedValue = 0xff;            
  69.   LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;         
  70.   LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
  71.   
  72.   LTDC_Init(<DC_InitStruct);
  73. }

LCD串行控制信号线配置:

  1. void LCD_CtrlLinesConfig(void)
  2. {
  3.   GPIO_InitTypeDef GPIO_InitStructure;

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

  6.   /* Configure NCS in Output Push-Pull mode */
  7.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  8.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  9.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  10.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  11.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  12.   GPIO_Init(GPIOC, &GPIO_InitStructure);
  13.   
  14.   /* Configure WRX in Output Push-Pull mode */
  15.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  16.   GPIO_Init(GPIOD, &GPIO_InitStructure);

  17.   /* Set chip select pin high */
  18.   GPIO_SetBits(GPIOC, GPIO_Pin_2);
  19. }
[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)
  
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初始化:


  1. void LCD_Layer1Init(void)
  2. {
  3.   LTDC_Layer_InitTypeDef         LTDC_Layer_InitStruct;

  4.   /* Windowing configuration */
  5.   /* In this case all the active display area is used to display a picture then:
  6.   Horizontal start = horizontal synchronization + Horizontal back porch = 30
  7.   Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1
  8.   Vertical start   = vertical synchronization + vertical back porch     = 4
  9.   Vertical stop   = Vertical start + window height -1  = 4 + 160 -1      */
  10.   LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30;
  11.   LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1);
  12.   LTDC_Layer_InitStruct.LTDC_VerticalStart = 4;
  13.   LTDC_Layer_InitStruct.LTDC_VerticalStop = 320 + 4 -1;
  14.   
  15.   /* Pixel Format configuration*/           
  16.   LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
  17.   
  18.   /* Alpha constant (255 totally opaque) */
  19.   LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
  20.   
  21.   /* Configure blending factors */      
  22.   LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;   
  23.   LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;  
  24.   
  25.   /* Default Color configuration (configure A,R,G,B component values) */         
  26.   LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;        
  27.   LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;      
  28.   LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;         
  29.   LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;   
  30.   
  31.   /* Input Address configuration */   
  32.   LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (u32)FrameBuffer;
  33.   
  34.   /* the length of one line of pixels in bytes + 3 then :
  35.   Line Lenth = Active high width x number of bytes per pixel + 3
  36.   Active high width         = 240
  37.   number of bytes per pixel = 2    (pixel_format : RGB565)
  38.   */
  39.   LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 2) + 3);
  40.   
  41.   /*  the pitch is the increment from the start of one line of pixels to the
  42.   start of the next line in bytes, then :
  43.   Pitch = Active high width x number of bytes per pixel     
  44.   */
  45.   LTDC_Layer_InitStruct.LTDC_CFBPitch = (240 * 2);  
  46.   
  47.   /* configure the number of lines */
  48.   LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320;
  49.   
  50.   LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct);
  51.   LTDC_LayerCmd(LTDC_Layer1, ENABLE);
  52.   LTDC_ReloadConfig(ENABLE);
  53. }
主程序:

  1. int main(void)
  2. {
  3.   LCD_Init();
  4.   LCD_Layer1Init();
  5.   LTDC_Cmd(ENABLE);

  6.   while(1);
  7. }


 楼主| lzandyc 发表于 2016-3-16 10:19 | 显示全部楼层
你们上面所提到的都是并行的RGB通信方式,这个没有问题是可以的,目前我们用的是串行RGB的方式,不知道这个怎么弄?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部