Need help with I2C register access in bootloader
Posted: Tue Sep 25, 2018 6:26 am
Hello,
I have a requirement to use I2C in bootloader in master mode. As I2C driver is not added as component into bootloader, using I2C with low level registers is the only way to do it.
I have tried to configure I2C registers from TRM as below, but not getting success.
Can anyone point me out what am I missing in it.?
Can anyone help what am I missing in it.? Or if there is any other way to use i2c_driver.c directly in bootloader.
Thanks.
I have a requirement to use I2C in bootloader in master mode. As I2C driver is not added as component into bootloader, using I2C with low level registers is the only way to do it.
I have tried to configure I2C registers from TRM as below, but not getting success.
Can anyone point me out what am I missing in it.?
Code: Select all
gpio_matrix_out(15, I2CEXT0_SDA_OUT_IDX, 0, 0); //set output signal for io_matrix
gpio_matrix_in (15, I2CEXT0_SDA_IN_IDX, 0); //set input signal for io_matrix
gpio_matrix_out(2, I2CEXT0_SCL_OUT_IDX, 0, 0); //set output signal for io_matrix
gpio_matrix_in (2, I2CEXT0_SCL_IN_IDX, 0); //set input signal for io_matrix
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2C_EXT0_CLK_EN); /* enable clock */
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2C_EXT0_RST);
WRITE_PERI_REG(I2C_CTR_REG(0),0xff);
WRITE_PERI_REG(I2C_FIFO_CONF_REG(0),I2C_NONFIFO_EN);
WRITE_PERI_REG(I2C_SDA_HOLD_REG(0),10);
WRITE_PERI_REG(I2C_SCL_LOW_PERIOD_REG(0),14);
WRITE_PERI_REG(I2C_SCL_HIGH_PERIOD_REG(0),14);
WRITE_PERI_REG(I2C_SDA_SAMPLE_REG(0),10);
/* command and data write */
WRITE_PERI_REG(I2C_COMD0_REG(0), 0x00); /* start */
WRITE_PERI_REG(I2C_COMD1_REG(0), 0x803); /* write */
WRITE_PERI_REG(I2C_DATA_APB_REG(0), 0x20 << 1 | 0); /* slave address with write */
WRITE_PERI_REG(I2C_DATA_APB_REG(0), 0x07); /* data */
WRITE_PERI_REG(I2C_DATA_APB_REG(0), 0x00); /* data */
WRITE_PERI_REG(I2C_COMD2_REG(0), 0x1800); /* stop */
Thanks.