|
Edited by dmx512 at 2018-10-19 07:25
I have the UART (other then the debug uart) and SPI working on bare metal.
However, I have an challenge with the TWI. Whatever I write to the TWI0 register, but it reads always 0 back.
The TWI_STAT register should read 0xF8.
I have set the proper GATING4 and RESET4 bit.
Any idea what I could be missing ?
Many thanks in advance, Arjan
- void h3_i2c_begin(void) {
- h3_gpio_fsel(EXT_I2C_SCL, ALT_FUNCTION_SCK);
- h3_gpio_fsel(EXT_I2C_SDA, ALT_FUNCTION_SDA);
- #if (EXT_I2C_NUMBER == 0)
- H3_CCU->BUS_SOFT_RESET4 |= RESET_TWI0;
- H3_CCU->BUS_CLK_GATING4 |= GATE_TWI0;
- #elif (EXT_I2C_NUMBER == 1)
- H3_CCU->BUS_SOFT_RESET4 |= RESET_TWI1;
- H3_CCU->BUS_CLK_GATING4 |= GATE_TWI1;
- #else
- #error Unsupported I2C device configured
- #endif
- _soft_reset();
- #ifndef NDEBUG
- printf("H3_PIO_PORTA->CFG1=%p\n", H3_PIO_PORTA->CFG1);
- print_bits(H3_PIO_PORTA->CFG1);
- printf("H3_CCU->BUS_CLK_GATING4=%p\n", H3_CCU->BUS_CLK_GATING4);
- printf("H3_CCU->BUS_SOFT_RESET4=%p\n", H3_CCU->BUS_SOFT_RESET4);
- printf("EXT_I2C=%p\n", EXT_I2C);
- printf("EXT_I2C_SCL=%d\n", EXT_I2C_SCL);
- printf("EXT_I2C_SDA=%d\n", EXT_I2C_SDA);
- printf("EXT_I2C->STAT=%p [%p]\n", EXT_I2C->STAT, &EXT_I2C->STAT);
- printf("EXT_I2C->SRST=%p [%p]\n", EXT_I2C->SRST, &EXT_I2C->SRST);
- printf("EXT_I2C->LCR=%p [%p]\n", EXT_I2C->LCR, &EXT_I2C->LCR);
- #endif
- }
- static inline void _soft_reset(void) {
- uint32_t value = EXT_I2C->SRST;
- value |= TWI_SRST_SRST;
- EXT_I2C->SRST = value;
- uint16_t timeout = 0xFFFF;
- while (((EXT_I2C->SRST & TWI_SRST_SRST) == TWI_SRST_SRST) && (timeout-- > 0))
- ;
- #ifndef NDEBUG
- printf("_soft_reset - timeout=%d\n", timeout);
- #endif
- }
Copy code
- --> src/h3_i2c.c:h3_i2c_begin:742
- h3_gpio_fsel gpio=11, port=0[A], number=11, reg=1, shift=12, pio=0x01c20800
- h3_gpio_fsel gpio=12, port=0[A], number=12, reg=1, shift=16, pio=0x01c20800
- _soft_reset - timeout=65535
- H3_PIO_PORTA->CFG1=0x77722777
- 0 1 2 4 5 6 8 9 10 13 17 20 21 22 24 25 26 28 29 30
- H3_CCU->BUS_CLK_GATING4=0x00000001
- H3_CCU->BUS_SOFT_RESET4=0x00010001
- EXT_I2C=0x01c2ac00
- EXT_I2C_SCL=11
- EXT_I2C_SDA=12
- EXT_I2C->STAT=0x00000000 [0x01c2ac10]
- EXT_I2C->SRST=0x00000000 [0x01c2ac18]
- EXT_I2C->LCR=0x00000000 [0x01c2ac20]
- <-- src/h3_i2c.c:h3_i2c_begin:772
Copy code |
|