bmp280 ds1307 hmc5883l update
This commit is contained in:
parent
60cbd9c710
commit
13efa882d2
10 changed files with 169 additions and 160 deletions
|
|
@ -10,9 +10,9 @@
|
|||
#include "bmp280/bmp280.h"
|
||||
|
||||
// In forced mode user initiate measurement each time.
|
||||
// In normal mode measurement is done continuously with specified standby time.
|
||||
// In normal mode measurement is done continuously with specified standby time.
|
||||
// #define MODE_FORCED
|
||||
|
||||
const uint8_t i2c_bus = 0;
|
||||
const uint8_t scl_pin = 0;
|
||||
const uint8_t sda_pin = 2;
|
||||
|
||||
|
|
@ -26,7 +26,8 @@ static void bmp280_task_forced(void *pvParameters)
|
|||
params.mode = BMP280_MODE_FORCED;
|
||||
|
||||
bmp280_t bmp280_dev;
|
||||
bmp280_dev.i2c_addr = BMP280_I2C_ADDRESS_0;
|
||||
bmp280_dev.i2c_dev.bus = i2c_bus;
|
||||
bmp280_dev.i2c_dev.addr = BMP280_I2C_ADDRESS_0;
|
||||
|
||||
while (1) {
|
||||
while (!bmp280_init(&bmp280_dev, ¶ms)) {
|
||||
|
|
@ -67,7 +68,8 @@ static void bmp280_task_normal(void *pvParameters)
|
|||
bmp280_init_default_params(¶ms);
|
||||
|
||||
bmp280_t bmp280_dev;
|
||||
bmp280_dev.i2c_addr = BMP280_I2C_ADDRESS_0;
|
||||
bmp280_dev.i2c_dev.bus = i2c_bus;
|
||||
bmp280_dev.i2c_dev.addr = BMP280_I2C_ADDRESS_0;
|
||||
|
||||
while (1) {
|
||||
while (!bmp280_init(&bmp280_dev, ¶ms)) {
|
||||
|
|
@ -103,7 +105,7 @@ void user_init(void)
|
|||
printf("SDK version : %s\n", sdk_system_get_sdk_version());
|
||||
printf("GIT version : %s\n", GITSHORTREV);
|
||||
|
||||
i2c_init(scl_pin, sda_pin);
|
||||
i2c_init(i2c_bus, scl_pin, sda_pin, I2C_FREQ_400K);
|
||||
|
||||
#ifdef MODE_FORCED
|
||||
xTaskCreate(bmp280_task_forced, "bmp280_task", 256, NULL, 2, NULL);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <ds1307/ds1307.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
|
|
@ -19,8 +20,12 @@ void user_init(void)
|
|||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
ds1307_start(true);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K);
|
||||
i2c_dev_t dev = {
|
||||
.addr = DS1307_ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
ds1307_start(&dev, true);
|
||||
|
||||
// setup datetime: 2016-10-09 13:50:10
|
||||
struct tm time = {
|
||||
|
|
@ -31,11 +36,11 @@ void user_init(void)
|
|||
.tm_min = 50,
|
||||
.tm_sec = 10
|
||||
};
|
||||
ds1307_set_time(&time);
|
||||
ds1307_set_time(&dev, &time);
|
||||
|
||||
while (true)
|
||||
{
|
||||
ds1307_get_time(&time);
|
||||
ds1307_get_time(&dev, &time);
|
||||
|
||||
printf("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon + 1,
|
||||
time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <i2c/i2c.h>
|
||||
#include <hmc5883l/hmc5883l.h>
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
|
|
@ -19,20 +20,24 @@ void user_init(void)
|
|||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n\n", sdk_system_get_sdk_version());
|
||||
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
i2c_dev_t dev = {
|
||||
.addr = HMC5883L_ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
|
||||
while (!hmc5883l_init())
|
||||
while (!hmc5883l_init(&dev))
|
||||
printf("Device not found\n");
|
||||
|
||||
hmc5883l_set_operating_mode(HMC5883L_MODE_CONTINUOUS);
|
||||
hmc5883l_set_samples_averaged(HMC5883L_SAMPLES_8);
|
||||
hmc5883l_set_data_rate(HMC5883L_DATA_RATE_07_50);
|
||||
hmc5883l_set_gain(HMC5883L_GAIN_1090);
|
||||
hmc5883l_set_operating_mode(&dev, HMC5883L_MODE_CONTINUOUS);
|
||||
hmc5883l_set_samples_averaged(&dev, HMC5883L_SAMPLES_8);
|
||||
hmc5883l_set_data_rate(&dev, HMC5883L_DATA_RATE_07_50);
|
||||
hmc5883l_set_gain(&dev, HMC5883L_GAIN_1090);
|
||||
|
||||
while (true)
|
||||
{
|
||||
hmc5883l_data_t data;
|
||||
hmc5883l_get_data(&data);
|
||||
hmc5883l_get_data(&dev, &data);
|
||||
printf("Magnetic data: X:%.2f mG, Y:%.2f mG, Z:%.2f mG\n", data.x, data.y, data.z);
|
||||
|
||||
for (uint32_t i = 0; i < 1000; i++)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue