1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
想学习使用SPI框架驱动OLED,就准备把中景园的程序移植到RTT上,参考了网上的步骤,在settings里开启spi,在board.c里复制HAL_SPI_MspInit,在board.h和stm32xxxx_hal_config.h里开启了spi,然后代码如下: /* Copyright (c) 2006-2021, RT-Thread Development Team SPDX-License-Identifier: Apache-2.0 Change Logs: 在OLED_Init最后想画个点测试是否成功,但是屏幕没有点亮,msh里输入list_device可以看见spi1和spi10是正常开启的,请问是哪个步骤做错了吗 |
|
相关推荐
1个回答
|
|
拿着个试试
/* * Copyright (c) 2014-2019, Winning_technology * * SPDX-License-Identifier: None * * Change Logs: * Date Author Notes * 2019-07-19 Jiao newly-built */ /* * 程序清单:OLED屏幕底层驱动 */ #include #include "oled_drv.h" #include "stdlib.h" #include #include #include "drv_spi.h" #define OLED_DC_PIN 4 /* 数据控制脚 */ #define Max_Column 128 #define Max_Row 64 #define X_WIDTH 128 #define Y_WIDTH 64 //OLED控制用函数 struct rt_spi_device *spi_device = RT_NULL; rt_uint8_t video_mem[8][128]; //显存,1K RAM空间 //屏幕命令 static void OLED_CMD(unsigned dat) { struct rt_spi_message spi_msg; rt_pin_write(OLED_DC_PIN,PIN_LOW); rt_memset(&spi_msg, 0x00, sizeof(spi_msg)); spi_msg.send_buf = &dat; spi_msg.length = 1; rt_spi_transfer_message(spi_device, &spi_msg); rt_pin_write(OLED_DC_PIN,PIN_LOW); } //开启OLED显示 void OLED_Display_On(void) { OLED_CMD(0X8D); //SET DCDC命令 OLED_CMD(0X14); //DCDC ON OLED_CMD(0XAF); //DISPLAY ON } //关闭OLED显示 void OLED_Display_Off(void) { OLED_CMD(0X8D); //SET DCDC命令 OLED_CMD(0X10); //DCDC OFF OLED_CMD(0XAE); //DISPLAY OFF } //刷屏,不刷不显示 void OLED_refresh(void) { struct rt_spi_message spi_msg; rt_uint8_t i; rt_memset(&spi_msg, 0x00, sizeof(spi_msg)); for(i=0;i<8;i++) { OLED_CMD(0xB0+i); OLED_CMD(0x02); OLED_CMD(0x10); rt_pin_write(OLED_DC_PIN,PIN_HIGH); spi_msg.send_buf = video_mem[i]; spi_msg.length = 128; rt_spi_transfer_message(spi_device, &spi_msg); rt_pin_write(OLED_DC_PIN,PIN_LOW); } } //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!! void OLED_Clear(void) { rt_uint8_t i,n; for(i=0;i<8;i++)for(n=0;n<128;n++)video_mem[i][n]=0X00; // OLED_refresh();//更新显示 } //画点 //x:0~127 //y:0~63 //t:1 填充 0,清空 void OLED_DrawPoint(rt_uint8_t x,rt_uint8_t y,rt_uint8_t t) { rt_uint8_t pos,bx,temp=0; if(x>127||y>63)return;//超出范围了. pos=7-(y>>3); bx=y%8; temp=1<<(7-bx); if(t)video_mem[pos][x]|=temp; else video_mem[pos][x]&=~temp; } //x1,y1,x2,y2 填充区域的对角坐标 //确保x1<=x2;y1<=y2 0<=x1<=127 0<=y1<=63 //dot:0,清空;1,填充 void OLED_Fill(rt_uint8_t x1,rt_uint8_t y1,rt_uint8_t x2,rt_uint8_t y2,rt_uint8_t dot) { rt_uint8_t x,y; for(x=x1;x<=x2;x++) { for(y=y1;y<=y2;y++)OLED_DrawPoint(x,y,dot); } OLED_refresh();//更新显示 } /*OLED spi驱动初始化*/ rt_err_t oled_drv_init(void) { char *spi_dev_name="spi10"; /* 输入模式 */ rt_pin_mode(OLED_DC_PIN, PIN_MODE_OUTPUT); //OLED_DC rt_pin_write(OLED_DC_PIN,PIN_LOW); rt_hw_spi_device_attach("spi1",spi_dev_name,GPIOA,GPIO_PIN_12); if (spi_device != RT_NULL) { return 0; } spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name); if (spi_device == RT_NULL) { rt_kprintf("SPI device %s not found!", spi_dev_name); return -RT_ENOSYS; } /* check SPI device type */ RT_ASSERT(spi_device->parent.type == RT_Device_Class_SPIDevice); /* configure SPI device*/ { struct rt_spi_configuration cfg; cfg.data_width = 8; cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible Modes 0 */ cfg.max_hz = 8 * 1000 * 1000; /* SPI Interface with Clock Speeds Up to 8 MHz */ rt_spi_configure(spi_device, &cfg); } if (rt_device_open((rt_device_t) spi_device, RT_DEVICE_OFLAG_WRONLY) != RT_EOK) { rt_kprintf("open SPI device %s error.", spi_dev_name); return -RT_ERROR; } return RT_EOK; } //显示初始化 void Display_Init(void) { oled_drv_init(); rt_thread_mdelay(300); OLED_CMD(0xAE); //关闭显示 OLED_CMD(0xD5); //设置时钟分频因子,震荡频率 OLED_CMD(80); //[3:0],分频因子;[7:4],震荡频率 OLED_CMD(0xA8); //设置驱动路数 OLED_CMD(0X3F); //默认0X3F(1/64) OLED_CMD(0xD3); //设置显示偏移 OLED_CMD(0X00); //默认为0 OLED_CMD(0x40); //设置显示开始行 [5:0],行数. OLED_CMD(0x8D); //电荷泵设置 OLED_CMD(0x14); //bit2,开启/关闭 OLED_CMD(0x20); //设置内存地址模式 OLED_CMD(0x02); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10; OLED_CMD(0xA1); //段重定义设置,bit0:0,0->0;1,0->127; OLED_CMD(0xC0); //设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数 OLED_CMD(0xDA); //设置COM硬件引脚配置 OLED_CMD(0x12); //[5:4]配置 OLED_CMD(0x81); //对比度设置 OLED_CMD(0xEF); //1~255;默认0X7F (亮度设置,越大越亮) OLED_CMD(0xD9); //设置预充电周期 OLED_CMD(0xf1); //[3:0],PHASE 1;[7:4],PHASE 2; OLED_CMD(0xDB); //设置VCOMH 电压倍率 OLED_CMD(0x30); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc; OLED_CMD(0xA4); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏) OLED_CMD(0xA6); //设置显示方式;bit0:1,反相显示;0,正常显示 OLED_CMD(0xAF); //开启显示 OLED_Clear(); OLED_refresh(); // rt_thread_mdelay(2000); } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
590 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
2241 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1233 浏览 0 评论
1788 浏览 0 评论
1464 浏览 0 评论
74835 浏览 21 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 07:46 , Processed in 0.696870 second(s), Total 70, Slave 54 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号