I2C bus upgrade (#432)
This commit is contained in:
parent
d100f42b1f
commit
b83c2629b9
56 changed files with 909 additions and 804 deletions
|
|
@ -8,7 +8,6 @@
|
|||
#include <esp/uart.h>
|
||||
#include <espressif/esp_common.h>
|
||||
#include <stdio.h>
|
||||
#include <i2c/i2c.h>
|
||||
#include <ad770x/ad770x.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
// Connect ADDR pin to GND
|
||||
#define ADDR ADS111X_ADDR_GND
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
|
|
@ -28,23 +29,27 @@ 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);
|
||||
i2c_dev_t dev = {
|
||||
.addr = ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
|
||||
ads111x_set_mode(ADDR, ADS111X_MODE_CONTUNOUS);
|
||||
ads111x_set_data_rate(ADDR, ADS111X_DATA_RATE_32);
|
||||
ads111x_set_mode(&dev, ADS111X_MODE_CONTUNOUS);
|
||||
ads111x_set_data_rate(&dev, ADS111X_DATA_RATE_32);
|
||||
|
||||
ads111x_set_input_mux(ADDR, ADS111X_MUX_0_GND);
|
||||
ads111x_set_gain(ADDR, GAIN);
|
||||
ads111x_set_input_mux(&dev, ADS111X_MUX_0_GND);
|
||||
ads111x_set_gain(&dev, GAIN);
|
||||
|
||||
float gain_val = ads111x_gain_values[GAIN];
|
||||
|
||||
while (true)
|
||||
{
|
||||
// wait for conversion end
|
||||
while (ads111x_busy(ADDR)) {}
|
||||
while (ads111x_busy(&dev)) {}
|
||||
|
||||
// Read result
|
||||
int16_t raw = ads111x_get_value(ADDR);
|
||||
int16_t raw = ads111x_get_value(&dev);
|
||||
|
||||
float voltage = gain_val / ADS111X_MAX_VALUE * raw;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,17 +11,20 @@
|
|||
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
#define I2C_BUS 0
|
||||
|
||||
static void measure(void *pvParameters)
|
||||
{
|
||||
bh1750_configure(BH1750_ADDR_LO,
|
||||
BH1750_CONTINUOUS_MODE | BH1750_HIGH_RES_MODE);
|
||||
i2c_dev_t dev = {
|
||||
.addr = BH1750_ADDR_LO,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
bh1750_configure(&dev, BH1750_CONTINUOUS_MODE | BH1750_HIGH_RES_MODE);
|
||||
|
||||
while (1) {
|
||||
while(1) {
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
|
||||
printf("Lux: %d\n", bh1750_read(BH1750_ADDR_LO));
|
||||
printf("Lux: %d\n", bh1750_read(&dev));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +38,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_100K);
|
||||
|
||||
xTaskCreate(measure, "measure_task", 256, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,18 +13,25 @@
|
|||
// BMP180 driver
|
||||
#include "bmp180/bmp180.h"
|
||||
|
||||
#define MY_EVT_TIMER 0x01
|
||||
#define MY_EVT_BMP180 0x02
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN GPIO_ID_PIN((0))
|
||||
#define SDA_PIN GPIO_ID_PIN((2))
|
||||
|
||||
#define MY_EVT_TIMER 0x01
|
||||
#define MY_EVT_BMP180 0x02
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t event_type;
|
||||
bmp180_result_t bmp180_data;
|
||||
} my_event_t;
|
||||
|
||||
//device descriptor
|
||||
i2c_dev_t dev = {
|
||||
.addr = BMP180_DEVICE_ADDRESS,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
|
||||
// Communication Queue
|
||||
static QueueHandle_t mainqueue;
|
||||
static TimerHandle_t timerHandle;
|
||||
|
|
@ -70,7 +77,7 @@ void bmp180_task(void *pvParameters)
|
|||
case MY_EVT_TIMER:
|
||||
printf("%s: Received Timer Event\n", __FUNCTION__);
|
||||
|
||||
bmp180_trigger_measurement(com_queue);
|
||||
bmp180_trigger_measurement(&dev, com_queue);
|
||||
break;
|
||||
case MY_EVT_BMP180:
|
||||
printf("%s: Received BMP180 Event temp:=%d.%dC press=%d.%02dhPa\n", __FUNCTION__, \
|
||||
|
|
@ -91,6 +98,9 @@ void user_setup(void)
|
|||
|
||||
// Give the UART some time to settle
|
||||
sdk_os_delay_us(500);
|
||||
|
||||
// Init I2C bus Interface
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
|
|
@ -107,7 +117,7 @@ void user_init(void)
|
|||
bmp180_informUser = bmp180_i2c_informUser;
|
||||
|
||||
// Init BMP180 Interface
|
||||
bmp180_init(SCL_PIN, SDA_PIN);
|
||||
bmp180_init(&dev);
|
||||
|
||||
// Create Main Communication Queue
|
||||
mainqueue = xQueueCreate(10, sizeof(my_event_t));
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Test code for DS3231 high precision RTC module
|
||||
/* Test code for DS3231 high precision RTC module
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2016 Bhuvanchandra DV <bhuvanchandra.dv@gmail.com>
|
||||
|
|
@ -12,15 +12,21 @@
|
|||
|
||||
#include "ds3231/ds3231.h"
|
||||
|
||||
#define ADDR DS3231_ADDR
|
||||
#define I2C_BUS 0
|
||||
|
||||
void task1(void *pvParameters)
|
||||
{
|
||||
struct tm time;
|
||||
float tempFloat;
|
||||
|
||||
i2c_dev_t dev = {
|
||||
.addr = ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
while(1) {
|
||||
vTaskDelay(100);
|
||||
ds3231_getTime(&time);
|
||||
ds3231_getTempFloat(&tempFloat);
|
||||
ds3231_getTime(&dev, &time);
|
||||
ds3231_getTempFloat(&dev, &tempFloat);
|
||||
printf("TIME:%d:%d:%d, TEMPERATURE:%.2f DegC\r\n", time.tm_hour, time.tm_min, time.tm_sec, tempFloat);
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +41,7 @@ void user_init(void)
|
|||
printf("SDK version : %s\n", sdk_system_get_sdk_version());
|
||||
printf("GIT version : %s\n", GITSHORTREV);
|
||||
|
||||
ds3231_Init(scl, sda);
|
||||
i2c_init(0,scl,sda,I2C_FREQ_400K);
|
||||
|
||||
xTaskCreate(task1, "tsk1", 256, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#define CS_GPIO_PIN 2
|
||||
|
||||
// ds1307
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
|
|
@ -29,7 +30,11 @@
|
|||
uint32_t get_fattime()
|
||||
{
|
||||
struct tm time;
|
||||
ds1307_get_time(&time);
|
||||
i2c_dev_t dev = {
|
||||
.addr = DS1307_ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
ds1307_get_time(&dev, &time);
|
||||
|
||||
return ((uint32_t)(time.tm_year - 1980) << 25)
|
||||
| ((uint32_t)time.tm_mon << 21)
|
||||
|
|
@ -127,7 +132,7 @@ 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_400K);
|
||||
|
||||
xTaskCreate(rewrite_file_task, "task1", 512, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <hd44780/hd44780.h>
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
#define ADDR 0x27
|
||||
|
|
@ -27,10 +28,11 @@ 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);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
|
||||
hd44780_t lcd = {
|
||||
.addr = ADDR,
|
||||
.i2c_dev.bus = I2C_BUS,
|
||||
.i2c_dev.addr = ADDR,
|
||||
.font = HD44780_FONT_5X8,
|
||||
.lines = 2,
|
||||
.pins = {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <stdbool.h>
|
||||
#include "ina3221/ina3221.h"
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define PIN_SCL 5
|
||||
#define PIN_SDA 2
|
||||
#define ADDR INA3221_ADDR_0
|
||||
|
|
@ -33,7 +34,8 @@ void ina_measure(void *pvParameters)
|
|||
|
||||
// Create ina3221 device
|
||||
ina3221_t dev = {
|
||||
.addr = ADDR,
|
||||
.i2c_dev.bus = I2C_BUS,
|
||||
.i2c_dev.addr = ADDR,
|
||||
.shunt = { 100 ,100 ,100 }, // shunt values are 100 mOhm for each channel
|
||||
.mask.mask_register = INA3221_DEFAULT_MASK, // Init
|
||||
.config.config_register = INA3221_DEFAULT_CONFIG, // Init
|
||||
|
|
@ -120,7 +122,7 @@ void user_init(void)
|
|||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
i2c_init(PIN_SCL,PIN_SDA);
|
||||
i2c_init(I2C_BUS, PIN_SCL, PIN_SDA, I2C_FREQ_400K);
|
||||
|
||||
xTaskCreate(ina_measure, "Measurements_task", 512, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,15 @@
|
|||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
#define ADDR MCP4725A0_ADDR0
|
||||
#define VDD 3.3
|
||||
|
||||
inline static void wait_for_eeprom()
|
||||
inline static void wait_for_eeprom(i2c_dev_t* dev)
|
||||
{
|
||||
while (mcp4725_eeprom_busy(ADDR))
|
||||
while (mcp4725_eeprom_busy(dev))
|
||||
{
|
||||
printf("...DAC is busy, waiting...\n");
|
||||
vTaskDelay(1);
|
||||
|
|
@ -33,21 +34,25 @@ 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);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
i2c_dev_t dev = {
|
||||
.addr = ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
|
||||
// setup EEPROM values
|
||||
if (mcp4725_get_power_mode(ADDR, true) != MCP4725_PM_NORMAL)
|
||||
if (mcp4725_get_power_mode(&dev, true) != MCP4725_PM_NORMAL)
|
||||
{
|
||||
printf("DAC was sleeping... Wake up Neo!\n");
|
||||
mcp4725_set_power_mode(ADDR, MCP4725_PM_NORMAL, true);
|
||||
wait_for_eeprom();
|
||||
mcp4725_set_power_mode(&dev, MCP4725_PM_NORMAL, true);
|
||||
wait_for_eeprom(&dev);
|
||||
}
|
||||
|
||||
printf("Set default DAC ouptut value to MAX...\n");
|
||||
mcp4725_set_raw_output(ADDR, MCP4725_MAX_VALUE, true);
|
||||
wait_for_eeprom();
|
||||
mcp4725_set_raw_output(&dev, MCP4725_MAX_VALUE, true);
|
||||
wait_for_eeprom(&dev);
|
||||
|
||||
printf("And now default DAC output value is 0x%03x\n", mcp4725_get_raw_output(ADDR, true));
|
||||
printf("And now default DAC output value is 0x%03x\n", mcp4725_get_raw_output(&dev, true));
|
||||
|
||||
printf("Now let's generate the sawtooth wave in slow manner\n");
|
||||
|
||||
|
|
@ -58,7 +63,7 @@ void user_init(void)
|
|||
if (vout > VDD) vout = 0;
|
||||
|
||||
printf("Vout: %.02f\n", vout);
|
||||
mcp4725_set_voltage(ADDR, VDD, vout, false);
|
||||
mcp4725_set_voltage(&dev, VDD, vout, false);
|
||||
|
||||
// It will be very low freq wave
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
|
|
|
|||
|
|
@ -13,18 +13,20 @@
|
|||
#include <i2c/i2c.h>
|
||||
#include <ms561101ba03/ms561101ba03.h>
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n\n", sdk_system_get_sdk_version());
|
||||
|
||||
ms561101ba03_t device = {
|
||||
.addr = MS561101BA03_ADDR_CSB_LOW,
|
||||
.i2c_dev.bus = I2C_BUS,
|
||||
.i2c_dev.addr = MS561101BA03_ADDR_CSB_LOW,
|
||||
.osr = MS561101BA03_OSR_4096,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@
|
|||
#include <pca9685/pca9685.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ADDR 0x40
|
||||
#define ADDR PCA9685_ADDR_BASE
|
||||
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
|
|
@ -23,19 +24,23 @@ 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);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
i2c_dev_t dev = {
|
||||
.addr = ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
|
||||
pca9685_init(ADDR);
|
||||
pca9685_init(&dev);
|
||||
|
||||
pca9685_set_pwm_frequency(ADDR, 1000);
|
||||
printf("Freq 1000Hz, real %d\n", pca9685_get_pwm_frequency(ADDR));
|
||||
pca9685_set_pwm_frequency(&dev, 1000);
|
||||
printf("Freq 1000Hz, real %d\n", pca9685_get_pwm_frequency(&dev));
|
||||
|
||||
uint16_t val = 0;
|
||||
while (true)
|
||||
{
|
||||
printf("Set ch0 to %d, ch4 to %d\n", val, 4096 - val);
|
||||
pca9685_set_pwm_value(ADDR, 0, val);
|
||||
pca9685_set_pwm_value(ADDR, 4, 4096 - val);
|
||||
pca9685_set_pwm_value(&dev, 0, val);
|
||||
pca9685_set_pwm_value(&dev, 4, 4096 - val);
|
||||
|
||||
if (val++ == 4096)
|
||||
val = 0;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,21 @@
|
|||
#include "i2c/i2c.h"
|
||||
#include "pcf8591/pcf8591.h"
|
||||
|
||||
#define ADDR PCF8591_DEFAULT_ADDRESS
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
static void measure(void *pvParameters)
|
||||
{
|
||||
i2c_dev_t dev = {
|
||||
.addr = ADDR,
|
||||
.bus = I2C_BUS,
|
||||
};
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
printf("Value: %d\n", pcf8591_read(PCF8591_DEFAULT_ADDRESS, 0x03));
|
||||
printf("Value: %d\n", pcf8591_read(&dev, 0x03));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +36,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_100K);
|
||||
|
||||
xTaskCreate(measure, "measure_task", 256, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#ifdef I2C_CONNECTION
|
||||
#define PROTOCOL SSD1306_PROTO_I2C
|
||||
#define ADDR SSD1306_I2C_ADDR_0
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
#else
|
||||
|
|
@ -35,7 +36,8 @@
|
|||
static const ssd1306_t dev = {
|
||||
.protocol = PROTOCOL,
|
||||
#ifdef I2C_CONNECTION
|
||||
.addr = ADDR,
|
||||
.i2c_dev.bus = I2C_BUS,
|
||||
.i2c_dev.addr = ADDR,
|
||||
#else
|
||||
.cs_pin = CS_PIN,
|
||||
.dc_pin = DC_PIN,
|
||||
|
|
@ -97,7 +99,7 @@ void user_init(void)
|
|||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
#ifdef I2C_CONNECTION
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K);
|
||||
#endif
|
||||
|
||||
while (ssd1306_init(&dev) != 0)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#ifdef I2C_CONNECTION
|
||||
#define PROTOCOL SSD1306_PROTO_I2C
|
||||
#define ADDR SSD1306_I2C_ADDR_0
|
||||
#define I2C_BUS 0
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
#else
|
||||
|
|
@ -43,7 +44,8 @@
|
|||
static const ssd1306_t dev = {
|
||||
.protocol = PROTOCOL,
|
||||
#ifdef I2C_CONNECTION
|
||||
.addr = ADDR,
|
||||
.i2c_dev.bus = I2C_BUS,
|
||||
.i2c_dev.addr = ADDR,
|
||||
#else
|
||||
.cs_pin = CS_PIN,
|
||||
.dc_pin = DC_PIN,
|
||||
|
|
@ -162,7 +164,7 @@ void user_init(void)
|
|||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
#ifdef I2C_CONNECTION
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K);
|
||||
#endif
|
||||
|
||||
while (ssd1306_init(&dev) != 0) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
* Connect 3.3v from the ESP to Vin and GND to GND
|
||||
*/
|
||||
|
||||
#define I2C_BUS (0)
|
||||
#define SCL_PIN (2)
|
||||
#define SDA_PIN (0)
|
||||
|
||||
|
|
@ -27,7 +28,8 @@ void tsl2561MeasurementTask(void *pvParameters)
|
|||
// TSL2561_I2C_ADDR_VCC (0x49)
|
||||
// TSL2561_I2C_ADDR_GND (0x29)
|
||||
// TSL2561_I2C_ADDR_FLOAT (0x39) Default
|
||||
lightSensor.i2c_addr = TSL2561_I2C_ADDR_FLOAT;
|
||||
lightSensor.i2c_dev.bus = I2C_BUS;
|
||||
lightSensor.i2c_dev.addr = TSL2561_I2C_ADDR_FLOAT;
|
||||
|
||||
tsl2561_init(&lightSensor);
|
||||
|
||||
|
|
@ -63,7 +65,7 @@ void tsl2561MeasurementTask(void *pvParameters)
|
|||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
|
||||
xTaskCreate(tsl2561MeasurementTask, "tsl2561MeasurementTask", 256, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,15 @@
|
|||
* Connect 3.3v from the ESP to Vin and GND to GND
|
||||
*/
|
||||
|
||||
#define I2C_BUS (0)
|
||||
#define SCL_PIN (2)
|
||||
#define SDA_PIN (0)
|
||||
|
||||
void tsl4531MeasurementTask(void *pvParameters)
|
||||
{
|
||||
tsl4531_t lightSensor;
|
||||
lightSensor.i2c_addr = TSL4531_I2C_ADDR;
|
||||
lightSensor.i2c_dev.bus= I2C_BUS;
|
||||
lightSensor.i2c_dev.addr= TSL4531_I2C_ADDR;
|
||||
tsl4531_init(&lightSensor);
|
||||
|
||||
tsl4531_set_integration_time(&lightSensor, TSL4531_INTEGRATION_400MS);
|
||||
|
|
@ -49,7 +51,7 @@ void tsl4531MeasurementTask(void *pvParameters)
|
|||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
||||
|
||||
xTaskCreate(tsl4531MeasurementTask, "tsl4531MeasurementTask", 256, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue