在stm32U575在RT-Thread studio下面是没有开发板和芯片可选的,所以只能用keil或者IAR,或者是vscode等,但是在MacOs下,没有keil、IAR可用,当然也可以用VSCODE来写。这里向大家分享如何从零开始驱动OLED。
1、增加配置里面的I2C,来启用i2c,我们根据原理图,CN7的D15为SCL对应的是PB8,D14为SDA对应的PB9,根据管脚计算公式,计算出PB8为16*1+8=24,同理PB9为24.编辑/board文件夹下的Kconfig,增加如下内容:
if BSP_USING_I2C
menuconfig BSP_USING_I2C1
bool "Enable I2C1 BUS (software simulation)"
default y
if BSP_USING_I2C1
comment "Notice: PB8 --> 24; PB9 --> 25"
config BSP_I2C1_SCL_PIN
int "i2c1 scl pin number"
range 1 176
default 24
config BSP_I2C1_SDA_PIN
int "I2C1 sda pin number"
range 1 178
default 25
endif
endif
2、进入图形化配置工具,配置I2C1、增加在线软件包ssd1306:
在stm32u575-st-nucleo目录下打开终端,执行scons --pyconfig图形化工具,当然也可以用scons --menuconfig
保存后退出,先加载env环境:
source ~/.env/env.sh
然后执行pkgs --update来更新ssd1306软件包。
3、等待加载完成后执行scons来构建项目。构建完成后下载到开发板。系统启动,查看串口终端如下:
[12:08:51.355] msh >help
[12:09:00.537] RT-Thread shell commands:
[12:09:00.537] reboot - Reboot System
[12:09:00.537] pin - pin [option]
[12:09:00.547]
[12:09:00.547] clear - clear the terminal screen
[12:09:00.547] version - show RT-Thread version information
[12:09:00.547] list - list objects
[12:09:00.557] help - RT-Thread shell help.
[12:09:00.557] ps - List threads in the system.
[12:09:00.557] free - Show the memory usage in the system.
[12:09:00.567] ssd1306_TestAll - test ssd1306 oled driver
[12:09:00.567]
[12:09:00.567] msh >list device
[12:09:13.854] device type ref count
[12:09:13.854] -------- -------------------- ----------
[12:09:13.865] i2c1 I2C Bus 0
[12:09:13.865] uart2 Character Device 0
[12:09:13.865] uart1 Character Device 2
[12:09:13.865] pin Pin Device 0
看到i2c总线已要加载成功。打OLED屏的SDA接到开发板的D14,SCL接到D15.执行ssd1306_TestAll就可以看到OLED屏已经驱动成功。
---------------------
作者:lulugl
链接:https://bbs.21ic.com/icview-3286562-1-1.html
来源:21ic.com
此文章已获得原创/原创奖标签,著作权归21ic所有,任何人未经允许禁止转载。