sanjaywu / bh1750_sensor

基于RT-Thread的BH1750FVI光照强度传感器驱动软件包,含旧版本(非sensor框架)和新版本(sensor框架)
Apache License 2.0
5 stars 2 forks source link

根据文档初始化代码报错,怎么解决? #2

Open qiaowei361 opened 3 years ago

qiaowei361 commented 3 years ago

`#include

define DBG_TAG "main"

define DBG_LVL DBG_LOG

include

include

include

include

include "bh1750.h"

int main(void) { return RT_EOK; } int bh1750_port(void) { struct rt_sensor_config cfg; cfg.intf.dev_name = "i2c2"; //根据传感器所挂的I2C设备修改 cfg.intf.user_data = (void *)BH1750_ADDR; cfg.irq_pin.pin = RT_PIN_NONE; rt_hw_bh1750_init("bh1750", &cfg); rt_hw_bh return 0; } INIT_APP_EXPORT(bh1750_port);`

image

报如下错误: make -j4 all arm-none-eabi-gcc "../applications/main.c" ../applications/main.c: In function 'bh1750_port': ../applications/main.c:37:5: warning: implicit declaration of function 'rt_hw_bh1750_init' [-Wimplicit-function-declaration] rt_hw_bh1750_init("bh1750", &cfg); ^ linking... ./applications/main.o: In functionbh1750_port': F:\STM32\STM32_F411CE_U8G2_sensor\Debug/../applications/main.c:32: multiple definition of bh1750_port' ./packages/bh1750-latest/sensor_rohm_bh1750.o:F:\STM32\STM32_F411CE_U8G2_sensor\Debug/../packages/bh1750-latest/sensor_rohm_bh1750.c:143: first defined here ./applications/main.o: In functionmain': F:\STM32\STM32_F411CE_U8G2_sensor\Debug/../applications/main.c:28: multiple definition of `__rt_init_bh1750_port' ./packages/bh1750-latest/sensor_rohm_bh1750.o:F:\STM32\STM32_F411CE_U8G2_sensor\Debug/../packages/bh1750-latest/sensor_rohm_bh1750.c:21: first defined here collect2.exe: error: ld returned 1 exit status make: *** [makefile:79: rtthread.elf] Error 1 "make -j4 all" terminated with exit code 2. Build might be incomplete.

19:04:15 Build Failed. 5 errors, 1 warnings. (took 3s.830ms)`

qiaowei361 commented 3 years ago

ADDR引脚接地 GND,换一种写法也是不行 image

qiaowei361 commented 3 years ago

后面我在main.c删除所有初始化代码,只使用 #include "sensor_rohm_bh1750.h" 就可以了,显示初始化成功,为何驱动查看却是没有...

期待作者

image