
本文来源:http://www.lpqz.cn/news/110227
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
接手过ST7567这颗驱动IC的朋友应该都懂最容易让人崩溃的不是它有多复杂而是明明照着别人的代码抄了一遍屏就是不亮或者白屏一片怀疑自己焊坏了屏。上个月帮一个网友调了一块12864“串口屏”他把初始化代码发给我看命令和时序表面上都没问题最后用万用表量了一圈发现模块上的PS引脚悬空了串行模式根本没被选中。这让我决定把这几年调ST7567屏踩过的坑系统整理一遍尤其是标题里提到的引脚电平、复位时序和对比度调节这三块每一个都能让屏“看起来坏了”。这里要先把一个容易混淆的概念说清楚标题里的“串口屏”指的是采用ST7567控制器的SPI串行接口单色LCD屏不是那种通过UART发指令控制的大彩屏、迪文屏。后者是带智能协议的主控屏驱动逻辑完全不同。本文所有内容只针对ST7567这种通过SPI写入像素数据的液晶屏。文章内容全部来自我自己的调试记录适合正在用STM32裸机驱动这种屏、又遇到白屏花屏问题的朋友参考
。1. ST7567“串口屏”到底是什么接口类型与引脚电平的坑1.1 “串口屏”这个叫法最容易造成的误会很多淘宝店的标题把ST7567的12864屏叫“串口屏”新同学买回来以为像串口屏一样两根线发字符就行结果发现根本不出字。这里必须明确ST7567是一颗纯液晶驱动芯片本身没有任何中文字库更没有串口协议解析功能。它所谓的“串口”只是说这颗IC支持串行SPI接口输入显示数据大小和普通的8128像素LCD一样显示内容需要单片机一页一页地写进去。ST7567本身支持8080并口、6800并口和4线SPI串行接口三种方式模块上通常只把其中一种或两种引出来。串口模式使用SCL作为时钟、SI很多模块标成SDA或MOSI作为数据输入、A0也叫RS、DC区分命令与数据、CS作为片选。你买的模块如果只引出了这几个接口说明厂家已经默认工作在串行模式。如果模块还引出了更多引脚比如DB0到DB7那你需要先检查PS或
者PSB引脚确认它被正确设置为串行模式。1.2 最小硬件连接与逻辑电平兼容性先列一个最常用的接线方式这是ST7567屏在串口模式下的最小系统连接ST7567模块引脚STM32引脚说明VDD3.3V逻辑电源绝大多数模块为3.3VVSSGND地CSPA4片选低有效A0RSPA3命令/数据选择低为命令、高为数据SCLPA2SPI时钟SISDAPA1SPI数据输入RSTPA0复位低有效LEDA/LEDK3.3V或5V加限流电阻背光极性别接反引脚电平这块是标题里第一个核心坑。ST7567的VDD典型工作电压是3.3V数据手册里的输入高电平阈值一般是0.7倍VDD左右也就是说VDD3.3V时只要高电平超过2.31V就能稳定识别STM32的3.3V推挽输出完全没问题。但如果你图方便把5V接到了VDD上事情就变了。VDD5V时输入高电平阈值变成3.5VSTM32的3.3V高电平虽然勉强接近但这个电压已经不
够裕量再加上连线阻抗、板内压降很容易出现“时好时坏”的间歇性白屏。我见过一个案例初始化命令偶尔生效、偶尔不生效就是VDD接了5V又没做电平转换。如果你必须用5V供电请在SCL、SI、A0、CS、RST这几根线上加电平转换电路别直接拿3.3V推5V逻辑输入。还有一个需要注意的背光供电最好和逻辑供电分开。很多模块的LEDA引脚没有内置限流电阻直接接5V可能过流建议串一个10到100欧的电阻根据背光亮度实测调整。2. 引脚电平与SPI连接里那些“看起来正常”的陷阱2.1 PS引脚的串/并选择是最隐蔽的开关PS引脚在ST7567的数据手册里叫串行/并行接口选择有些模块会把它引出来有些模块直接在PCB上用焊锡焊接选择。这个引脚如果被拉高芯片工作在并口模式你不管怎么发SPI命令屏幕都不会有任何反应。我遇到的实际情况是某款模块的PS引脚被引出到排针但厂家没有在丝印上写清楚它到底需要接高还是接低。当时我只
按常规接了VDD、GND和SPI四根线PS悬空结果屏幕永远是白屏。用万用表量PS排针电压发现是浮空的不确认是高是低芯片内部状态完全不确定。后来把PS接GND屏幕立刻有反应。排查这类问题时第一件事就是翻模块原理图或者数据手册确认PS引脚的电平要求。ST7567在串行模式时PS必须拉低具体以你的模块丝印为准。如果模块没有引出PS那一般已经硬接好了就不需要管它。2.2 JTAG复用引脚和GPIO配置的暗坑引脚电平的另一个经典坑是用了STM32上电默认被JTAG占用的引脚。这类引脚包括PA13、PA14、PA15、PB3、PB4。很多教程喜欢把SCL放在PB3、SDA放在PB4或者在PA15上接CS看起来完全没有问题因为代码里也做了GPIO初始化。但STM32F103的这些引脚在芯片上电后默认不是普通IO而是JTAG调试接口。你把GPIO模式配置成推挽输出写高电平它可能拉不起来或者写低电平也不受控
制。屏幕表现出来的症状就是SPI波形不对发命令毫无反应。解决办法有两个。第一个是避开这些引脚重新画接线用PC13、PA0、PA1这些普通引脚这是最省心的方案。第二个是使用重映射功能GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);这行代码的作用是关闭JTAG、保留SWD执行之后PA15、PB3、PB4才能当普通IO用。不过我建议如果屏对引脚没有硬性要求直接换引脚更稳妥毕竟重映射代码写错或者下载前没设置好可能导致下载器连不上芯片。2.3 硬件SPI和模拟SPI怎么选ST7567的串行SPI频率上限并不高很多模块的SCL时钟最快也就2MHz左右STM32跑72MHz主频时如果直接AHC最高分频到18MHz去发数据大概率花屏或者乱码。我用硬件SPI时习惯把波特率预分频设成64也就是1.125MHz左右完全够用而且特别稳。硬件SPI的极
性选择也很容易踩坑。ST7567的串行时序是SCL空闲为低、数据在SCL上升沿被采样对应SPI Mode0也就是CPOLLow、CPHA1Edge。实际使用中Mode3有时也能工作但我不推荐赌这种兼容性老老实实用Mode0最保险。但我自己更喜欢用模拟GPIO去实现SPI原因很简单时序完全可控不容易受主频分频影响而且调试时可以很直观地看每一位的电平是否正确。模拟SPI写一个字节的核心逻辑如下void ST7567_SPI_WriteByte(uint8_t dat) { for (uint8_t i 0; i 8; i) { SCL_L(); if (dat 0x80) SDA_H(); else SDA_L(); dat 1; SCL_H(); // 上升沿ST7567采样数据 } }注意这里必须先拉低SCL然后改变SDA电平再拉高SCL。如果SCL拉高期间SDA还在变采样到的数据
就是错的。这样写虽然比硬件SPI慢一些但驱动一块12864的单色屏完全够用。3. 复位时序一个最容易“偶发白屏”的环节3.1 规格书上没写明白的上电细节很多人的初始化代码里复位时序只是象征性地拉低、拉高没有去认真思考上电后芯片处于什么状态。ST7567上电后内部电路需要一个VDD从0爬升到稳定值的过程。如果你在VDD还没稳定时就执行复位和初始化命令芯片可能根本没有正确进入工作状态表现出来就是偶发白屏按一下复位键又正常了。我通常这样处理先等主控上电稳定至少延时100ms再去碰屏的引脚然后执行复位脉冲。不要上电后立刻初始化更不要和STM32的SystemInit挤在同一个瞬间去操作外设。单片机上电后跑得比屏的电源稳定快得多这个时间差必须用Delay补上。复位引脚的实际操作我会给出一个偏保守但足够可靠的时序LCD_RST_H(); DelayMs(10); LCD_RST_L(); DelayM
s(20); // RST低电平维持20ms LCD_RST_H(); DelayMs(50); // 复位释放后等待50ms再发命令为什么这么长的延迟因为不同厂家模块在ST7567前面可能还搭了电平转换或者滤波电路RC时间常数不一样。数据手册上的最小复位脉宽只有1微秒左右但工程上不能按极限值去设计多留余量可以省掉一大半“上电偶发不亮”的麻烦。3.2 复位脉冲宽度与初始化命令间隔除了复位引脚本身的脉冲初始化命令之间的间隔同样重要。ST7567有些命令需要内部电路稳定比如打开升压电路之后如果没有等待足够的时间就马上去设对比度显示效果可能不正确。我写初始化函数时会在几个关键节点加延时0xE2软复位命令之后至少等5ms0x2F开升压之后等20ms以上让内部升压电路建立稳定的LCD驱动电压最后写0xAF开显示之后等20ms再清屏。这些时间不是拍脑袋定的而是实测中发现如果命令发得太快屏偶发显示异常。
具体表现是上电后第一次正常第二次白屏或者复位后正常断电重上电就花。把初始化命令之间的间隔拉大后问题消失。3.3 和MCU共用复位信号是个隐患有人会把屏的RST引脚直接接到STM32的NRST复位脚上觉得这样省一个GPIO。这个做法偶尔能用但存在一个典型问题MCU复位释放后内部程序启动需要一段时间而屏的复位释放也同时开始等MCU跑到初始化函数时屏可能还在复位状态或者刚复位完内部寄存器还没准备好接收命令。更稳妥的做法是屏的RST用一个单独的GPIO控制这样你可以精确控制复位释放的时机。如果PCB已经画死了、屏的复位和MCU复位必须共用那解决方案是软件里补救重新对屏执行一次0xE2软复位然后等足够长时间再初始化。3.4 软复位命令0xE2的用法0xE2是ST7567的软件复位命令功能是让芯片内部所有寄存器恢复默认状态。它的作用和外部RST引脚类似但不需要硬件连线在调试阶段特别好用。如果屏已经处于
工作状态但显示乱了直接在代码里执行一次0xE2再重新执行完整初始化流程等于给屏做了一次“软件断电重启”。我在调试菜单切换导致花屏时会优先尝试软复位。注意软复位命令后也要延时至少等5ms确保内部状态稳定再发后面的命令。4. 初始化命令序列升压、偏置、温度补偿怎么协同工作4.1 能直接抄的初始化代码先用标准库给出一个完整的初始化函数这个序列我实测可以点亮绝大多数ST7567模块用的是STM32F103模拟GPIO方式void ST7567_WriteCmd(uint8_t cmd) { CS_L(); A0_L(); // 命令模式 ST7567_SPI_WriteByte(cmd); CS_H(); } void ST7567_WriteData(uint8_t dat) { CS_L(); A0_H(); // 数据模式 ST7567_SPI_WriteByte(dat); CS_H();
} void ST7567_Init(void) { // 复位时序 RST_H(); DelayMs(10); RST_L(); DelayMs(20); RST_H(); DelayMs(50); // 初始化命令序列 ST7567_WriteCmd(0xE2); // 软复位 DelayMs(5); ST7567_WriteCmd(0xA2); // 1/9偏置比用于12864屏 ST7567_WriteCmd(0x2F); // 打开升压电路1、升压电路2、电压跟随器 DelayMs(20); // 等升压稳定 ST7567_WriteCmd(0x25); // 温度补偿系数选择第二档 ST7567_WriteCmd(0x22); // 内部电阻比例 ST7567_WriteCmd(0x81); // 电子对比度设置命令 ST7567_WriteCmd(0x1F); // 对比度
初始值后续按需调整 ST7567_WriteCmd(0xA0); // ADC输出方向正常的列方向 ST7567_WriteCmd(0xC8); // COM扫描方向正常扫描 ST7567_WriteCmd(0xA6); // 正常显示关闭反显 ST7567_WriteCmd(0xAF); // 打开显示 DelayMs(20); ST7567_ClearScreen(); // 清屏 }4.2 0x2F升压电路不开就是白屏0x2F这个命令在ST7567初始化里排在非常重要的位置。ST7567内置了DC-DC升压电路用来产生液晶面板需要的驱动电压V0。如果这个升压电路没有打开驱动IC虽然能收到命令但液晶两端没有足够的电压差屏幕看起来就是白花花一片和没通电差不多。0x2F是完整开启三个电源模块——升压电路1、升压电路2、电压跟随器。有些初始化示例只写了0x2E也就是只开了升压电路1屏幕也可能
亮但显示对比度可能偏弱驱动能力不足。我建议直接写0x2F一步到位。以后遇到白屏优先确认这一条命令有没有正确执行以及0x2F后面有没有留足升压稳定时间。4.3 偏置比、显示方向和非显示模式命令0xA2设置的是1/9偏置比这个参数要和屏幕面板的实际液晶层厚度、驱动电压匹配。12864这种结构用1/9偏置比较常见如果选择错误比如用了0xA3的1/7偏置画面会明显过暗或者过浓这不是对比度寄存器能完全弥补的。0xA0和0xC8决定扫描方向。0xA0是ADC正常方向0xC8是COM反向扫描这个组合在大多数模块上显示方向正确。如果你的屏幕装上去发现内容左右反了把0xA0改成0xA1上下反了把0xC8改成0xC0。如果左右和上下都反就把两个命令都换掉相当于旋转180度。另外有两个命令容易误触0xA5是“显示全亮”0xA4是“显示正常”。如果你初始化代码里不小心把0xA4写成了0xA5屏幕会整个变成深色或者
全黑很多人误以为是屏坏了。5. 对比度调节的实战从0x20开始往上试5.1 0x81之后那个数据到底在调什么ST7567的电子对比度调节是通过命令0x81后跟一个0x00到0x3F之间的值来完成的。这个值控制的是芯片内部电阻网络的分压比直接影响输出给液晶面板的V0电压。V0电压不同液晶翻转程度就不同显示出来的笔画深度也就不一样。这里要特别注意0x3F是六位数据有些代码写成0x81、0x1F有些写成0x81、0x25都没有问题只要范围在0x00到0x3F之间。对比度数值越大显示越浓越黑。我在多数3.3V供电的模块上初始值用0x1F到0x25之间都能获得不错的显示效果。对比度和供电电压强相关。同样一个模块VDD3.3V时对比度0x22刚好如果把VDD换成5V同样的值可能显示过深甚至出现鬼影。所以网上抄对比度参数时最好确认对方的供电电压是多少否则抄过来不一定适配。5.2 调对比度的具体步骤与范围

本文来源:http://www.lpqz.cn/news/110227
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
Anyone who has worked with the ST7567 driver IC knows that the most frustrating thing isn't how complex it is, but that even after copying someone else's code verbatim, the screen simply won't light up, or shows nothing but white, making you suspect you've soldered the screen wrong. Last month I helped a netizen debug a 12864 "serial screen"; he sent me his initialization code, and the commands and timing looked fine on the surface, but after poking around with a multimeter I found the PS pin on the module was floating, so serial mode wasn't selected at all. That made me decide to systematically organize the pitfalls I've encountered debugging ST7567 screens over the years, especially the three areas mentioned in the title: pin levels, reset timing, and contrast adjustment, each of which can make a screen "look broken." First I need to clarify a confusing concept: the "serial screen" in the title refers to a monochrome LCD screen with an SPI serial interface using the ST7567 controller, not those large color screens or DWIN screens controlled by sending commands over UART. The latter are master-control screens with intelligent protocols and completely different driver logic. Everything in this article applies only to ST7567-type LCD screens where pixel data is written via SPI. The content is entirely from my own debugging notes, suitable as a reference for friends who are driving such screens with bare-metal STM32 and are running into white-screen or garbled-display problems.
1. What exactly is an ST7567 "serial screen"? Interface types and the pitfalls of pin levels 1.1 The misunderstanding most easily caused by the term "serial screen" Many Taobao store titles call the ST7567 12864 screen a "serial screen"; newcomers buy it and assume that, like a UART screen, two wires are enough to send characters, only to find that nothing displays at all. It must be made clear here that the ST7567 is a pure LCD driver chip with no built-in Chinese font library, let alone any serial protocol parsing function. Its so-called "serial" only means that this IC supports inputting display data via a serial SPI interface, and its size is the same as an ordinary 128x64-pixel LCD; the display content has to be written in page by page by the microcontroller. The ST7567 itself supports three modes: 8080 parallel interface, 6800 parallel interface, and 4-wire SPI serial interface, and modules usually bring out only one or two of these. In serial mode, SCL is used as the clock, SI (labeled SDA or MOSI on many modules) as the data input, A0 (also called RS or DC) to distinguish commands from data, and CS as the chip select. If the module you bought only brings out these few interfaces, it means the manufacturer has set it to work in serial mode by default. If the module also brings out more pins, such as DB0 to DB7, then you need to first check PS or
PSB pin to confirm it is correctly set to serial mode. 1.2 Minimal hardware connection and logic level compatibility First, let me list the most common wiring scheme, which is the minimal system connection for an ST7567 screen in serial mode: ST7567 module pin / STM32 pin / description: VDD / 3.3V / logic power supply, the vast majority of modules are 3.3V; VSS / GND / ground; CS / PA4 / chip select, active low; A0 (RS) / PA3 / command/data selection, low for command, high for data; SCL / PA2 / SPI clock; SI (SDA) / PA1 / SPI data input; RST / PA0 / reset, active low; LEDA/LEDK / 3.3V or 5V with a current-limiting resistor / backlight polarity, don't connect it backwards. Pin levels are the first core pitfall mentioned in the title. The typical operating voltage of ST7567's VDD is 3.3V, and the input high-level threshold in the datasheet is generally around 0.7 times VDD, meaning that when VDD is 3.3V, any high level above 2.31V is reliably recognized, so the STM32's 3.3V push-pull output is perfectly fine. But if you take the easy route and connect 5V to VDD, things change. When VDD is 5V, the input high-level threshold becomes 3.5V; although the STM32's 3.3V high level is barely close, this voltage is already not
enough margin, and with wiring impedance and on-board voltage drops, it's easy to get intermittent "sometimes-works-sometimes-doesn't" white screens. I've seen a case where initialization commands would take effect intermittently, simply because VDD was connected to 5V without level conversion. If you must use a 5V supply, add level-shifting circuitry on the SCL, SI, A0, CS, and RST lines; don't directly drive 5V logic inputs with 3.3V. Another thing to note is that the backlight supply is best kept separate from the logic supply. Many modules' LEDA pins have no built-in current-limiting resistor, so connecting directly to 5V may cause overcurrent; it's recommended to add a 10 to 100 ohm resistor in series and adjust based on measured backlight brightness. 2. The "looks normal" traps in pin levels and SPI connections 2.1 The PS pin's serial/parallel selection is the most hidden switch In the ST7567 datasheet, the PS pin is called the serial/parallel interface selection; some modules bring it out, while others make the selection directly on the PCB with a solder bridge. If this pin is pulled high, the chip operates in parallel mode, and no matter what SPI commands you send, the screen won't respond at all. In a case I encountered, a certain module's PS pin was brought out to a header, but the manufacturer didn't clearly indicate on the silkscreen whether it should be tied high or low. At that time I only
connected VDD, GND, and the four SPI wires as usual, leaving PS floating, with the result that the screen was always white. Measuring the PS header voltage with a multimeter showed it was floating, so I couldn't tell whether it was high or low, and the chip's internal state was completely indeterminate. Later, when I tied PS to GND, the screen responded immediately. When troubleshooting this kind of problem, the first thing to do is check the module schematic or datasheet to confirm the PS pin's level requirement. In serial mode, ST7567 requires PS to be pulled low; defer to your module's silkscreen for specifics. If the module doesn't bring out PS, it's generally already hardwired, so you don't need to worry about it. 2.2 The hidden pitfall of JTAG-multiplexed pins and GPIO configuration Another classic pin-level pitfall is using pins that are occupied by JTAG by default when the STM32 powers on. These pins include PA13, PA14, PA15, PB3, and PB4. Many tutorials like to put SCL on PB3, SDA on PB4, or CS on PA15; it looks like there's no problem at all because the code also does GPIO initialization. But on the STM32F103, after power-on these pins are not ordinary IO by default; they are the JTAG debug interface. If you configure the GPIO mode as push-pull output and write a high level, it may fail to drive high, or writing a low level may also be uncon
trolled. The symptom on the screen is that the SPI waveform is wrong and commands get no response at all. There are two solutions. The first is to avoid these pins and rewire using ordinary pins such as PC13, PA0, and PA1; this is the most worry-free approach. The second is to use the remapping function GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); the effect of this line of code is to disable JTAG while retaining SWD, after which PA15, PB3, and PB4 can be used as ordinary IO. However, I'd recommend that if the screen has no hard pin requirements, simply changing pins is more reliable; after all, a mistake in the remapping code or failing to set it before downloading may prevent the programmer from connecting to the chip. 2.3 How to choose between hardware SPI and bit-banged SPI The upper limit of the ST7567's serial SPI frequency is not high; on many modules the SCL clock tops out at around 2MHz. When the STM32 runs at a 72MHz main frequency, if you directly use the AHB maximum divider to send data at 18MHz, you'll most likely get a garbled or messy display. When I use hardware SPI, I habitually set the baud rate prescaler to 64, i.e., around 1.125MHz, which is more than enough and particularly stable. The polarity of hardware SPI
selection is also an easy place to stumble. The ST7567's serial timing has SCL idle low and data sampled on the rising edge of SCL, corresponding to SPI Mode 0, i.e., CPOL Low, CPHA 1Edge. In actual use, Mode 3 sometimes works too, but I don't recommend betting on such compatibility; honestly, using Mode 0 is the safest. Personally, I prefer to implement SPI with bit-banged GPIO for a simple reason: the timing is completely controllable, not easily affected by main-frequency dividers, and when debugging you can visually see whether each bit's level is correct. The core logic of writing one byte with bit-banged SPI is as follows: void ST7567_SPI_WriteByte(uint8_t dat) { for (uint8_t i 0; i 8; i) { SCL_L(); if (dat 0x80) SDA_H(); else SDA_L(); dat 1; SCL_H(); // rising edge, ST7567 samples the data } } Note here that you must first pull SCL low, then change the SDA level, and then pull SCL high. If SDA is still changing while SCL is high, the sampled data
will be wrong. Although this approach is somewhat slower than hardware SPI, it's more than adequate for driving a 12864 monochrome screen. 3. Reset timing, the step most prone to "intermittent white screens" 3.1 Power-on details not clearly stated in the datasheet In many people's initialization code, the reset timing is just a token pull-low and pull-high, without seriously considering what state the chip is in after power-on. After the ST7567 powers on, its internal circuitry needs a process in which VDD ramps from 0 up to a stable value. If you execute reset and initialization commands before VDD has stabilized, the chip may not enter its working state correctly, showing up as an intermittent white screen that becomes normal again after pressing the reset button once. I usually handle it this way: first wait for the main controller's power to stabilize, delaying at least 100ms before touching the screen's pins, and then perform the reset pulse. Don't initialize immediately after power-on, and don't operate the peripherals at the same instant as the STM32's SystemInit. After power-on, the microcontroller runs much faster than the screen's power supply stabilizes, so this time difference must be made up with a Delay. For the actual operation of the reset pin, I'll give a somewhat conservative but sufficiently reliable timing: LCD_RST_H(); DelayMs(10); LCD_RST_L(); DelayM
s(20); // RST low level maintained for 20ms LCD_RST_H(); DelayMs(50); // after reset release, wait 50ms before sending commands Why such long delays? Because modules from different manufacturers may have level conversion or filtering circuits in front of the ST7567, and the RC time constants differ. The minimum reset pulse width in the datasheet is only about 1 microsecond, but in engineering you can't design to the limit value; leaving more margin can save you more than half the trouble of "occasional no-display at power-on." 3.2 Reset pulse width and intervals between initialization commands Besides the pulse on the reset pin itself, the intervals between initialization commands are equally important. Some ST7567 commands require the internal circuitry to stabilize; for example, after turning on the boost circuit, if you don't wait long enough before setting the contrast, the display may be incorrect. When writing the initialization function, I add delays at several key points: wait at least 5ms after the 0xE2 soft-reset command; wait more than 20ms after 0x2F turns on the boost, letting the internal boost circuit establish a stable LCD drive voltage; finally, after writing 0xAF to turn the display on, wait 20ms before clearing the screen. These timings aren't arbitrary; in testing I found that if commands are sent too quickly, the screen occasionally displays abnormally.
The specific symptom is: after power-on, the first time is normal, the second time is a white screen; or it's normal after a reset but garbled after a power cycle. After increasing the intervals between initialization commands, the problem disappears. 3.3 Sharing the reset signal with the MCU is a hidden risk Some people connect the screen's RST pin directly to the STM32's NRST reset pin, thinking it saves a GPIO. This occasionally works, but there's a typical problem: after the MCU's reset is released, the internal program takes a while to start, while the screen's reset release also begins at the same time; by the time the MCU reaches the initialization function, the screen may still be in reset, or just out of reset with its internal registers not yet ready to receive commands. A more robust approach is to control the screen's RST with a separate GPIO, so you can precisely control the timing of the reset release. If the PCB is already finalized and the screen's reset must be shared with the MCU's reset, then the workaround in software is to perform another 0xE2 soft reset on the screen, wait long enough, and then initialize. 3.4 Usage of the soft-reset command 0xE2 0xE2 is the ST7567's software reset command; its function is to restore all internal registers of the chip to their default state. It has a similar effect to the external RST pin but requires no hardware connection, making it especially useful during debugging. If the screen is already in
its working state but the display is messed up, simply execute 0xE2 once in the code and then re-run the full initialization flow; it's equivalent to giving the screen a "software power-cycle reboot." When debugging garbled displays caused by menu switching, I try a soft reset first. Note that after the soft-reset command you must also delay, waiting at least 5ms to ensure the internal state is stable before sending subsequent commands. 4. Initialization command sequence: how boost, bias, and temperature compensation work together 4.1 Initialization code you can copy directly First, here's a complete initialization function using the Standard Peripheral Library; I've tested this sequence and it can light up the vast majority of ST7567 modules, using the STM32F103 bit-banged GPIO method: void ST7567_WriteCmd(uint8_t cmd) { CS_L(); A0_L(); // command mode ST7567_SPI_WriteByte(cmd); CS_H(); } void ST7567_WriteData(uint8_t dat) { CS_L(); A0_H(); // data mode ST7567_SPI_WriteByte(dat); CS_H();
} void ST7567_Init(void) { // reset timing RST_H(); DelayMs(10); RST_L(); DelayMs(20); RST_H(); DelayMs(50); // initialization command sequence ST7567_WriteCmd(0xE2); // soft reset DelayMs(5); ST7567_WriteCmd(0xA2); // 1/9 bias ratio, used for 12864 screens ST7567_WriteCmd(0x2F); // turn on booster circuit 1, booster circuit 2, and voltage follower DelayMs(20); // wait for boost to stabilize ST7567_WriteCmd(0x25); // temperature compensation coefficient, select the second level ST7567_WriteCmd(0x22); // internal resistor ratio ST7567_WriteCmd(0x81); // electronic contrast setting command ST7567_WriteCmd(0x1F); // contrast
initial value, adjust later as needed ST7567_WriteCmd(0xA0); // ADC output direction, normal column direction ST7567_WriteCmd(0xC8); // COM scan direction, normal scan ST7567_WriteCmd(0xA6); // normal display, reverse display off ST7567_WriteCmd(0xAF); // turn display on DelayMs(20); ST7567_ClearScreen(); // clear screen } 4.2 If the 0x2F boost circuit isn't turned on, you get a white screen The command 0x2F occupies a very important position in ST7567 initialization. The ST7567 has a built-in DC-DC boost circuit used to generate the drive voltage V0 required by the LCD panel. If this boost circuit isn't turned on, the driver IC can still receive commands, but there isn't enough voltage difference across the LCD, so the screen looks like a blank white sheet, much like having no power at all. 0x2F fully turns on three power modules: booster circuit 1, booster circuit 2, and the voltage follower. Some initialization examples only write 0x2E, which turns on just booster circuit 1; the screen may
still light up, but the display contrast may be weak due to insufficient drive capability. I recommend just writing 0x2F and getting it right in one step. In the future, when you encounter a white screen, first confirm whether this command was executed correctly and whether enough time was left after 0x2F for the boost to stabilize. 4.3 Bias ratio, display direction, and non-display mode commands 0xA2 sets the 1/9 bias ratio; this parameter must match the actual liquid-crystal layer thickness and drive voltage of the screen panel. A 1/9 bias is common for a structure like the 12864; if you choose wrong, for example using 0xA3 for a 1/7 bias, the image will be noticeably too dark or too dense, which the contrast register can't fully compensate for. 0xA0 and 0xC8 determine the scan direction. 0xA0 is the normal ADC direction, and 0xC8 is reverse COM scanning; this combination gives the correct display orientation on most modules. If after installing your screen you find the content is mirrored left-right, change 0xA0 to 0xA1; if it's flipped top-bottom, change 0xC8 to 0xC0. If both left-right and top-bottom are reversed, change both commands, which is equivalent to rotating 180 degrees. In addition, there are two commands that are easy to trigger by mistake: 0xA5 is "display all on" and 0xA4 is "display normal." If you accidentally write 0xA5 instead of 0xA4 in your initialization code, the entire screen will turn dark or
completely black, and many people mistake it for a broken screen. 5. Contrast adjustment in practice: start from 0x20 and work upward 5.1 What exactly does the data after 0x81 adjust? The ST7567's electronic contrast adjustment is done through the command 0x81 followed by a value between 0x00 and 0x3F. This value controls the voltage-divider ratio of the chip's internal resistor network, directly affecting the V0 voltage output to the LCD panel. With different V0 voltages, the degree of liquid-crystal rotation differs, and so does the depth of the displayed strokes. Note especially that 0x3F is six-bit data; some code writes 0x81, 0x1F and some writes 0x81, 0x25; both are fine as long as the value is in the range 0x00 to 0x3F. The larger the contrast value, the denser and blacker the display. On most 3.3V-powered modules, I get good display results with initial values between 0x1F and 0x25. Contrast is strongly related to supply voltage. For the same module, a contrast of 0x22 may be just right at VDD 3.3V, but if you switch VDD to 5V, that same value may display too darkly or even produce ghosting. So when copying contrast parameters from the internet, it's best to confirm the other person's supply voltage, otherwise the copied value may not be suitable. 5.2 Specific steps and range for adjusting contrast