2024-11-06 05:23 AM - last edited on 2024-11-06 06:36 AM by Andrew Neil
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
Solved! Go to Solution.
2024-11-12 05:48 AM
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 */
}
}
2024-11-06 06:13 AM
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
2024-11-07 05:50 AM
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?
2024-11-07 07:12 AM
Connect the probe to MOSI. Currently it looks like it's connected to SCK.
2024-11-07 07:39 AM
no dude! i connected everything correctly
2024-11-07 07:50 AM
I verified hardware connection, as per our connection set up,
Controller - SPI2 CLK is connected to CRO channel1 SCK
Controller - SPI2 MOSI is connected to CRO channel3 MOSI
Controller - SPI2 CS is connected to CRO channel4 CS
2024-11-07 08:06 PM
Anyone please help me!! i am waiting for your response
2024-11-12 05:48 AM
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 */
}
}