Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么获取到的三轴数据一直都是0?求助 #1

Open
cuboart opened this issue Jan 23, 2021 · 2 comments
Open

为什么获取到的三轴数据一直都是0?求助 #1

cuboart opened this issue Jan 23, 2021 · 2 comments

Comments

@cuboart
Copy link

cuboart commented Jan 23, 2021

[使用I2c1总线,mpu6050,bpm180,hmc5983l,除了hmc5983其他两个传感器都能读出数据。初始化,注册设备都没有问题。就是hmc5983读出的数据为0(无论是命令行读取还是代码读取),.在arduino中可以读出三轴数据,排除设备坏掉了。

@cuboart
Copy link
Author

cuboart commented Jan 23, 2021

@cuboart
Copy link
Author

cuboart commented Jan 23, 2021

初始化的代码:

//init hmc5983
static int rt_hw_hmc5983_port(void)
{
struct rt_sensor_config cfg;
cfg.intf.dev_name = "i2c1"; /* i2c bus */
cfg.intf.user_data = (void )HMC5883_ADDR; / i2c slave addr */
rt_hw_hmc5883_init("hmc",&cfg);
return RT_EOK;
}
INIT_ENV_EXPORT(rt_hw_hmc5983_port);

创建进程代码

int main{
//hmc5983
hmc5983_thread = rt_thread_create("hmc_pro",
read_hmc5983_entry,
I2C_BUS_NAME,
1024,
RT_THREAD_PRIORITY_MAX / 2,
20);
if (hmc5983_thread != RT_NULL)
{
rt_thread_startup(hmc5983_thread);
}
}
static void read_hmc5983_entry(void *parameter)
{
rt_device_t dev = RT_NULL;
struct rt_sensor_data sensor_data;
rt_size_t res;
dev = rt_device_find("mag_hmc");
if (dev == RT_NULL)
{
rt_kprintf("Can't find device:%s\n", "mag_hmc");
return;
}
if (rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
rt_kprintf("open device failed!\n");
return;
}
while (1)
{
res = rt_device_read(dev, 0, &sensor_data, 1);
if (res != 1)
{
rt_kprintf("read data failed!size is %d\n", res);
rt_device_close(dev);
return;
}
else
{
rt_kprintf("hmc5983l:%d,%d,%d,%5d\n",sensor_data.data.mag.x, sensor_data.data.mag.y, sensor_data.data.mag.z, sensor_data.timestamp);
}
rt_thread_mdelay(100);
}
}

@cuboart cuboart changed the title 为什么获取到的三轴数据一直都是0? 为什么获取到的三轴数据一直都是0?求助 Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant