我有一些驱动程序代码,我正在测试一个SSD1306驱动的OLED屏幕,这是128x32 (与OLED adafruit模型相同)。我需要在debian中运行这个(我正在使用Linario-4.4.9)
我遵循了Debian指南中关于如何开始为设备创建文件处理程序的指导,如下所示。oled.h中唯一的东西是设备入口(0x3C)和proto类型。我遵循了在adafruit上采用的初始化方法(我首先在Ardunio上尝试了他们的代码,以确保屏幕确实正常工作)。我相信我可能做错了什么,但我不完全确定我做错了什么。下面我还列出了我的init流程。
#include <errno.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <linux/i2c-dev.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "oled.h"
int oled;
int lcd_driver_init(void)
{
///< Begin the init proc.
int dloc = open("/dev/i2c-1", O_RDWR);
if (dloc < 0 )
{
fprintf(stderr, "Error opening i2c device\n");
return -1;
}
if(ioctl(dloc, I2C_SLAVE, SCR_ADDR) < 0)
{
fprintf(stderr, "Error in ioctl. Errno :%i\n",errno);
return -2;
}
oled = dloc;
fprintf(stderr, "init success, device open and local\n");
return EXIT_SUCCESS;
}
int oled_command( uint8_t cmd)
{
char command[2]= {0};
command[1] = cmd;
int check = (write(oled, command, 2));
return check;
}
void oled_cmd_start()
{
int check = (write(oled, 0x00, sizeof(uint8_t)));
if(check<0)
fprintf(stderr, "Errno set:: %i\n", errno);
return;
}
void oled_data_start()
{
uint8_t _data_start_[1] ={ 0x40 };
int check = (write(oled, _data_start_, sizeof(uint8_t)));
if(check<0)
fprintf(stderr, "Errno set oled_data_start:: %i\n", errno);
return;
}
int oled_data (uint8_t xmit)
{
int check = (write(oled, &xmit, (sizeof(uint8_t))));
if(check<0)
fprintf(stderr, "Errno set oled_data:: %i\n", errno);
return check;
}INIT工艺
void sendcommand(unsigned char payload)
{
oled_data(0x00); //Control Byte - Command
oled_data(payload); //payload
}
void lcd_init(void)
{
sendcommand(0xAE);//--Set Display off
sendcommand(0x00);//--set low column address
sendcommand(0x10);//--set high column address
sendcommand(0x81);//--set contrast control register
sendcommand(0x7f);
sendcommand(0xa1);//--set segment re-map 95 to 0
sendcommand(0xA6);//--set normal display
sendcommand(0xa8);//--set multiplex ratio(1 to 16)
sendcommand(0x1f);//--duty 1/32
sendcommand(0xd3);//--set display offset
sendcommand(0x00);//--not offset
sendcommand(0xd5);//--set display clock divide ratio/oscillator frequency
sendcommand(0xf0);//--set divide ratio
sendcommand(0xd9);//--set pre-charge period
sendcommand(0x22);
sendcommand(0xda);//--set com pins hardware configuration
sendcommand(0x02);//disable left/right remap and set for sequential
sendcommand(0xdb);//--set vcomh
sendcommand(0x49);//--0.83*vref
sendcommand(0x8d);//--set DC-DC enable
sendcommand(0x14);//
sendcommand(0xAF);//--turn on oled panel
sendcommand(0xA4);//--Entire Display ON
}在此之后,我发送交替的0xFF来尝试在屏幕上制作条纹。唯一能显示出来的就是随机像素。没什么连贯的。
我已经连接了一个逻辑分析器来嗅探I2C线路,当我连接到LA时,I2C线路就不再起作用,ERRNO返回一个IO错误(#5)。然而,似乎从未出现过打开设备以获取文件指针的问题。
有时候,我确实会以超时的形式获得ERRNO,但我已经读到,这只是I2C设备使用协议的一个问题,因为write希望比I2C提供更快的响应。
我还使用-std=c99 -O0进行编译,以确保所有内联函数都存在,并确保循环变量可用。
如果有人能为我指出正确的方向,指出我的方法中的一些缺陷,我们将不胜感激。谢谢。
编辑
我检查了设备树,并正确启用了i2c设备。然而,似乎没有一个i2c_freq速度是启用的。这会导致超时和垃圾数据传输吗?
发布于 2017-04-14 16:23:27
原来SOM有一个I2C线路的内部调节器为1V8,当SSD1306芯片运行在3V3时,导致信息处理不当。这一行为并没有记录在SOM上。
将电平转换芯片应用到设计中,可以进行适当的通信。
如果有人有同样的问题,检查您的示意图电压失配水平。
发布于 2017-04-11 02:07:58
我连接了一个逻辑分析器来嗅探I2C线路,当我连接到LA时,I2C线路就不再起作用了,ERRNO返回一个IO错误(#5)。
逻辑分析仪只是一种测量装置。它将捕获的数据转换为您设置的定时图、解码协议。因此,它将不负责任何I2C读写错误(直到您的接地和h/w连接正确)。
对于超时问题,可以通过减少i2c clock-frequency或ioctl I2C_TIMEOUT来尝试。
https://stackoverflow.com/questions/43333649
复制相似问题