I2C bus upgrade (#432)

This commit is contained in:
Zaltora 2017-09-01 06:29:32 -03:00 committed by Ruslan V. Uss
parent d100f42b1f
commit b83c2629b9
56 changed files with 909 additions and 804 deletions

View file

@ -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;