SH1122 256x64 vertical looping offset after a few minutes of running
Author: TrevorCashCreated Jun 15, 2026Updated Jun 27, 2026
I am using the SH1122 Driver with SPI on a STM32 platform.
It runs well and seems stable until after a few minutes something causes the screen to be vertically offset with the bottom content drawn on the top of the display and everything else shifted downward.
Are there known causes of this this? Is there a way to reset the vertical offset each frame ?
uint8_t u8x8_stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
/* STM32 supports HW SPI, Remove unused cases like U8X8_MSG_DELAY_XXX & U8X8_MSG_GPIO_XXX */
switch(msg)
{
case U8X8_MSG_GPIO_AND_DELAY_INIT:
/* Insert codes for initialization */
break;
case U8X8_MSG_DELAY_MILLI:
/* ms Delay */
//dont actually need delay here.
break;
case U8X8_MSG_GPIO_CS:
/* Insert codes for SS pin control */
HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, (GPIO_PinState)arg_int);
break;
case U8X8_MSG_GPIO_DC:
/* Insert codes for DC pin control */
HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, (GPIO_PinState)arg_int);
break;
case U8X8_MSG_GPIO_RESET:
/* Insert codes for RST pin control */
HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, (GPIO_PinState)arg_int);
break;
}
return 1;
}
uint8_t u8x8_byte_stm32_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
HAL_StatusTypeDef status;
switch(msg) {
case U8X8_MSG_BYTE_SEND:
{
/* Insert codes to transmit data */
status = HAL_SPI_Transmit(&hspi2, (uint8_t*)arg_ptr, arg_int, 1000);
if(status != HAL_OK)
Error_Handler();
break;
}
case U8X8_MSG_BYTE_INIT:
/* Insert codes to begin SPI transmission */
break;
case U8X8_MSG_BYTE_SET_DC:
{
/* Control DC pin, U8X8_MSG_GPIO_DC will be called */
u8x8_gpio_SetDC(u8x8, arg_int);
break;
}
case U8X8_MSG_BYTE_START_TRANSFER:
{
/* Select slave, U8X8_MSG_GPIO_CS will be called */
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
break;
}
case U8X8_MSG_BYTE_END_TRANSFER:
{
/* Insert codes to end SPI transmission */
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
tx_thread_relinquish();
break;
}
default:
return 0;
}
return 1;
}
Any Tips/Help Appreciated!
Source: olikraus/u8g2