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在,一个简单的地磁计就会让人崩溃的!

转载于:https://www.cnblogs.com/wb4916/p/9818854.html

461在全志r16平台tinav3.0系统下使用地磁计QMC5883L相关推荐

  1. 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 ...

  2. 双路E5平台PVE7.0系统GTX1060 显卡直通

    双路E5平台PVE7.0系统GTX1060 显卡直通 刚通,熟悉的错误消失了,有点失落,有点不知所措.直通成功了,开机能跑好几套系统(win10系统还能直通显卡玩游戏). 使用鲁大师对比物理机和虚机的 ...

  3. 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 ...

  4. 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 ...

  5. android9.0系统下,如何保活

    android9.0系统下,讨论如何延长APP退到后台的保活/复活时间 一.7.0及以上不存在真正意义的保活. 二.盘点目前在9.0上,可能有效的"白色手段"保活手段(这里不讨论黑 ...

  6. android设置静态i,关于Android4.0系统下如何设置wlan静态ip的设置(转)

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 估计有不少人都以为Android4.0系统下如何设置wlan静态ip地址吧,其实不是Android4.0的问题,只是设置上有点区别而已,下面重新教大家如何 ...

  7. RK3229平台Android6.0系统的一些定制性需求开发

    1.默认语音.地区.时区 device/rockchip/rk322x/rk322x_box/system.prop persist.sys.language=zh #简体中文 persist.sys ...

  8. RK3229平台Android6.0系统添加广升OTA升级功能

    添加脚本: build/core/FotaInfo.sh #!/bin/bash#********Do not modify this file. If you want modify this fi ...

  9. 在WinCE 6.0系统下实现USB功能定制

    USB的广泛应用就不用多说了,相信目前的各个领域的嵌入式产品中,很少有不用USB的.USB是主从结构的,分为USB Host和USB Slave,从USB1.0,USB1.1到现在的USB2.0,基于 ...

最新文章

  1. Algorithm——最长公共前缀
  2. 用文件fw读写链表_用FORTRAN95写的sgy文件读写程序
  3. C语言输出长方柱的体积,需要求3个长方柱的体积,请编写一个基于对象的程序。数据成员包括length(长)、width(宽)、 height(高)。要求用成员函数实现以下功能...
  4. mysql 上一条_mysql选择上一条、下一条数据记录
  5. 前端学习(1932)vue之电商管理系统电商系统之tree树形控件
  6. 探讨一下常见支付系统的对外接口
  7. 机器学习:用正规方程法求解线性回归
  8. 【精品】好用的验证码工具类VerifyCodeUtils
  9. C#读取网卡地址的几种方法
  10. 网易有道招银 前端面经
  11. [Constraints 18-5210] No constraints selected for write.
  12. php yield 携程,爬取携程国内地区攻略评论
  13. 解决WIN10播放AVI等格式视频黑屏只有声音的问题
  14. 2017第15届中国(武汉)国际汽车服务产业博览会会刊(参展商名录)
  15. Win11预装软件怎么卸载?Win11如何精简预装应用程序
  16. 计算机小知识140,电脑小知识140个小技巧(7)
  17. onmouseover和onmouseout的烦恼
  18. 创业穷途,我要加入丐帮
  19. C#委托和事件的概念
  20. .ren助力高校BBS圈,sdada.ren为山工艺学子服务~

热门文章

  1. 每天一道LeetCode-----生命游戏
  2. MCS-51单片机的指令时序
  3. HDU - 6704 K-th occurrence (后缀数组+主席树)
  4. java 远程shell脚本_java通过ssh连接服务器执行shell命令详解及实例
  5. MySQL的原理以及流程_MySQL的复制原理以及流程?
  6. qprocess调用linux命令
  7. Python生成随机数总结
  8. 8086标志寄存器介绍及作用(未完)
  9. IEDA快速书写代码快捷键
  10. [BUUCTF-pwn]——wustctf2020_name_your_dog