目前我正在为Arm 9嵌入式应用程序开发两个驱动程序.它们都是i2c驱动程序,每个驱动程序都使用IO扩展器pcf8575.我已经独立测试了驱动程序,但是当我将它们编译到内核并运行我的主应用程序时,我得到了下面的核心转储.通常不会在第一次驱动程序访问期间发生.它似乎是随机发生的.当我的驱动程序调用i2c驱动程序在I2c总线上传输(i2c_master_send(客户端,&buff [0],计数))时,肯定会发生这种情况.我将为我的两个司机附上主要文件.它们很相似,都非常简单.我已经独立完成了很多测试.我通过在两个非常不同的硬件上获得相同的结果来将此作为硬件问题排除在外.我猜我 我甚至不确定它何时说内核分页请求甚至开始查找.我很难相信问题出现在i2c核心驱动程序中,但这是它正在消亡的代码部分.
> Unable to handle kernel paging request at virtual address 000b9a81
> pgd = cfb80000 [000b9a81] *pgd=3fba1031,
> *pte=3f0e43cf, *ppte=3f0e4ffe Internal error: Oops: 17 [#1] Modules linked
> in: i2c_lcd gpio CPU: 0 Not tainted
> (2.6.28.10 #1036) PC is at s3c24xx_i2c_irq+0x308/0x5c4 LR is at
> handle_IRQ_event+0x44/0x80 pc :
> [<c01e7ce8>] lr : [<c00a870c>]
> psr: 80000093 sp : cfbe1d08 ip :
> cfbe1d2c fp : cfbe1d28 r10: cfbe0000
> r9 : 00000000 r8 : 00000004 …Run Code Online (Sandbox Code Playgroud) 我已经明白,当涉及到GPIO上的SPI/I2C时,位敲击是一种可怕的做法.为什么这样?
我正在修改原型的监视器控制器。使用 DDC/CI 向原型发送命令会很方便。在 Windows 中,我找不到将 DDC/CI 命令发送到“显示相关设备”的明显方法。
的监视器配置API可以发送虚拟控制面板命令,但它不给访问显示依赖设备(其将具有比其他0x6e的I2C地址)。
Nicomsoft 的WinI2C/DDC产品似乎可以访问依赖于显示的设备,但它已停产。我不希望建立对报废产品的依赖。
NVIDIA 的NVAPI有一个 I2C API,但我想要一个也适用于 Intel 和 AMD 图形适配器的解决方案。
我在Arduino之间通过I2C进行通信时遇到了麻烦.出于某种原因,onReceive处理程序只被调用一次.
主码(发件人):
#include <Wire.h>
#include "i2csettings.h" // defines address
void setup()
{
Wire.begin(I2C_MASTER_ADDRESS);
}
void loop()
{
Wire.beginTransmission(I2C_SLAVE_ADDRESS);
Wire.write(0x11);
Wire.endTransmission();
delay(1000);
}
Run Code Online (Sandbox Code Playgroud)
奴隶代码(接收者):
#include <Wire.h>
#include "i2csettings.h"
void takeAction(int);
void setup()
{
Serial.begin(9600);
Wire.begin(I2C_SLAVE_ADDRESS);
Wire.onReceive(takeAction);
}
void loop()
{}
void takeAction(int nBytes)
{
Serial.println("Action!");
}
Run Code Online (Sandbox Code Playgroud)
这个测试设置的想法是让发送者每秒发送一个字节,让接收者通过打印消息来对此进行操作.但是,该消息仅打印一次.当我重置奴隶时,它再次打印,但只打印一次.
有什么想法可能来自哪里?
我正在尝试将PCA9557 I / O扩展器添加到I2C总线上基于手臂的系统上。系统已经在不同的I2C总线上具有另一个I / O扩展器。我试图弄清楚如何指定新扩展器上的针脚获得的GPIO编号,以及如何使它们都能正常工作。
这是I2C总线2下现有扩展器的设备树部分:
i2c2: i2c@e8007000 {
status = "ok";
pca9539: pca9539@74 {
compatible = "nxp,pca9539";
reg = <0x74>;
interrupt-parent = <&gpio>;
interrupts = <9 0x0>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
};
};
Run Code Online (Sandbox Code Playgroud)
使用上述方法,现有的I / O扩展器(带有16个GPIO)在Linux中显示为/ sys / class / gpio / gpiochip128,公开了GPIO编号128-143。GPIO 0-127内置于主机处理器中。
我为I2C总线0上的新扩展器添加了以下内容:
i2c0: i2c@e8003000 {
status = "ok";
pca9557: pca9557@18 {
compatible = "nxp,pca9557";
reg = <0x18>;
gpio-controller;
#gpio-cells = <2>;
};
Run Code Online (Sandbox Code Playgroud)
我还修改了内核配置,以构建GPIO_PCA953X驱动程序,该驱动程序应支持PCA9557。
当我将以上内容添加到设备树中进行编译和引导时,我现在看到映射为/ sys / class …
我想使用Arduino作为i2c奴隶.但我要求Arduino通过向多个i2c地址注册来充当多个设备.
这可能不是人们通常会做的事情,但这是我做这件事的原因:
我想用Arduino作为Spektrum遥测的遥测传感器.遥测接收器有一些i2c插头,连接到多个传感器(电流0x02,电压0x03,空速0x11等),每个传感器都具有遥测接收器所需的固定i2c地址.
我想使用一个 Arduino作为所有这些设备,通过注册所有上述地址,并适当地响应读数.
我可以使用每个传感器一个Arduino,这看起来很傻,因为我可以使用一个Arduino pro-mini执行所有这些读数.
我知道你可以使用注册Arduino
Wire.begin(0x02);
Run Code Online (Sandbox Code Playgroud)
但是我需要类似的东西(伪代码)
Wire.begin(0x02, 0x03, 0x11);
Run Code Online (Sandbox Code Playgroud)
当收到请求时,我需要知道Arduino被查询的地址.
例如(伪代码)
void receiveEvent(byte address, int bytesReceived){
if(address == 0x02){
// Current reading
}
else if(address == 0x03){
// Voltage reading
}
else if(address == 0x11){
// Airspeed reading
}
}
Run Code Online (Sandbox Code Playgroud)
任何意见,将不胜感激.
我正在尝试编写一个代码,在其中我在 arduino 中运行我的主程序,并在需要时从树莓派的 i2c 总线获取数据。因此,我需要将我的 arduino 配置为 I2C Master,将 raspberry pi 配置为 I2C slave。是否有可能以与使 pi 为主而 arduino 为从属相同的方式来做到这一点?如果没有,还有其他可能的方法吗?
PS:-我只做一对一的通信,即arduino为主,树莓为从。没有连接其他设备。
谢谢你的帮助。
我有一个python类,用于抽象通过i2c连接的专用设备(功率传感器)。我将python-smbus模块用于I2c访问。当然,在该类中,我有current_ma使用smbus.SMBus()该类的方法(即,以毫安为单位返回当前值)。
import smbus
class PowerSensor(object):
def __init__(self, bus, addr):
self.__bus = smbus.SMBus(bus)
self.__addr = addr
def current_ma(self):
data = self.__bus.read_i2c_block_data(self.__addr, 0x04)
if data[0] >> 7 == 1:
current = data[0] * 256 + data[1]
if current & (1 << 15):
current = current - (1 << 16)
else:
current = (data[0] << 8) | (data[1])
return current / 10
Run Code Online (Sandbox Code Playgroud)
要对current_ma方法进行单元测试,我必须模拟smbus访问。我的第一个想法是修补该read_i2c_block_data方法:
mock.patch('power_sensor.smbus.SMBus.read_i2c_block_data')
Run Code Online (Sandbox Code Playgroud)
但是,如果我在执行测试时这样做,则会得到:
TypeError: can't set attributes of built-in/extension type 'smbus.SMBus'
Run Code Online (Sandbox Code Playgroud)
我很确定,这是因为smbus …
如何将 i2c 连接到 Arduino uno 的 20x4 LCD 显示器上的背光调暗?
我用的是LiquidCrystal_I2C.h图书馆,我可以打开与光的和
lcd.backlight();
与
lcd.noBacklight();
但我不想完全关闭背光:我想把它调暗。
我试图找出为什么当我尝试写入 I2C 时,即使我使用 CDLL,Python 中的相同代码的工作速度也比 C 慢 25 倍。下面我将逐步描述我正在做的所有细节。
树莓派版本:Raspberry PI 3 Model B
操作系统:Raspbian Buster Lite 版本:2019 年 7 月
GCC 版本:gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Python 版本:Python 3.7.3
尽管 I2C,我正在使用的设备是 MCP23017。我所做的就是将 0 和 1 写入引脚 B0。这是我用 C 编写的代码:
// test1.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <time.h>
int init() {
int fd = open("/dev/i2c-1", O_RDWR);
ioctl(fd, I2C_SLAVE, 0x20);
return fd;
}
void deinit(int fd) {
close(fd);
}
void makewrite(int fd, int v) …Run Code Online (Sandbox Code Playgroud)