Skip to content

Instantly share code, notes, and snippets.

@jgoney
Created December 8, 2023 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoney/2a554e1f80a943f9936f04a7061d03d2 to your computer and use it in GitHub Desktop.
Save jgoney/2a554e1f80a943f9936f04a7061d03d2 to your computer and use it in GitHub Desktop.
i2c_4 test
#include "daisy_seed.h"
using namespace daisy;
// I2C pins
constexpr Pin PIN_I2C1_SCL = seed::D11; // 12
constexpr Pin PIN_I2C1_SDA = seed::D12; // 13
constexpr Pin PIN_I2C4_SCL = seed::D13; // 14
constexpr Pin PIN_I2C4_SDA = seed::D14; // 15
static I2CHandle::Config i2c_config;
DaisySeed hardware;
I2CHandle i2c_handle;
I2CHandle::Result res;
I2CHandle::Result InitDriver()
{
i2c_config.periph = I2CHandle::Config::Peripheral::I2C_1; // works
// i2c_config.periph = I2CHandle::Config::Peripheral::I2C_4; // does not work
i2c_config.speed = I2CHandle::Config::Speed::I2C_100KHZ;
i2c_config.mode = I2CHandle::Config::Mode::I2C_MASTER;
i2c_config.pin_config.scl = PIN_I2C4_SCL;
i2c_config.pin_config.sda = PIN_I2C4_SDA;
return i2c_handle.Init(i2c_config);
}
I2CHandle::Result I2CSend(uint16_t val)
{
uint8_t cmd = 0b00000111; // Write to channel H
uint8_t lsb, msb;
msb = val >> 4;
lsb = val << 4;
uint16_t address = 0b1001000;
uint8_t data[3] = {cmd, msb, lsb};
uint16_t size = 3;
uint32_t timeout = 10000;
return i2c_handle.TransmitBlocking(address, data, size, timeout);
}
int main(void)
{
hardware.Init();
res = InitDriver();
bool blink = false;
uint16_t i = 0;
while(1)
{
res = I2CHandle::Result::ERR;
I2CSend(i);
i += 64;
hardware.SetLed(blink);
blink = !blink;
hardware.DelayMs(200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment