|
发表于 2019-5-16 17:21:53
49215 浏览 5 回复
硬件i2c6问题,一直报错
最近在用i2c_sda6、i2c_scl6这两个引脚给另一片单片机通信,但是仿照视频31里的i2c设备驱动仿写了,然后下载到开发板里,出现以下情况:[root@iTOP-4412]# insmod i2c_stm8.ko
[ 41.431201] ==i2c_stm8_init:
[ 41.765040] ==i2c_io_init:
[ 41.766351] ==i2c_stm8_init:
[ 41.769254] ==i2c_stm8_probe:
[root@iTOP-4412]# ./app_i2c
open /dev/i2c_control!
APP open /dev/i2c_control success!
[ 51.550155] s3c-i2c s3c2440-i2c.6: timeout waiting for bus idle
i2c read reg 0xa6 data is 0xa6!
[ 52.525130] CPU1: shutdown
[ 53.024030] CPU2: shutdown
[ 55.550157] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 59.550155] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 59.554666] read reg error!
i2c read reg 0x00 data is 0x00!
[ 63.555051] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 64.641342] failed to copy MFC F/W during init
[ 67.560159] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 67.564674] write reg 0x00 error!
[ 71.021874] CPU3: shutdown
[ 71.565142] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 75.570147] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 75.574660] read reg error!
i2c read reg 0x00 data is 0x00!
所以我想问下 为啥会这样,是还有什么驱动在占用i2c6吗,而且我已经去掉了spi、can总线的驱动的还是这样,是什么问题,是设备驱动写的有问题吗,下面是我的设备驱动代码:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#include <linux/regulator/consumer.h>
#include <mach/gpio.h>
#include <plat/gpio-cfg.h>
#include <asm/uaccess.h>
#include <linux/miscdevice.h>
static struct i2c_client *this_client;
#define I2C_SDA6 EXYNOS4_GPC1(3)
#define I2C_SCL6 EXYNOS4_GPC1(4)
static int i2c_open_func(struct file *filp)
{
return 0;
}
static int i2c_release_func(struct file *filp)
{
return 0;
}
static ssize_t i2c_read_func(struct file *filp, char __user *buffer, size_t count, loff_t *ppos){
int ret;
u8 reg_data;
ret = copy_from_user(®_data,buffer,1);
struct i2c_msg msgs[] = {
{
.addr = this_client->addr, //0x38
.flags = 0, //写
.len = 1, //要写的数据的长度
.buf = ®_data,
},
{
.addr = this_client->addr,
.flags = I2C_M_RD,
.len = 1,
.buf = ®_data,
},
};
ret = i2c_transfer(this_client->adapter, msgs, 2);
if (ret < 0) {
pr_err("read reg error!\n");
}
ret = copy_to_user(buffer,®_data,1);
return ret;
}
static ssize_t i2c_write_func(struct file *filp, char __user *buffer, size_t count, loff_t *ppos){
int ret;
u8 buf[2];
struct i2c_msg msgs[1];
ret = copy_from_user(&buf,buffer,2);
msgs[0].addr = this_client->addr; //0x38
msgs[0].flags = 0; //写
msgs[0].len = 2; //第一个是要写的寄存器地址,第二个是要写的内容
msgs[0].buf = buf;
ret = i2c_transfer(this_client->adapter, msgs, 1);
if (ret < 0) {
pr_err("write reg 0x%02x error!\n",buf[0]);
}
ret = copy_to_user(buffer,buf,1);
return ret;
}
static struct file_operations i2c_ops = {
.owner = THIS_MODULE,
.open = i2c_open_func,
.release= i2c_release_func,
.write = i2c_write_func,
.read = i2c_read_func,
};
static struct miscdevice i2c_dev = {
.minor = MISC_DYNAMIC_MINOR,
.fops = &i2c_ops,
.name = "i2c_control",
};
static int i2c_stm8_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
//unsigned char val;
printk("==%s:\n", __FUNCTION__);
//i2c_tes_read_fw_reg(client,&val);
this_client = client;
misc_register(&i2c_dev);
return 0;
}
static int __devexit i2c_stm8_remove(struct i2c_client *client)
{
i2c_set_clientdata(client, NULL);
misc_deregister(&i2c_dev);
printk("==%s:\n", __FUNCTION__);
return 0;
}
static const struct i2c_device_id i2c_stm8_id[] = {
{ "i2c_stm8", 0 },
{ }
};
static struct i2c_driver i2c_stm8_driver = {
.probe = i2c_stm8_probe,
.remove = __devexit_p(i2c_stm8_remove),
.id_table = i2c_stm8_id,
.driver = {
.name = "i2c_stm8",
.owner = THIS_MODULE,
},
};
static void i2c_io_init()
{
int ret;
ret = gpio_request(I2C_SCL6, "I2C_SCL6");
if(ret) {
printk(KERN_ERR "failed to request TP1_EN for I2C control\n");
}
gpio_direction_output(I2C_SCL6, 1);
s3c_gpio_cfgpin(I2C_SCL6, S3C_GPIO_OUTPUT);
s3c_gpio_setpull(I2C_SCL6, S3C_GPIO_PULL_NONE);
gpio_free(I2C_SCL6);
mdelay(5);
ret = gpio_request(I2C_SDA6, "I2C_SDA6");
if(ret) {
printk("i2c_io_test: Fialed to request I2C_SDA6 \n");
}
gpio_direction_output(I2C_SDA6, 1);
s3c_gpio_cfgpin(I2C_SDA6, S3C_GPIO_OUTPUT);
s3c_gpio_setpull(I2C_SDA6, S3C_GPIO_PULL_NONE);
gpio_free(I2C_SDA6);
msleep(300);
printk("==%s: \n", __FUNCTION__);
}
static int __init i2c_stm8_init(void)
{
printk("==%s:\n", __FUNCTION__);
i2c_io_init();
printk("==%s:\n", __FUNCTION__);
return i2c_add_driver(&i2c_stm8_driver);
}
static void __exit i2c_stm8_exit(void)
{
printk("==%s:\n", __FUNCTION__);
i2c_del_driver(&i2c_stm8_driver);
}
late_initcall(i2c_stm8_init);
module_exit(i2c_stm8_exit);
MODULE_AUTHOR("xunwei_rty");
MODULE_DESCRIPTION("TsI2CTest");
MODULE_LICENSE("GPL");
所以想问问谁能我看看,万分感激,已经搞了很久了
’
|
|
|
|
|
|
|
|
在单片机中,可以用io口模拟i2c,用于学习i2c的基本协议~
在单片机中moii2c的读写,速度是可以任意变的。
实际上标准的i2c只支持两种速率100k和400k(没记错的话)
不知道单片机作为从机端,它能够提供这样的翻转速度么?对于单片机的普通gpio,100k的翻转频率是非常高的 |
|
|
|
|
|
|
|
楼主|
发表于 2019-5-22 16:54:30
?? 为什么会出错,是设备驱动的代码写错了吗,你好,可以帮忙看看吗 |
|
|
|
|
|
|
|
没注意看我写的么?
单片机的io反应速度能够达到100K么?
可以达到了再做后面的呀!
linux上的都是i2c控制器,传输速度是标准i2c的100k或者400k~
单片机作为从机,能行么?
如果单纯的学习i2c,搞个eeprom通信就成的,内核自带了驱动 |
|
|
|
|
|
|
|
发表于 2019-5-30 12:21:13
[ 71.565142] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
[ 75.570147] s3c-i2c s3c2440-i2c.6: cannot get bus (error -110)
-------------------------------------------------------------------------------------------
@admin, 我也遇到相同的情况, I2C_7 可以使用, I2C_6 驱动程序注册不成功, 楼主的程序, 驱动程序还没注册成功, 我 按照 贵司<视频31>的方法, 用 I2C_7, 读取AT2C02 正常, 但改为 I2C_6 时, 出现 'get bus' 出错的情况(与楼主相同的情况), 感觉是 make menuconfig 时, 没有去掉占用 I2C_6 的设备, 但我没找到哪一个驱动占用的I2C_6
|
|
|
|
|
|
|
|
发表于 2021-4-28 08:30:50
你好,请问你的I2C_7的驱动程序是参考的31吗, 我用I2C_7 一直显示 no device or address |
|
|
|
|
|
|
登录或注册
扫一扫关注迅为公众号
|