mavishak / cnss-embedded

1 stars 0 forks source link

Understanding I2C #22

Open mavishak opened 3 years ago

mavishak commented 3 years ago

We found that the reference manual was a little bit hard to understand there for searching for code that implemented I2C and compared them to each other and to the reference manual.

Here are the results: Untitled

comparing I2c.xlsx

References: char I2C_Read1Byte(char DeviceAddr, char addr) uint8_t ov7670_get(uint8_t reg) void I2C_start | void I2C_write | ...

_As the code above was writen using "stm32f4xx_i2c.h" and "stm32f4xx_I2c.c" from 'STM32F4xx Standard Peripherals Library'. We checked and found that the 'STM32F10x Standard Peripherals Library' contains the same functions under "stm32f10x_i2c.h" and "stm32f10xI2c.c".

Therefore it might be a good idea to implement the initial connection using the standard library.

Refrences: Serial communication - I2C - Excellent explanation and code examples STM32F10x Standard Peripherals Library - I2C

mavishak commented 3 years ago

Some other links

TemplarSpirit/BNO055-for-STM32 -_Look for uint8_t I2CReadByte(u8* pBuffer,u8 ReadAddr), similar to our code perhapse we could learn from it

STM32F103/Example_I2C_Master/main.c - This code uses 'Standerd Perophreial Library' to implement I2C for STM32F10x

Problem Our program gets stuck in 'while((I2C1->SR1 & 0x0002) != 0x0002);'

Possible causes:

_Note: we found out that we were probably polling on the wrong event. In 'I2C1Read1Byte' we changed

while((I2C1->SR1 & 0x0001) == 0x0001); // wait until SB = 0 to while((I2C1->SR1 & 0x0001) != 0x0001); // wait while SB != 1, start bit is not yet generated.