The examples you've provided use SPI, but don't include i2c. I've managed to get my head around the basics of initialising and using i2c, but I'm still a bit stuck as there isn't much in the way of comprehensive documentation. I've connected an oscilloscope and, in a few cases, I've noticed some fluctuations on the CLK and SDA lines during the boot-up process.
the code:
void i2c_write_data(uint8_t addr, uint8_t data)
{
//I2C_SetFunc(I2cStart_En);
stc_i2c_addr_t slaveAddr = {addr << 1, 1};
I2C_WriteSlaveAddr(&slaveAddr);
I2C_WriteByte(data);
//I2C_ClearFunc(I2cStart_En);
}
en_result_t Gpio_InitIOExtForI2C() {
CLK_EnablePeripheralClk(ClkPeripheralI2c);
//CLK_EnablePeripheralClk(ClkPeripheralGpio);
Gpio_SetFunc_I2C_SCL_P14();
Gpio_SetFunc_I2C_DAT_P15();
return Ok;
}
int main(void) {
Clk_Init(ClkFreq24Mhz, ClkDiv1, ClkDiv1);
Gpio_InitIOExt(0, 1, GpioDirOut, FALSE, FALSE, FALSE, TRUE);
Gpio_InitIOExtForI2C();
//I2C_SetFunc(I2cBaud_En);
//I2C_SetFunc(I2cHlm_En);
stc_i2c_config_t i2c_config;
i2c_config.u8Tm = 32; // << how to figure out?
i2c_config.pfnI2cCb = NULL;
i2c_config.bTouchNvic = FALSE;
i2c_config.enFunc = I2cMode_En;
i2c_config.stcSlaveAddr = (stc_i2c_addr_t){0x1A,1}; // << in case {0x1A,0} SDA / SCL doesn't change on boot
if (I2C_Init(&i2c_config) != Ok) {
SET_RGB(RGB(255,255,0));
delay1ms(1000);
}
// I2C_SetFunc(I2cStart_En); << change nothing
while (1)
{
i2c_write_data(0x1A,0x1A);
SET_RGB(RGB(32,160,255));
delay1ms(10);
SET_RGB(0);
delay1ms(990);
}
}
I found a reference manual for this chip which describes in detail how to work with I2c.
Need to delve into it to understand how to configure it.
http://holosense.cn/uploads/position/1693185730491519.pdf
The examples you've provided use SPI, but don't include i2c. I've managed to get my head around the basics of initialising and using i2c, but I'm still a bit stuck as there isn't much in the way of comprehensive documentation. I've connected an oscilloscope and, in a few cases, I've noticed some fluctuations on the CLK and SDA lines during the boot-up process.
the code:
I found a reference manual for this chip which describes in detail how to work with I2c.
Need to delve into it to understand how to configure it.
http://holosense.cn/uploads/position/1693185730491519.pdf