日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

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

發布時間:2024/4/17 windows 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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在,一個簡單的地磁計就會讓人崩潰的!

轉載于:https://www.cnblogs.com/wb4916/p/9818854.html

總結

以上是生活随笔為你收集整理的461在全志r16平台tinav3.0系统下使用地磁计QMC5883L的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。