Whenever I want to make a screen display, I will look for a screen with few pins and easy to drive. I originally wanted to use a real SPI driver, but there is no pin as fast as that.
I think I'll do it in two steps, and work on the hardware later... I don't know when, but probably in winter.
Let me talk about my screen first.
Here is the SPI specification:
Why can't I add it? It should be in the attachment.
01-规格书+驱动芯片手册.zip
(3.27 MB, downloads: 2)
Then add the pins you need: I use PA11, PA12, PB11, PB12, power and ground are not counted, just plug it in.
Then, create the entire OLED file as an OLED subdirectory and put it in the root directory of this program.
In the oled.h file, change the definition of the pin, and the initialization is automatically completed in STM32CUBEMX
//-----------------OLED端口定义----------------
#define OLED_SCLK_Clr() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);//GPIO_ResetBits(GPIOB,GPIO_Pins_12)//CLK
#define OLED_SCLK_Set() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);//GPIO_SetBits(GPIOB,GPIO_Pins_12)
#define OLED_SDIN_Clr() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);//GPIO_ResetBits(GPIOB,GPIO_Pins_13)//DIN
#define OLED_SDIN_Set() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);//GPIO_SetBits(GPIOB,GPIO_Pins_13)
#define OLED_RST_Clr() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);//GPIO_ResetBits(GPIOB,GPIO_Pins_14)//RES
#define OLED_RST_Set() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);//GPIO_SetBits(GPIOB,GPIO_Pins_14)
#define OLED_DC_Clr() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);//GPIO_ResetBits(GPIOB,GPIO_Pins_15)//DC
#define OLED_DC_Set() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);//GPIO_SetBits(GPIOB,GPIO_Pins_15)
Then include this header file in the main function. When initializing, be sure to connect each pin to high level immediately after initialization. This took me half a day.
//OLED_CS_Clr(); //打开片选使能
OLED_SCLK_Set()
OLED_SDIN_Set()
OLED_RST_Set();
HAL_Delay(1);
OLED_RST_Clr();
HAL_Delay(20);
OLED_RST_Set();
HAL_Delay(20);
//OLED_BLK_Set();
//************* Start Initial Sequence **********//
LCD_WR_REG(0x36);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA8(0x19);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x12);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA8(0xA4);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x54);
LCD_WR_DATA8(0x4C);
LCD_WR_DATA8(0x18);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0B);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x44);
LCD_WR_DATA8(0x51);
LCD_WR_DATA8(0x2F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x20);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x11);
//Delay (120);
LCD_WR_REG(0x29);
At first, there is no initial value set for the pin, so it can't be driven. I tried for a long time but couldn't figure it out. I changed the pin definition and the clock to the clock divided by 4, but it still didn't work.
Finally, I added an initial value and it was done.
Add a variable to the default task and then display it. There is no meaning, just display it.
Another bad thing about STM32CUBEMX is that once it is reset, the previously defined settings are gone.
Now if I want to complete the previous tasks, I have to refer to the previous posts and build them up slowly.
Here are the photos:
How should I put it? In the future, I will use the FREERTOS of the display department. This time, I uploaded the OLED package so that I won't be lost next time.
OLED.rar
(10.17 KB, downloads: 0)