olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
4.91k stars 1.02k forks source link

STM32F4 t6963 interfacing usage #2434

Closed AndreAhmed closed 1 month ago

AndreAhmed commented 2 months ago

Hello Guys, I'm in a trouble. I'm trying to interface an LCD t6963 based controller, and I'm using STM32F4, now I'm trying to use u8g2 lib for interfacing with the LCD. My problem right now is how to configure the GPIO pins for Data and for control. From my experience, before Setting a GPIO to Output or to Read, I have to use stm32Hal to reinit the port/pin, to be output or input. But in u8g2, it has a call back, that just set the pin to reset or set, How can I make that work, in case that GPIO data port if it's as input or output ?

also how do I clear a pixel at position ?

uint8_t u8x8_stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
    switch(msg)
    {
    case U8X8_MSG_GPIO_AND_DELAY_INIT:
        /* Insert codes for initialization */
        break;
    case U8X8_MSG_DELAY_MILLI:
        /* ms Delay */
        HAL_Delay(arg_int);
        break;
    case U8X8_MSG_GPIO_CS:
        /* Insert codes for SS pin control */
        HAL_GPIO_WritePin(CE_GPIO_Port, CE_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_DC:
        /* Insert codes for DC pin control */
        HAL_GPIO_WritePin(CD_GPIO_Port, CD_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_RESET:
        /* Insert codes for RST pin control */
        HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, arg_int);
        break;
    }

    case U8X8_MSG_GPIO_D0:              // D0 or SPI clock pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);
      break;
    case U8X8_MSG_GPIO_D1:              // D1 or SPI data pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);
      break;
    case U8X8_MSG_GPIO_D2:              // D2 pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

      break;
    case U8X8_MSG_GPIO_D3:              // D3 pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

      break;
    case U8X8_MSG_GPIO_D4:              // D4 pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

      break;
    case U8X8_MSG_GPIO_D5:              // D5 pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

      break;
    case U8X8_MSG_GPIO_D6:              // D6 pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

      break;
    case U8X8_MSG_GPIO_D7:              // D7 pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

    default:
      u8x8_SetGPIOResult(u8x8, 1);          // default return value
      break;

    return 1;
}

and here the GPIO_INIT

 GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  /*Configure GPIO pins : PA0 PA1 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PA2 PA3 PA4 */
  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USER CODE BEGIN MX_GPIO_Init_2 */

  /* GPIO Ports Clock Enable */

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, WR_Pin|RD_Pin|CE_Pin|CD_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOF, D0_Pin|D1_Pin|D2_Pin|D3_Pin
                          |D4_Pin|D5_Pin|D6_Pin|D7_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LCD_RST_Pin */
  GPIO_InitStruct.Pin = LCD_RST_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LCD_RST_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : WR_Pin RD_Pin CE_Pin CD_Pin */
  GPIO_InitStruct.Pin = WR_Pin|RD_Pin|CE_Pin|CD_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pin : LCD_BL_Pin */
  GPIO_InitStruct.Pin = LCD_BL_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LCD_BL_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : D0_Pin D1_Pin D2_Pin D3_Pin
                           D4_Pin D5_Pin D6_Pin D7_Pin */
  GPIO_InitStruct.Pin = D0_Pin|D1_Pin|D2_Pin|D3_Pin
                          |D4_Pin|D5_Pin|D6_Pin|D7_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
olikraus commented 2 months ago

Maybe a complete different solution could be to use stm32duino project.

AndreAhmed commented 2 months ago

Can you link it please?

AndreAhmed commented 2 months ago

Here is the link for the Lcd https://www.buydisplay.com/graphic-lcd-240x64-module-display-ra6963-fully-compatible-with-t6963

olikraus commented 2 months ago

Can you link it please?

For stm32duino? It is here: https://github.com/stm32duino

STM32Duino is a extension to the Arduino IDE. It will make almost any STM32 compatible with Arduino. U8g2 will then work out of the box.

AndreAhmed commented 2 months ago

@olikraus Can you check the display please if it needs any special pin configuration, for example negative CS,WR?

olikraus commented 2 months ago

there seems to be a copy & paste error in your code:

    case U8X8_MSG_GPIO_D1:              // D1 or SPI data pin: Output level in arg_int
        HAL_GPIO_WritePin(DATA_PORT, D0_Pin, arg_int);

D0_Pin probably should be D1_Pin. Same issues for the other pins also...

AndreAhmed commented 2 months ago

@olikraus Sorry I fixed that already in my code, but I still don't get any display, any other things needed for logic to work ? I mean PIN configuration or PIN Logic state ?

olikraus commented 2 months ago

it looks like a standard T6963 display, which should work out of the box with u8g2. Did you add a proper var-pot like show here: https://www.buydisplay.com/download/interfacing/ERM24064-1_Interfacing.pdf ?

AndreAhmed commented 2 months ago

