cancel
Showing results for 
Search instead for 
Did you mean: 

SPI2 in stm32f429 is not working while touchgfx and lcd config functions are added, however works fine if i comment the lcd config function and touchgfx init.

Eivor
Associate II

The lcd configuration uses LTDC(for data) and SPI5 for sending commands. The display driver used is ili9341.

system clock configuration is as below.

/**

 * @brief System Clock Configuration

 *     The system Clock is configured as follow :

 *      System Clock source      = PLL (HSE)

 *      SYSCLK(Hz)           = 168000000

 *      HCLK(Hz)            = 168000000

 *      AHB Prescaler         = 1

 *      APB1 Prescaler         = 4

 *      APB2 Prescaler         = 2

 *      HSE Frequency(Hz)       = 8000000

 *      PLL_M             = 8

 *      PLL_N             = 336

 *      PLL_P             = 2

 *      PLL_Q             = 7

 *      VDD(V)             = 3.3

 *      Main regulator output voltage = Scale1 mode

 *      Flash Latency(WS)       = 5

 * @param None

 * @retval None

 */

static void SystemClock_Config(void)

{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable Power Control clock */

  __HAL_RCC_PWR_CLK_ENABLE();

  /* The voltage scaling allows optimizing the power consumption when the device is

   clocked below the maximum system frequency, to update the voltage scaling value

   regarding system frequency refer to product datasheet. */

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /* Enable HSE Oscillator and activate PLL with HSE as source */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLM = 8;

  RCC_OscInitStruct.PLL.PLLN = 336;

  RCC_OscInitStruct.PLL.PLLP = 2;

  RCC_OscInitStruct.PLL.PLLQ = 7;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2

   clocks dividers */

  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

}

I'm using SPI2 to send command from display board to another custom board.

please help.

3 REPLIES 3
MM..1
Chief III

Maybe you mix GPIO functions , you need check LTDC RGB and reset pin isnt in conflict with SPI2...

Eivor
Associate II

I checked, the pins aren't conflict. I just found out that even hal_delay function is affecting SPI2. could this be due to any mistake in

    static uint8_t LCD_Init(void)
    {
        /* On STM32F429I-DISCO, it is not possible to read ILI9341 ID because */
        /* PIN EXTC is not connected to VDD and then LCD_READ_ID4 is not accessible. */
        /* In this case, ReadID function is bypassed.*/
        /*if(ili9341_drv.ReadID() == ILI9341_ID)*/
 
        /* LTDC Configuration ----------------------------------------------------*/
        LtdcHandler.Instance = LTDC;
 
        /* Timing configuration  (Typical configuration from ILI9341 datasheet)
              HSYNC=10 (9+1)
              HBP=20 (29-10+1)
              ActiveW=240 (269-20-10+1)
              HFP=10 (279-240-20-10+1)
 
              VSYNC=2 (1+1)
              VBP=2 (3-2+1)
              ActiveH=320 (323-2-2+1)
              VFP=4 (327-320-2-2+1)
          */
 
        
       /* Configure horizontal synchronization width */
        LtdcHandler.Init.HorizontalSync = ILI9341_HSYNC;
        /* Configure vertical synchronization height */
        LtdcHandler.Init.VerticalSync = ILI9341_VSYNC;
        /* Configure accumulated horizontal back porch */
        LtdcHandler.Init.AccumulatedHBP = ILI9341_HBP;
        /* Configure accumulated vertical back porch */
        LtdcHandler.Init.AccumulatedVBP = ILI9341_VBP;
        /* Configure accumulated active width */
        LtdcHandler.Init.AccumulatedActiveW = 484; 
        /* Configure accumulated active height */
        LtdcHandler.Init.AccumulatedActiveH = 274;
        /* Configure total width */
        LtdcHandler.Init.TotalWidth = 526;//531
        /* Configure total height */
        LtdcHandler.Init.TotalHeigh = 286;//292
 
 
        /* Configure R,G,B component values for LCD background color */
        LtdcHandler.Init.Backcolor.Red = 0;
        LtdcHandler.Init.Backcolor.Blue = 0;
        LtdcHandler.Init.Backcolor.Green = 0;
 
        /* LCD clock configuration */
        /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
        /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
        /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
        /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
        PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
        PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
        PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
        PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
        HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
 
        /* Polarity */
        LtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
        LtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
        LtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
        LtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
 
        LCD_MspInit();
        HAL_LTDC_Init(&LtdcHandler);
 
        /* Select the device */
        LcdDrv = &ili9341_drv;
 
        /* LCD Init */
        LcdDrv->Init();
 
        /* Initialize the SDRAM */
        BSP_SDRAM_Init();                                                
 
        return 0;
    }

