Skip to main content
Associate III
November 6, 2024
Solved

Library For ST7567 GLCD with STM32G0B1RCT6

HI, I am trying to implement ST7567 GLCD (128x64) with SPI on my STM32G0B1RCT6 MCU. Unfortunately i am not getting the Example Driver, i tried my self but there is no improvement, So Any one Kindly send me the STM32 related ST7567 GLCD Example 

This topic has been closed for replies.
Saket_OmBest answer
ST Technical Moderator
November 12, 2024

Hello @Berlin-raj123 

I modified the example Projects/NUCLEO-G0B1RE/Examples/SPI/SPI_FullDuplex_ComDMA_Master to fit your settings. The SPI sent the data without correctly.

Please find below the used SPI configuration:

static void MX_SPI2_Init(void)
{

 /* USER CODE BEGIN SPI1_Init 0 */

 /* USER CODE END SPI1_Init 0 */

 /* USER CODE BEGIN SPI2_Init 1 */

 /* USER CODE END SPI2_Init 1 */
 /* SPI2 parameter configuration*/
 hspi2.Instance = SPI2;
 hspi2.Init.Mode = SPI_MODE_MASTER;
 hspi2.Init.Direction = SPI_DIRECTION_1LINE;
 hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
 hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
 hspi2.Init.NSS = SPI_NSS_SOFT;
 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi2.Init.CRCPolynomial = 7;
 hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
 hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
 if (HAL_SPI_Init(&hspi2) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN SPI2_Init 2 */

 /* USER CODE END SPI2_Init 2 */

}

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(hspi->Instance==SPI2)
 {
 /* USER CODE BEGIN SPI2_MspInit 0 */

 /* USER CODE END SPI2_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_SPI2_CLK_ENABLE();

 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**SPI1 GPIO Configuration
 PA0 ------> SPI1_SCK
 PC2 ------> SPI1_MISO
 PC3 ------> SPI1_MOSI
 */
 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF1_SPI2;
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_0;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF0_SPI2;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* USER CODE BEGIN SPI2_MspInit 1 */

 /* USER CODE END SPI2_MspInit 1 */
 }

}

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om

7 replies

Tesla DeLorean
Guru
November 6, 2024

Perhaps find a developer on your team that can code, or port

Get a scope or logic analyzer on the signals and confirm you have communications,and can interact with the registers, send the initialization sequences.

https://github.com/mithunkamat/ST7567-driver

https://github.com/kaushalparikh/nuttx/blob/master/drivers/lcd/st7567.c

https://www.crystalfontz.com/controllers/Sitronix/ST7567/?srsltid=AfmBOoqNqEOyPlZ8Rv645yC8ZcUo7UJmTZVt-HBAeSso8EuMHTF1lK5u

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Associate III
November 7, 2024

Initially, I just wanted to check if the SPI is working, so I used an oscilloscope. I did get a signal, but it looks different than expected. I sent a single data byte, 0xFE, but the oscilloscope on the MOSI pin shows 0x00

here are my connection IOC Connection

Clk = 64 MHZ

mode :Half Duplex Master

Data Size :8 bits

baud rate : 4MBit/S

CPOL : HIGH

CPHASE : 2 EDGE

void Write_Command_SPI(uint8_t cmd)
{
 CS_LOW();
 RS_CMD(); // Set RS pin to Command mode
 HAL_SPI_Transmit(&hspi2, &cmd, 1, HAL_MAX_DELAY);
 //RS_CMD();
 CS_HIGH();
}
// Initialize ST7567
void ST7567_Init() {
 // Reset the display
 RESET_LOW();
 HAL_Delay(50);
 RESET_HIGH();
 HAL_Delay(50);

 //Send initialization commands
 // Example initialization commands, consult ST7567 datasheet for details
 Write_Command_SPI(0xAE); // Display OFF
 Write_Command_SPI(0xA2); // Set Bias
 Write_Command_SPI(0xA0); // Set SEG Direction
 Write_Command_SPI(0xC8); // Set COM Direction
 Write_Command_SPI(0xA4); // Disable Entire Display ON
 Write_Command_SPI(0xA6); // Normal Display
 Write_Command_SPI(0x2F); // Power Control
 Write_Command_SPI(0x27); // Set Contrast
 Write_Command_SPI(0x81); // Set Electronic Volume
 Write_Command_SPI(0x10); // Set Volume
 Write_Command_SPI(0xAF); // Display ON
}
main()
{ 
 MX_SPI2_Init();
 /* USER CODE BEGIN 2 */
 // Initialize the ST7567 display
 //ST7567_Init();

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
	 // Send test data periodically for SPI signal check
	 Write_Command_SPI(0xFE);
	 HAL_Delay(100); // Wait 100ms to easily observe SPI signals on CRO
 }

 

how to get the single data?WhatsApp Image 2024-11-07 at 7.14.51 PM.jpeg

gbm
Super User
November 7, 2024

Connect the probe to MOSI. Currently it looks like it's connected to SCK.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice