当前位置:网站首页>3线spi屏幕驱动方式
3线spi屏幕驱动方式
2022-06-27 00:13:00 【NULL_1969】
前言
最近研究了一下3线spi屏幕的驱动方式。屏幕的驱动芯片为ILI9488,相比于4线,3线spi屏幕没有用到DC写命令/写数据控制线。DC=0表示写命令,DC=1表示写数据。
3线spi数据格式

3线spi就是将DC命令放到了每个8位数据的最高位。这么说还是有些枯燥,看下具体的例子。
假如采用spi发送0x55,一般采用的MSB,高位在前的方式。
那么SDA(MOSI)数据线上是这样的:
01010101
如果要假如dc命令,则0x55要分为两个字节进行发送,假设DC=1,则SDA(MOSI)数据如下:
10101010 1
低字节 高字节
相当于要将0x55转换为:0x80AA。同时要在单片机中设置spi数据为9位。经过多次摸索,其转换公式为:
uint16_t data = (0x8000&(cmd<<15))|(0x7f&(cmd>>1)) ;
具体在esp32中需要将发送函数改为如下:
static void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd)
{
esp_err_t ret;
spi_transaction_t t;
uint16_t data=0;
data = (0x8000&(cmd<<15))|(0x7f&(cmd>>1)) ;
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length=9; //Command is 8 bits
t.tx_buffer=&data; //The data is the cmd itself
ret=spi_device_polling_transmit(spi, &t); //Transmit!
assert(ret==ESP_OK); //Should have had no issues.
}
static void lcd_data_byte(spi_device_handle_t spi, const uint8_t cmd)
{
esp_err_t ret;
spi_transaction_t t;
uint16_t data=0;
data = (0x8000&(cmd<<15))|(0x80|cmd>>1) ;
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length=8; //Command is 8 bits
t.tx_buffer=&data; //The data is the cmd itself
ret=spi_device_polling_transmit(spi, &t); //Transmit!
assert(ret==ESP_OK); //Should have had no issues.
}
只有改成为这样才能正常与屏幕通信。这个造成了通信速度降低,难以采用dma传输大量的数据。原因就是每个字节都要先进行拆解拼凑成2个字节再发送。及其不方便,当时调这个花了不少时间。
个人觉得3线spi通信方式及其扯淡,效率极低,还是老老实实用4线spi或者单片机8080接口来驱动屏幕。有的屏幕中DC引脚使用RS来表示的,笔者也是一开始没搞明白,发现这个屏幕没有DC引脚,才来研究3线spi,后面发现屏幕刷新率太低了,刷新一整屏需要10s钟。最后发现RS=DC,立刻改为4线spi,爽歪歪。
不过ILI9488这个驱动芯片最坑的一点是采用spi方式,只支持8bit和18bit的颜色格式,不支持16bit。这是实验所得,其规格书上写的是采用4线spi时,可以支持16bit颜色,
但将0x3A写入0x05(16bit)屏幕没有显示,只有将0x3A写入0x06(18bit)时,才能显示出颜色。这一点非常坑爹。
ILI9488 18位颜色格式

通常用的都是16位颜色,所以在采用18位颜色是需要进行装换。然后再通过spi发送。具体转换方式就是
colors[0] = (color>>8)&0xf8;
colors[1] = (color>>3)&0xfc;
colors[2] = (color<<3)&0xfc;
红色放到第一个字节,绿色放到第二个字节,蓝色放到低三个字节,且都是高位对齐。低位空置。转换后屏幕即可正常显示。
边栏推荐
- 大健康行业年度必参盛会,2022山东国际大健康产业博览会
- Amway! How to provide high-quality issue? That's what Xueba wrote!
- find_ Detailed use guide of CIRC
- Serial port debugging tool mobaxtermdownload
- Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
- Timing mechanism of LwIP
- 这10款文案神器帮你速码,做自媒体还担心写不出文案吗?
- Leetcode skimming 4 Find the median of two positive arrays
- 【UVM实战 ===> Episode_3 】~ Assertion、Sequence、Property
- 全網最全的混合精度訓練原理
猜你喜欢

当Transformer遇见偏微分方程求解

Ten thousand words explanation - mindarmour Xiaobai tutorial!

技术干货|极速、极智、极简的昇思MindSpore Lite:助力华为Watch更加智能

Implementation of ARP module in LwIP

05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?

Amway! How to provide high-quality issue? That's what Xueba wrote!

Big guys talk about the experience sharing of the operation of the cutting-edge mindspore open source community. Come up with a small notebook!

解决u8glib只显示一行文字或者不显示的问题

Redis detailed tutorial

直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
随机推荐
Interface test framework practice (I) | requests and interface request construction
玩转OLED,U8g2动画,增长数字和随机三角形等
Is it reliable to speculate in stocks by mobile phone? Is it safe to open an account and speculate in stocks online
Deep learning method for solving mean field game theory problems
Hit the point! The largest model training collection!
墨者学院-SQL注入漏洞测试(报错盲注)
敲重点!最全大模型训练合集!
滑环选型选购时需要注意的技巧
BootstrapBlazor + FreeSql实战 Chart 图表使用(2)
In the Internet industry, there are many certificates with high gold content. How many do you have?
这3个并发编程的核心,竟然还有人不知道?
直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
MATLAB data type - character type
Batch generate folders based on file names
matlab数据类型 —— 字符型
Lambda表达式
find_circ详细使用指南
一键加速索尼相机SD卡文件的复制操作,文件操作批处理教程
Special topic II on mathematical physics of the sprint strong foundation program
接口测试框架实战(一) | Requests 与接口请求构造