system clock configuration or systick configuration? when i comment out LcdDrv->Init() the SPI works. what's inside this function is below.

  LCD_IO_Init();
  
  /* Configure LCD */
  ili9341_WriteReg(0xCA);
  ili9341_WriteData(0xC3);
  ili9341_WriteData(0x08);
  ili9341_WriteData(0x50);
  ili9341_WriteReg(LCD_POWERB);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0xC1);
  ili9341_WriteData(0x30);
  ili9341_WriteReg(LCD_POWER_SEQ);
  ili9341_WriteData(0x64);
  ili9341_WriteData(0x03);
  ili9341_WriteData(0x12);
  ili9341_WriteData(0x81);
  ili9341_WriteReg(LCD_DTCA);
  ili9341_WriteData(0x85);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x78);
  ili9341_WriteReg(LCD_POWERA);
  ili9341_WriteData(0x39);
  ili9341_WriteData(0x2C);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x34);
  ili9341_WriteData(0x02);
  ili9341_WriteReg(LCD_PRC);
  ili9341_WriteData(0x20);
  ili9341_WriteReg(LCD_DTCB);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x00);
  ili9341_WriteReg(LCD_FRMCTR1);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x1B);
  ili9341_WriteReg(LCD_DFC);
  ili9341_WriteData(0x0A);
  ili9341_WriteData(0xA2);
  ili9341_WriteReg(LCD_POWER1);
  ili9341_WriteData(0x10);
  ili9341_WriteReg(LCD_POWER2);
  ili9341_WriteData(0x10);
  ili9341_WriteReg(LCD_VCOM1);
  ili9341_WriteData(0x45);
  ili9341_WriteData(0x15);
  ili9341_WriteReg(LCD_VCOM2);
  ili9341_WriteData(0x90);
  ili9341_WriteReg(LCD_MAC);
  ili9341_WriteData(0xC8);
  ili9341_WriteReg(LCD_3GAMMA_EN);
  ili9341_WriteData(0x00);
  ili9341_WriteReg(LCD_RGB_INTERFACE);
  ili9341_WriteData(0xC2);
  ili9341_WriteReg(LCD_DFC);
  ili9341_WriteData(0x0A);
  ili9341_WriteData(0xA7);
  ili9341_WriteData(0x27);
  ili9341_WriteData(0x04);
  
  /* Colomn address set */
  ili9341_WriteReg(LCD_COLUMN_ADDR);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0xEF);
  /* Page address set */
  ili9341_WriteReg(LCD_PAGE_ADDR);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x01);
  ili9341_WriteData(0x3F);
  ili9341_WriteReg(LCD_INTERFACE);
  ili9341_WriteData(0x01);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x06);
  
  ili9341_WriteReg(LCD_GRAM);
  LCD_Delay(200);
  
  ili9341_WriteReg(LCD_GAMMA);
  ili9341_WriteData(0x01);
  
  ili9341_WriteReg(LCD_PGAMMA);
  ili9341_WriteData(0x0F);
  ili9341_WriteData(0x29);
  ili9341_WriteData(0x24);
  ili9341_WriteData(0x0C);
  ili9341_WriteData(0x0E);
  ili9341_WriteData(0x09);
  ili9341_WriteData(0x4E);
  ili9341_WriteData(0x78);
  ili9341_WriteData(0x3C);
  ili9341_WriteData(0x09);
  ili9341_WriteData(0x13);
  ili9341_WriteData(0x05);
  ili9341_WriteData(0x17);
  ili9341_WriteData(0x11);
  ili9341_WriteData(0x00);
  ili9341_WriteReg(LCD_NGAMMA);
  ili9341_WriteData(0x00);
  ili9341_WriteData(0x16);
  ili9341_WriteData(0x1B);
  ili9341_WriteData(0x04);
  ili9341_WriteData(0x11);
  ili9341_WriteData(0x07);
  ili9341_WriteData(0x31);
  ili9341_WriteData(0x33);
  ili9341_WriteData(0x42);
  ili9341_WriteData(0x05);
  ili9341_WriteData(0x0C);
  ili9341_WriteData(0x0A);
  ili9341_WriteData(0x28);
  ili9341_WriteData(0x2F);
  ili9341_WriteData(0x0F);
  
  ili9341_WriteReg(LCD_SLEEP_OUT);
  LCD_Delay(200);
  ili9341_WriteReg(LCD_DISPLAY_ON);
  /* GRAM start writing */
  ili9341_WriteReg(LCD_GRAM);

the function LCD_IO_Init(); sets up SPI5 for sending commands to the LCD panel and ili9341_WriteReg() functions sends commands to display via SPI5.

Eivor
Associate II

This same problem happens with the touch controller initialization as well.

void gt911_init(void)
{
	uint16_t i,j;
	uint8_t tx_buffer;
 
	/*INT pin :PA15 set as output for resetting GT911*/
	INT_GPIO_InitStruct.Pin = GPIO_PIN_15;
  INT_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  INT_GPIO_InitStruct.Pull = GPIO_NOPULL;
  INT_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOA, &INT_GPIO_InitStruct);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);        // 12 us signal from low to high INT pin
	
	gt911_I2C3_Init();	
	
	for(j=0;j<5;j++)
	{
		for(i=0;i<186;i++)
		{
			
			HAL_I2C_Mem_Write(&hi2c3, GT9_ADDRESS, 0x8047+i, I2C_MEMADD_SIZE_16BIT, &gt911_conf[i], 1, 2000);
		}
	}
  HAL_Delay(200);			//time for GT911 to finish setting up
 
	tx_buffer = 0x00;
	HAL_I2C_Mem_Write(&hi2c3, GT9_ADDRESS, 0x8040, I2C_MEMADD_SIZE_16BIT, &tx_buffer, 1, 2000);
	
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
  HAL_Delay(100);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
	
	/*INT pin :PA15 set as input for make*/
	INT_GPIO_InitStruct.Pin = GPIO_PIN_15;
  INT_GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  INT_GPIO_InitStruct.Pull = GPIO_NOPULL;
  INT_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOA, &INT_GPIO_InitStruct);
}

The SPI would only work if i comment HAL_I2C_Mem_Write() function and hal_delay() function.