@olikraus Yes I added it, no display is showing

olikraus commented 2 months ago

Then... I assume a wiring error...

AndreAhmed commented 2 months ago

@olikraus After MX_GPIO Init, I get horizontal line in the display, before u8g2 init, after its init, it goes out. that's very weird ? any idea? I have doubled checked the connection, its correct

AndreAhmed commented 2 months ago

@olikraus I negated the reset pin in code, and I have two lines now... I'm drawing a string and a picture

AndreAhmed commented 2 months ago
 /* USER CODE BEGIN 2 */
  u8g2_Setup_t6963_240x64_f(&u8g2, U8G2_R0,u8x8_byte_8bit_8080mode, u8x8_stm32_gpio_and_delay);

  u8g2_InitDisplay(&u8g2);
  u8g2_SetPowerSave(&u8g2, 0);
    // clear VRAM
    for (int y=0;y<LCD_ys;y++)
        for (int x=0;x<LCD_xs>>3;x++)
            VRAM[y][x]=col0;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
    while (1)
    {
        u8g2_ClearBuffer(&u8g2);

        u8g2_SetDrawColor(&u8g2,1);
        u8g2_DrawCircle(&u8g2, 20, 20, 20, U8G2_DRAW_ALL);
        u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tr);
        u8g2_DrawStr(&u8g2, 0, 15, "Tarkan");

        for(int i = 0; i < 200; i++)
        {
            u8g2_DrawPixel(&u8g2, i, i);
        }
        u8g2_SendBuffer(&u8g2);
AndreAhmed commented 2 months ago

Running this, I get a line Without even Initializing the display

  __HAL_RCC_GPIOE_CLK_ENABLE();
   GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9
                          |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_0
                          |GPIO_PIN_1;

  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
AndreAhmed commented 2 months ago

I also noticed something very weird, when I remove pin 3 VDD which is 5V, and at power the MCU, I see the LCD is working(light on), how come ?!

that's their sample app image

AndreAhmed commented 2 months ago
uint8_t u8x8_stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
    switch(msg)
    {
    case U8X8_MSG_GPIO_AND_DELAY_INIT:
        /* Insert codes for initialization */
        break;
    case U8X8_MSG_DELAY_10MICRO:
        for (uint16_t n = 0; n < 320; n++)
        {
            __NOP();
        }
        break;
    case U8X8_MSG_DELAY_NANO:
        delay_ns(arg_int);

        break;
    case U8X8_MSG_DELAY_100NANO:
        for(int i = 0; i < 100; i++)
        {
            delay_ns(1);
        }
        break;
    case U8X8_MSG_DELAY_MILLI:
        /* ms Delay */
        HAL_Delay(arg_int);
        break;
    case U8X8_MSG_GPIO_E:
        /* Insert codes for SS pin control */
        HAL_GPIO_WritePin(GPIOE, WR_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_CS:
        /* Insert codes for SS pin control */
        HAL_GPIO_WritePin(GPIOE, CE_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_DC:
        /* Insert codes for DC pin control */
        HAL_GPIO_WritePin(GPIOE, CD_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_RESET:
        /* Insert codes for RST pin control */
        HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, arg_int);
        break;

    case U8X8_MSG_GPIO_D0:              // D0 or SPI clock pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D0_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_D1:              // D1 or SPI data pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D1_Pin, arg_int);
        break;
    case U8X8_MSG_GPIO_D2:              // D2 pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D2_Pin, arg_int);

        break;
    case U8X8_MSG_GPIO_D3:              // D3 pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D3_Pin, arg_int);

        break;
    case U8X8_MSG_GPIO_D4:              // D4 pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D4_Pin, arg_int);

        break;
    case U8X8_MSG_GPIO_D5:              // D5 pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D5_Pin, arg_int);

        break;
    case U8X8_MSG_GPIO_D6:              // D6 pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D6_Pin, arg_int);

        break;
    case U8X8_MSG_GPIO_D7:              // D7 pin: Output level in arg_int
        HAL_GPIO_WritePin(GPIOE, D7_Pin, arg_int);
        break;

    default:
        u8x8_SetGPIOResult(u8x8, 1);            // default return value
        break;
    }

    return 1;
}``
AndreAhmed commented 2 months ago

WhatsApp Image 2024-05-01 at 03 10 38_57989046

AndreAhmed commented 2 months ago

@olikraus I have followed your advice and used stm32arduino, and still no output to the display I used graphics test as example image WhatsApp Image 2024-05-01 at 16 44 27_bcf71afc WhatsApp Image 2024-05-01 at 16 44 27_4f5bc05c WhatsApp Image 2024-05-01 at 16 44 27_8e4ce065

olikraus commented 1 month ago

I am a little bit confused by the purple ERM2 graphics LCD connector. What exactly is the purpose of this device. What is the schematic for this purple add on board?