461在全志r16平台tinav3.0系统下使用地磁计QMC5883L
461在全志r16平台tinav3.0系统下使用地磁计QMC5883L
2018/9/7 14:08
版本:V1.0
开发板:SC3817R
SDK:tina v3.0
(基本确认全志tina v3.0的SDK中自带的驱动程序qmc5883.c是有问题的,鉴定完毕!)
1、01原始编译全志r16平台tinav3.0系统:
rootroot@cm88:~$ cd /home/wwt
rootroot@cm88:/home/wwt$
rootroot@cm88:~$ cd /home/wwt
rootroot@cm88:/home/wwt$
rootroot@cm88:/home/wwt$
rootroot@cm88:/home/wwt$ md5sum tina_v3.0_20180606_1711git.tar.gz
ebf7ea460473f13a7f64248ed61cf998 tina_v3.0_20180606_1711git.tar.gz
rootroot@cm88:/home/wwt$
rootroot@cm88:/home/wwt$ tar zxvf tina_v3.0_20180606_1711git.tar.gz
rootroot@cm88:/home/wwt$
rootroot@cm88:/home/wwt$ cd tina_v3.0/
rootroot@cm88:/home/wwt/tina_v3.0$
rootroot@cm88:/home/wwt/tina_v3.0$
rootroot@cm88:/home/wwt/tina_v3.0$ source build/envsetup.sh
(请严重注意:lunch之后的选项是环境依赖的,请选择astar_parrot-tina前的实际数值!)
rootroot@cm88:/home/wwt/tina_v3.0$ lunch
You're building on Linux
Lunch menu... pick a combo:
5. astar_parrot-tina
Which would you like?5
rootroot@cm88:/home/wwt/tina_v3.0$ make -j12
rootroot@cm88:/home/wwt/tina_v3.0$ pack -d
2、将qmc5883l开发板接到R16开发板的I2C1总线上:
rootroot@cm88:/home/wwt/tina_v3.0$ make kernel_menuconfig
Device Drivers --->
<*> UAV SENSORS support --->
--- UAV SENSORS support
< > icm20689
< > mpu6050
< > fbm320
< > hmc5883
< > qmc5883
修改为:
<*> qmc5883
< > ks103
< > gps_power
< > lis3mdl
rootroot@cm88:/home/wwt/tina_v3.0$ make -j12
rootroot@cm88:/home/wwt/tina_v3.0$ pack -d
刷机之后:
root@TinaLinux:/#
root@TinaLinux:/# lsmod
bcmdhd 610623 0
disp 966363 2 mali
gt82x 6569 0
lcd 34617 0
mali 410890 0
snd_mixer_oss 12246 1 snd_pcm_oss
snd_pcm_oss 36999 0
snd_seq_device 4779 0
xt_LOG 6190 0
xt_TCPMSS 1923 0
xt_comment 569 0
xt_limit 1202 0
xt_mac 697 0
xt_mark 762 0
xt_multiport 1322 0
xt_time 1605 0
root@TinaLinux:/#
root@TinaLinux:/#
root@TinaLinux:/# cd /sys/class/i2c-adapter/
root@TinaLinux:/sys/class/i2c-adapter#
root@TinaLinux:/sys/class/i2c-adapter# ll
drwxr-xr-x 2 root root 0 Jan 1 08:01 .
drwxr-xr-x 50 root root 0 Jan 1 08:01 ..
lrwxrwxrwx 1 root root 0 Jan 1 08:01 i2c-0 -> ../../devices/platform/twi.0/i2c-0
lrwxrwxrwx 1 root root 0 Jan 1 08:01 i2c-1 -> ../../devices/platform/twi.1/i2c-1
lrwxrwxrwx 1 root root 0 Jan 1 08:01 i2c-2 -> ../../devices/platform/twi.2/i2c-2
root@TinaLinux:/sys/class/i2c-adapter# cd i2c-1/
(开心吧,QMC5883L挂载到i2c-1上了!)
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1# ll
drwxr-xr-x 5 root root 0 Jan 1 08:01 .
drwxr-xr-x 4 root root 0 Jan 1 08:01 ..
drwxr-xr-x 3 root root 0 Jan 1 08:01 1-000d
--w------- 1 root root 4096 Jan 1 08:01 delete_device
lrwxrwxrwx 1 root root 0 Jan 1 08:01 device -> ../../twi.1
drwxr-xr-x 3 root root 0 Jan 1 08:01 i2c-dev
-r--r--r-- 1 root root 4096 Jan 1 08:01 name
--w------- 1 root root 4096 Jan 1 08:01 new_device
drwxr-xr-x 2 root root 0 Jan 1 08:01 power
lrwxrwxrwx 1 root root 0 Jan 1 08:01 subsystem -> ../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Jan 1 08:01 uevent
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1# cd 1-000d/
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d# ll
drwxr-xr-x 3 root root 0 Jan 1 08:01 .
drwxr-xr-x 5 root root 0 Jan 1 08:01 ..
lrwxrwxrwx 1 root root 0 Jan 1 08:02 driver -> ../../../../../bus/i2c/drivers/qmc5883
-r--r--r-- 1 root root 4096 Jan 1 08:02 modalias
-r--r--r-- 1 root root 4096 Jan 1 08:02 name
drwxr-xr-x 2 root root 0 Jan 1 08:02 power
lrwxrwxrwx 1 root root 0 Jan 1 08:02 subsystem -> ../../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Jan 1 08:02 uevent
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d# cat name
qmc5883
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1/1-000d# cd /bin
root@TinaLinux:/bin#
root@TinaLinux:/bin#
root@TinaLinux:/bin# ll he*
-rwxr-xr-x 1 root root 20677 May 21 2018 healthd
-rw-rw-rw- 1 root root 8192 Sep 6 2018 hello_mod_test
root@TinaLinux:/bin# chmod 777 hello_mod_test
root@TinaLinux:/bin#
root@TinaLinux:/bin#
(就算你硬件电路都接好了,还是不通的!)
root@TinaLinux:/bin# ./hello_mod_test
[ 96.357521] ==qmc5883_open==
[ 96.372068] sunxi_i2c_do_xfer()1001 - [i2c0] incomplete xfer (status: 0x20, dev addr: 0xd)
[ 96.392884] ID=ba(186)
Failed at open():: Operation not permitted
root@TinaLinux:/bin#
root@TinaLinux:/bin#
root@TinaLinux:/bin# cd /sys/class/i2c-adapter/
root@TinaLinux:/sys/class/i2c-adapter#
(偶然的原因,在i2c-0设备节点下面也发现了0x0D这个从机地址,并且确认是QMC5883L,太神奇了!确认是全志的驱动不严谨,没有经过验证!)
root@TinaLinux:/sys/class/i2c-adapter# cd i2c-0
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0#
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0# ll
drwxr-xr-x 6 root root 0 Jan 1 08:01 .
drwxr-xr-x 4 root root 0 Jan 1 08:01 ..
drwxr-xr-x 3 root root 0 Jan 1 08:01 0-000d
drwxr-xr-x 3 root root 0 Jan 1 08:03 0-005d
--w------- 1 root root 4096 Jan 1 08:03 delete_device
lrwxrwxrwx 1 root root 0 Jan 1 08:03 device -> ../../twi.0
drwxr-xr-x 3 root root 0 Jan 1 08:01 i2c-dev
-r--r--r-- 1 root root 4096 Jan 1 08:03 name
--w------- 1 root root 4096 Jan 1 08:03 new_device
drwxr-xr-x 2 root root 0 Jan 1 08:03 power
lrwxrwxrwx 1 root root 0 Jan 1 08:03 subsystem -> ../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Jan 1 08:03 uevent
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0#
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0#
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0# cd 0-000d
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0/0-000d# ll
drwxr-xr-x 3 root root 0 Jan 1 08:01 .
drwxr-xr-x 6 root root 0 Jan 1 08:01 ..
lrwxrwxrwx 1 root root 0 Jan 1 08:03 driver -> ../../../../../bus/i2c/drivers/qmc5883
-r--r--r-- 1 root root 4096 Jan 1 08:03 modalias
-r--r--r-- 1 root root 4096 Jan 1 08:03 name
drwxr-xr-x 2 root root 0 Jan 1 08:03 power
lrwxrwxrwx 1 root root 0 Jan 1 08:03 subsystem -> ../../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Jan 1 08:03 uevent
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0/0-000d#
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0/0-000d# cat name
qmc5883
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0/0-000d#
(不用怀疑,i2c-2设备节点上面也挂载了QMC5883L,基本确定是detect函数不严谨了!)
root@TinaLinux:/sys/devices/platform/twi.0/i2c-0/0-000d# cd ../../i2c-2
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2# ll
drwxr-xr-x 5 root root 0 Jan 1 08:01 .
drwxr-xr-x 4 root root 0 Jan 1 08:01 ..
drwxr-xr-x 3 root root 0 Jan 1 08:01 2-000d
--w------- 1 root root 4096 Jan 1 08:03 delete_device
lrwxrwxrwx 1 root root 0 Jan 1 08:03 device -> ../../twi.2
drwxr-xr-x 3 root root 0 Jan 1 08:01 i2c-dev
-r--r--r-- 1 root root 4096 Jan 1 08:03 name
--w------- 1 root root 4096 Jan 1 08:03 new_device
drwxr-xr-x 2 root root 0 Jan 1 08:03 power
lrwxrwxrwx 1 root root 0 Jan 1 08:03 subsystem -> ../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Jan 1 08:03 uevent
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2# cd 2-000d
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2/2-000d#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2/2-000d# ll
drwxr-xr-x 3 root root 0 Jan 1 08:01 .
drwxr-xr-x 5 root root 0 Jan 1 08:01 ..
lrwxrwxrwx 1 root root 0 Jan 1 08:03 driver -> ../../../../../bus/i2c/drivers/qmc5883
-r--r--r-- 1 root root 4096 Jan 1 08:03 modalias
-r--r--r-- 1 root root 4096 Jan 1 08:03 name
drwxr-xr-x 2 root root 0 Jan 1 08:03 power
lrwxrwxrwx 1 root root 0 Jan 1 08:03 subsystem -> ../../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Jan 1 08:03 uevent
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2/2-000d#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2/2-000d#
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2/2-000d# cat name
qmc5883
root@TinaLinux:/sys/devices/platform/twi.2/i2c-2/2-000d#
3、仔细比对qmc5883.c和成熟的驱动bma250.c之间的差异:
W:\tina_v3.0\lichee\linux-3.4\drivers\uav_sensors\qmc5883.c
W:\tina_v3.0\lichee\linux-3.4\drivers\hwmon\bma250.c
正确:bma250.c
/**
* gsensor_detect - Device detection callback for automatic device creation
* return value:
* = 0; success;
* < 0; err
*/
static int gsensor_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
int ret;
dprintk(DEBUG_INIT, "%s enter \n", __func__);
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;
if (twi_id == adapter->nr) {
for (i2c_num = 0; i2c_num < (sizeof(i2c_address)/sizeof(i2c_address[0]));i2c_num++) {
client->addr = i2c_address[i2c_num];
pr_info("%s:addr= 0x%x,i2c_num:%d\n",__func__,client->addr,i2c_num);
ret = i2c_smbus_read_byte_data(client,BMA250_CHIP_ID_REG);
pr_info("Read ID value is :%d",ret);
if ((ret &0x00FF) == BMA250_CHIP_ID) {
pr_info("Bosch Sensortec Device detected!\n" );
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
} else if((ret &0x00FF) == BMA150_CHIP_ID) {
pr_info("Bosch Sensortec Device detected!\n" \
"BMA150 registered I2C driver!\n");
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
return 0;
} else if((ret &0x00FF) == BMA250E_CHIP_ID) {
pr_info("Bosch Sensortec Device detected!\n" \
"BMA250E registered I2C driver!\n");
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
deep_suspend = 1;
return 0;
} else if((ret &0x00FF) == BMA223_CHIP_ID) {
pr_info("Bosch Sensortec Device detected!\n" \
"BMA223 registered I2C driver!\n");
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
deep_suspend = 1;
return 0;
}
}
pr_info("%s:Bosch Sensortec Device not found, \
maybe the other gsensor equipment! \n",__func__);
return -ENODEV;
} else {
return -ENODEV;
}
}
异常:qmc5883.c(I2C设备挂载I2C总线上的时候没有进行有效性检查)
static int qmc5883_i2c_test(struct i2c_client *client)
{
unsigned char id;
id = i2c_smbus_read_byte_data(client, QMC5883_ID_REG);
printk(KERN_INFO "ID=%x(%d)\r\n", id, id);
if (id != QMC5883_ID_VAL)
return -1;
return 0;
}
static int qmc5883_detect(struct i2c_client *client,
struct i2c_board_info *info)
{
pr_info("%s: addr=0x%x\n", __func__, client->addr);
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
(有效性检查缺失了,有可能是拿掉这部分的代码的时候拿多了!)
return 0;
}
参照修改qmc5883.c为:
static int qmc5883_detect(struct i2c_client *client,
struct i2c_board_info *info)
{
pr_info("%s: addr=0x%x\n", __func__, client->addr);
printk("**** wyb %s-%d-%s: addr=0x%02x\n", __FILE__, __LINE__, __func__, client->addr);
unsigned char id;
id = i2c_smbus_read_byte_data(client, QMC5883_ID_REG);
printk(KERN_INFO "ID=%x(%d)\r\n", id, id);
printk("**** wyb %s-%d-%s addr=0x%02x QMC5883_ID_REG=0x%02x ID=0x%02x(%d)\n", __FILE__, __LINE__, __func__, client->addr, QMC5883_ID_REG, id, id);
if (id != QMC5883_ID_VAL)
return -1;
strlcpy(info->type, SENSOR_NAME, I2C_NAME_SIZE);
//qmc5883_init_client(client);
//qmc5883_init_client(qmc5883_i2c_client);
return 0;
}
rootroot@cm88:/home/wwt/tina_v3.0$ make -j12
rootroot@cm88:/home/wwt/tina_v3.0$ pack -d
刷机之后(可以看见是0-360度水平转动!):
root@TinaLinux:/#
root@TinaLinux:/# cd /bin
root@TinaLinux:/bin#
root@TinaLinux:/bin# chmod 777 he
healthd hello_mod_test
root@TinaLinux:/bin# chmod 777 hello_mod_test
root@TinaLinux:/bin#
root@TinaLinux:/bin#
root@TinaLinux:/bin# ./hello_mod_test
[ 66.351808] ==qmc5883_open==
[ 66.357522] ID=ff(255)
[ 66.388057] ==qmc5883_init_client==
**** wyb hello_mod_test.c-80-main 0xdd, 0xfd, 0xcd, 0x02, 0xa5, 0x11,
**** wyb hello_mod_test.c-113-main x=-547, y=717, angle=-0.651707, degree=323
**** wyb hello_mod_test.c-80-main 0x12, 0x04, 0xf3, 0x04, 0x33, 0x10,
**** wyb hello_mod_test.c-113-main x=1042, y=1267, angle=0.688260, degree=39
**** wyb hello_mod_test.c-80-main 0x37, 0xf9, 0xc7, 0x06, 0x02, 0x0f,
**** wyb hello_mod_test.c-113-main x=-1737, y=1735, angle=-0.785974, degree=315
**** wyb hello_mod_test.c-80-main 0x85, 0x04, 0xf8, 0xf3, 0x99, 0x09,
**** wyb hello_mod_test.c-113-main x=1157, y=-3080, angle=-0.359340, degree=160
**** wyb hello_mod_test.c-80-main 0x73, 0x0a, 0x07, 0x0a, 0xda, 0x09,
**** wyb hello_mod_test.c-113-main x=2675, y=2567, angle=0.805998, degree=46
**** wyb hello_mod_test.c-80-main 0x28, 0x07, 0x3e, 0x0a, 0xe0, 0x0b,
**** wyb hello_mod_test.c-113-main x=1832, y=2622, angle=0.609855, degree=34
**** wyb hello_mod_test.c-80-main 0x9d, 0x08, 0xcf, 0x08, 0x21, 0x0c,
**** wyb hello_mod_test.c-113-main x=2205, y=2255, angle=0.774188, degree=44
**** wyb hello_mod_test.c-80-main 0xb5, 0x0b, 0xd7, 0x00, 0x26, 0x0c,
**** wyb hello_mod_test.c-113-main x=2997, y=215, angle=1.499181, degree=85
**** wyb hello_mod_test.c-80-main 0xef, 0x08, 0xd0, 0xfb, 0x4a, 0x0d,
**** wyb hello_mod_test.c-113-main x=2287, y=-1072, angle=-1.132471, degree=116
**** wyb hello_mod_test.c-80-main 0x99, 0x02, 0xd3, 0xf8, 0x8a, 0x0e,
**** wyb hello_mod_test.c-113-main x=665, y=-1837, angle=-0.347328, degree=161
**** wyb hello_mod_test.c-80-main 0x5d, 0xfb, 0x36, 0xfc, 0xbb, 0x0f,
**** wyb hello_mod_test.c-113-main x=-1187, y=-970, angle=0.885664, degree=230
**** wyb hello_mod_test.c-80-main 0xd1, 0xf7, 0xa7, 0xfc, 0x49, 0x0e,
**** wyb hello_mod_test.c-113-main x=-2095, y=-857, angle=1.182496, degree=247
**** wyb hello_mod_test.c-80-main 0x19, 0xf9, 0x9e, 0xfb, 0x8a, 0x0e,
**** wyb hello_mod_test.c-113-main x=-1767, y=-1122, angle=1.005056, degree=237
**** wyb hello_mod_test.c-80-main 0x53, 0xf6, 0x70, 0xfe, 0x15, 0x0e,
**** wyb hello_mod_test.c-113-main x=-2477, y=-400, angle=1.410693, degree=260
**** wyb hello_mod_test.c-80-main 0xb7, 0xf6, 0xf7, 0x08, 0x4b, 0x0c,
**** wyb hello_mod_test.c-113-main x=-2377, y=2295, angle=-0.802948, degree=314
**** wyb hello_mod_test.c-80-main 0x9f, 0xfc, 0x06, 0x0e, 0x15, 0x0b,
**** wyb hello_mod_test.c-113-main x=-865, y=3590, angle=-0.236440, degree=347
**** wyb hello_mod_test.c-80-main 0x69, 0x00, 0x3e, 0x0f, 0xda, 0x09,
**** wyb hello_mod_test.c-113-main x=105, y=3902, angle=0.026903, degree=1
**** wyb hello_mod_test.c-80-main 0xae, 0xf7, 0xa5, 0x02, 0xee, 0x0e,
**** wyb hello_mod_test.c-113-main x=-2130, y=677, angle=-1.263054, degree=288
**** wyb hello_mod_test.c-80-main 0xb0, 0xf8, 0xba, 0xf3, 0xee, 0xf6,
**** wyb hello_mod_test.c-113-main x=-1872, y=-3142, angle=0.537325, degree=210
^C[ 318.132610] ==qmc5883_release==
root@TinaLinux:/bin#
root@TinaLinux:/bin#
4、修正一个逻辑问题,是由上海矽睿的工程师发现的:
static int qmc5883_init_client(struct i2c_client *client)
{
uint8_t data = 0;
i2c_smbus_write_byte_data(client, QMC5883_RESET_REG, 0x01);
i2c_smbus_write_byte_data(client, 0x20, 0x40);
i2c_smbus_write_byte_data(client, 0x21, 0x01);
i2c_smbus_write_byte_data(client, QMC5883_CONTROL_REG, 0x0D);
mdelay(5);
while (data != 0x0D) {
mdelay(2);
data = i2c_smbus_read_byte_data(client, QMC5883_CONTROL_REG);
}
printk(KERN_INFO "==%s==\r\n", __func__);
return 0;
}
在应用程序open设备节点/dev/qmc5883的时候每次都去初始化QMC5883L,这是多此一举的!修改为:
static int iInit = 0;
static int qmc5883_init_client(struct i2c_client *client)
{
uint8_t data = 0;
printk("**** wyb %s-%d-%s 2018/9/6 10:43\n", __FILE__, __LINE__, __func__);
//iInit++;
if(iInit)
{
return 0;
}
i2c_smbus_write_byte_data(client, QMC5883_RESET_REG, 0x01);
i2c_smbus_write_byte_data(client, 0x20, 0x40);
i2c_smbus_write_byte_data(client, 0x21, 0x01);
i2c_smbus_write_byte_data(client, QMC5883_CONTROL_REG, 0x0D);
mdelay(5);
while (data != 0x0D) {
mdelay(2);
data = i2c_smbus_read_byte_data(client, QMC5883_CONTROL_REG);
}
printk(KERN_INFO "==%s==\r\n", __func__);
printk("**** wyb %s-%d-%s \n", __FILE__, __LINE__, __func__);
iInit++;
return 0;
}
增加读取角度的应用程序read_degree(Makefile省略了):
W:\tina_v3.0\package\allwinner\read_degree\src\read_degree.c
//https://blog.csdn.net/Sagittarius_Warrior/article/details/51067518
/*
* =====================================================================================
*
* Filename: hell_mod_test.c
*
* Description: hell_mod test app
*
* Version: 1.0
* Created: 06/20/2011 01:44:11 AM
* Revision: none
* Compiler: gcc
*
* Author: Tishion (shion), tishion@163.com
* Company: LIM
*
* =====================================================================================
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/ioctl.h>
#include <string.h>
#include <errno.h>
#include <math.h>
//#include "../hello_mod_ioctl.h"
int main()
{
char outbuf[512];
//int fd = open("/dev/hello", O_RDWR, S_IRUSR|S_IWUSR);
int fd = open("/dev/qmc5883", O_RDWR, S_IRUSR|S_IWUSR);
if(fd != -1)
{
while(1)
{
read(fd, outbuf, 6);
//printf("**** wyb %s-%d-%s 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, \n", __FILE__, __LINE__, __func__, outbuf[0], outbuf[1], outbuf[2], outbuf[3], outbuf[4], outbuf[5]);
int16_t x = ((int16_t) outbuf[1] << 8) | outbuf[0];
int16_t y = ((int16_t) outbuf[3] << 8) | outbuf[2];
double angle = atan(x*1.0/y);
//int degree = (int)(angle*180);
int degree = (int)(angle*57.3);
if(x>0)
{
if(y>0)
{
;
}
else
{
degree += 180;
}
}
else
{
if(y>0)
{
degree += 360;
}
else
{
degree += 180;
}
}
//printf("angle = %f\n",angle);
printf("**** wyb %s-%d-%s x=%d, y=%d, angle=%f, degree=%d\n\n", __FILE__, __LINE__, __func__, x, y, angle, degree);
sleep(1);
}
}
else
{
perror("Failed at open():");
}
return 0;
}
rootroot@cm88:/home/wwt/tina_v3.0$ make menuconfig
Allwinner --->
< > read_degree............................. read_degree just test the camera (NEW)
修改为:
<*> read_degree............................. read_degree just test the camera
5、调试故事一(上海矽睿的PM给的QMC5883L是老版本的):
芯片丝印:
L883
21C2
我司遵照贵司提供的更新的QMC5883L地磁计的模块的PIN脚定义重新接线,特意将ADO引脚拉高使得QMC5883L的7位为0x0D(8位为0x1C)
Q:\r16_tinav3.0\lichee\linux-3.4\drivers\uav_sensors\qmc5883.c
因为全志R16平台的tina v3.0的SDK中自带的驱动qmc5883.c的I2C从机地址为:0x0D(ADO引脚拉高)
编译之后不能获取QMC5883L的指南针数据,初步判断是qmc5883.c驱动不严谨。
直接使用SDK自带的bma250.c(博世的加速度传感器)这个成熟的驱动,然后修改其中的I2C从机地址,I2C1挂载bma250(QMC5883L)失败。
使用i2cdetect扫描I2C1总线,发现不接QMC5883L地磁计的模块有有7位地址:0x19 和 0x23。
有您的的模块进行I2C1的扫描:有7位地址:0x19和0x1e以及0x23,初步判定您提供的设备的I2C从机7位地址是0x1e。请问您确认提供的是QMC5883L地磁计模块?
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1#
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1# i2cdump -f -y 1 0x1e
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 10 20 03 01 49 00 67 00 a0 03 48 34 33 00 00 3c ? ??I.g.??H43..<
10: 00 00 00 00 00 00 00 00 00 00 00 00 0e 06 e8 10 ............????
20: 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ........?.......
30: 00 00 00 14 12 65 77 00 a0 00 07 00 00 00 00 00 ...??ew.?.?.....
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 10 20 03 01 49 00 67 00 a0 03 48 34 33 00 00 3c ? ??I.g.??H43..<
90: 00 00 00 00 00 00 00 00 00 00 00 00 0e 06 e8 10 ............????
a0: 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ........?.......
b0: 00 00 00 14 12 65 77 00 a0 00 07 00 00 00 00 00 ...??ew.?.?.....
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1#
i2c1总线上挂载的设备扫描:
root@TinaLinux:/sys/devices/platform/twi.1/i2c-1# i2cdetect -y -r 1
0 1 2 3 4 5 6 7 8 [ 1355.681919] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x3)
9 a b c d e f
00: -- [ 1355.706430] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x4)
-- [ 1355.723033] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x5)
-- [ 1355.738998] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x6)
-- [ 1355.760575] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x7)
-- [ 1355.775136] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x8)
-- [ 1355.784875] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x9)
-- [ 1355.794893] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0xa)
-- [ 1355.804560] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0xb)
-- [ 1355.814281] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0xc)
-- [ 1355.823831] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0xd)
-- [ 1355.833574] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0xe)
-- [ 1355.843271] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0xf)
--
10: [ 1355.853265] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x10)
-- [ 1355.863497] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x11)
-- [ 1355.873157] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x12)
-- [ 1355.882938] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x13)
-- [ 1355.892700] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x14)
-- [ 1355.902386] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x15)
-- [ 1355.912146] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x16)
-- [ 1355.921886] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x17)
-- [ 1355.931622] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x18)
-- 19 [ 1355.941524] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x1a)
-- [ 1355.951325] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x1b)
-- [ 1355.961023] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x1c)
-- [ 1355.970736] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x1d)
-- 1e [ 1355.980597] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x1f)
--
20: [ 1355.990360] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x20)
-- [ 1356.000649] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x21)
-- [ 1356.010374] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x22)
-- 23 [ 1356.020271] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x24)
-- [ 1356.029950] sunxi_i2c_do_xfer()1001 - [i2c1] incomplete xfer (status: 0x48, dev addr: 0x25)
参考资料:
https://blog.csdn.net/u013308744/article/details/50128651
i2cdetect/i2cdump 查看系统的i2c bus数量以及i2c device挂载地址
https://blog.csdn.net/mantis_1984/article/details/18254767
i2c-tools的使用方法及举例
(内核)
https://www.cnblogs.com/tid-think/p/9112531.html
arm开发板上找不到/dev/i2c-*设备
6、调试故事二:上海矽睿的PM给的另一片QMC5883L,我读寄存器获取的x、y、z的值都很小,变动范围是-20到20。上海矽睿的FAE很有经验,QMC5883L焊接不良。要不是他们的FAE在,一个简单的地磁计就会让人崩溃的!
461在全志r16平台tinav3.0系统下使用地磁计QMC5883L的更多相关文章
- 460在全志r16平台tinav3.0系统下使用i2c-tools
460在全志r16平台tinav3.0系统下使用i2c-tools 2018/9/6 19:05 版本:V1.0 开发板:SC3817R SDK:tina v3.0 1.01原始编译全志r16平台ti ...
- 501在全志r16平台tinav3.0系统下调通pwm1的10KHZ波形
501在全志r16平台tinav3.0系统下调通pwm1的10KHZ波形 2018/10/19 19:52 版本:V1.0 开发板:SC3817R SDK:tina v3.0 1.01原始编译全志r1 ...
- 009全志R16平台tinav3.0下编译不过的问题
009全志R16平台tinav3.0下编译不过的问题 2018/11/13 11:39 版本:V1.0 开发板:SC3817R SDK:tina v3.0 1.01原始编译全志r16平台tinav3. ...
- 001原始编译全志r6平台tinav3.0.2系统
001原始编译全志r6平台tinav3.0.2系统 2018/6/8 11:32 版本:V1.0 开发板:R6 SDK:tina v3.0.2 1.01原始编译全志r16平台tinav3.0系统: r ...
- 31全志r58平台Android4.4.2下打开USB摄像头
31全志r58平台Android4.4.2下打开USB摄像头 2018/10/26 16:00 版本:V1.0 开发板:SC5806 1.系统编译:(略) 2.需要修改的文件: W:\r58_andr ...
- 02全志r58平台Android4.4.4下关闭内核中的CPU的开启关闭提示
02全志r58平台Android4.4.4下关闭内核中的CPU的开启关闭提示 2017/8/18 13:53 版本:V1.0 开发板:SC5806(全志R58平台) SDK:android4.4.4 ...
- <03>labview在winCE6.0系统下的程序移植与界面开发
任务布置:labview与winCE开发<3> 要求一:学会TouchPane的环境配置,建立调试通道:要求二:掌握触控屏幕界面优化: 正文: 今天介绍labview虚拟仪器软件中 Tou ...
- 关于iphone6/5/4s 在iOS8.0系统下 仅仅读@3x图片
做iphone6和plus适配时候发现一个问题,先来看图(一下讨论所有在真机下完毕,非模拟器) 128*750图片是 nav@2x.png watermark/2/text/aHR0cDovL2Js ...
- ionic3 在ios9.0 系统下 会出现ReferenceError:Can't find variable:Intl 错误提示
ionic3 框架开发app 在ios 9.0版本中 ReferenceError:Can't find variable:Intl 错误提示: 在index.html 文件中添加 <scri ...
随机推荐
- Ctags基本配置
一般linux系统都会自带ctags,也可输入"ctags"看有木有该命令.有的话速度配置吧,没有话yum install ctags安装吧. 打开vim 配置文件,要是没该文件就 ...
- DataTables warning requested unknown parameter
This is possibly the most cryptic warning message that DataTables will show. It is a short error mes ...
- Navicat 提示Cannot create oci environment 解决方案
一直在使用 Navicat ,这是一个数据库客户端软件,能连接多种不同类型的数据库,给我们的日常的工作带来了不少的便捷.当Navicat 就莫名其妙的不能连接 oracle 数据库了.总是提示如下错误 ...
- YTU 2559: “心脏出血”
2559: "心脏出血" 时间限制: 1 Sec 内存限制: 128 MB 提交: 5 解决: 2 题目描述 2014年4月,一个开源加密库OpenSSL的严重漏洞" ...
- mongodb 关闭服务 mongod -f /root/mongodb/bin/xx.conf --shutdown
/root/mongodb/bin/mongod -f /root/mongodb/bin/xx.conf --shutdown
- mac toad下建表问题
mac toad下创建表,表名会自动多一个双引号,如:tb_test => "tb_test",这个应该是mac系统智能引号问题导致的,目前还没找到解决办法,只能手动用sql ...
- Spark 大数据文本统计
此程序功能: 1.完成对10.4G.csv文件各个元素频率的统计 2.获得最大的统计个数 3.对获取到的统计个数进行降序排列 4.对各个元素出现次数频率的统计 import org.apache.sp ...
- TCP、UDP和HTTP关系
TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层.IP:网络层协议: TCP和UDP:传输层协议:TCP提供有保证的数据传输,UDP不提供. HTTP:应用层协议(超文本传输协议): 如 ...
- OSI模型与TCP/IP模型基础
一.OSI七层模型 OSI(Open System Interconnection),OSI是一个开放性的通行系统互连参考模型,是一个协议规范.OSI七层模型是一种框架性的设计方法 ,建立七层模型的主 ...
- E201700525-hm
skeleton n. 骨骼; (建筑物等的) 骨架; 梗概; 骨瘦如柴的人(或动物);adj. 骨骼的; 骨瘦如柴的; 概略的; 基本的; cloud n. 云; 云状物; invoke ...