Hi everybody
I tried to use ST7920 and stm32f030 via 3 wire software spi.
my code is:
//----------------------------------------------------------
uint8_t u8g2_gpio_and_delay_stm32(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
{
switch(msg){
//Initialize SPI peripheral
case U8X8_MSG_GPIO_AND_DELAY_INIT:
/* HAL initialization contains all what we need so we can skip this part. */
HAL_Delay(1);
break;
//Function which implements a delay, arg_int contains the amount of ms
case U8X8_MSG_DELAY_MILLI:
HAL_Delay(arg_int);
break;
//Function which delays 10us
case U8X8_MSG_DELAY_10MICRO:
for (uint16_t n = 0; n < 320; n++)
{
__NOP();
}
//HAL_Delay(1);
break;
//Function which delays 100ns
case U8X8_MSG_DELAY_100NANO:
__NOP();
//HAL_Delay(1);
break;
//Function to define the logic level of the clockline
//case U8X8_MSG_GPIO_D0:
case U8X8_MSG_GPIO_SPI_CLOCK:
if (arg_int)
HAL_GPIO_WritePin(SCK_GPIO_Port, SCK_Pin, GPIO_PIN_SET);
else
HAL_GPIO_WritePin(SCK_GPIO_Port, SCK_Pin, GPIO_PIN_RESET);
break;
//Function to define the logic level of the data line to the display
case U8X8_MSG_GPIO_SPI_DATA:
//case U8X8_MSG_GPIO_D1:
if (arg_int)
HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_SET);
else
HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_RESET);
break;
// Function to define the logic level of the CS line
case U8X8_MSG_GPIO_CS:
if (arg_int)
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
else
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_RESET);
break;
//Function to define the logic level of the Data/ Command line
case U8X8_MSG_GPIO_DC:
// if (arg_int) HAL_GPIO_WritePin(CD_LCD_PORT, CD_LCD_PIN, GPIO_PIN_SET);
// else HAL_GPIO_WritePin(CD_LCD_PORT, CD_LCD_PIN, GPIO_PIN_RESET);
break;
//Function to define the logic level of the GPIO_PIN_RESET line
case U8X8_MSG_GPIO_RESET:
// if (arg_int)
// HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_SET);
// else
// HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET);
break;
default:
return 0; //A message was received which is not implemented, return 0 to indicate an error
}
return 1; // command processed successfully.
}
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
u8g2_t u8g2;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
u8g2_Setup_st7920_p_128x64_1(&u8g2, U8G2_R0, u8x8_byte_3wire_sw_spi, u8g2_gpio_and_delay_stm32);
//u8g2_Setup_st7920_s_128x64_f(&u8g2, U8G2_R0, u8x8_byte_3wire_sw_spi, u8g2_gpio_and_delay_stm32);
u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
u8g2_SetPowerSave(&u8g2, 0); // wake up display
// HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET);
// HAL_Delay(100);
// HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_SET);
// HAL_Delay(200);
HAL_Delay(1000);
u8g2_DrawLine(&u8g2, 50,50, 100, 100);
u8g2_SendBuffer(&u8g2);
HAL_Delay(1000);
ST7920_SendString(1,0,"U8G2");
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Hi everybody I tried to use ST7920 and stm32f030 via 3 wire software spi. my code is:
and
and also connected the psb to gnd. but that did not work and showed nothing! how can i coupe this issue thanks