2024-06-08 11:45 PM
Hi,
I'm emulating M24C02 protocol with STM32F030 & STM32G030. To read M24C02, address is written following by repeated start then data read. Here is my code:
----main.c ----
uint8_t i2c_bytes[256] ={0x55, 0xaa, 0xff, 0x00}; //Virtual M24C02 Content
LL_I2C_EnableOwnAddress1(I2C1);
LL_I2C_EnableIT_TX(I2C1);
LL_I2C_EnableIT_RX(I2C1);
LL_I2C_EnableIT_ADDR(I2C1);
NVIC_EnableIRQ(I2C1_IRQn);
//enable i2c
LL_I2C_Enable(I2C1);
---stm32g0xx_it.c---
extern uint8_t i2c_bytes[256];
void I2C1_IRQHandler(void){
static volatile uint8_t i2c_bytes_addr = 0;
__disable_irq();
if(I2C1->ISR & I2C_ISR_TXIS){
I2C1->TXDR = i2c_bytes[i2c_bytes_addr];//Send Data
} else
if(I2C1->ISR & I2C_ISR_RXNE){
i2c_bytes_addr = I2C1->RXDR;//Store Address
} else
if(I2C1->ISR & I2C_ISR_ADDR){
I2C1->ICR |= I2C_ICR_ADDRCF_Msk;
}
}
__enable_irq();
}
The result is not as expected. Dump the virtual device with raspberry pi, Instead of '55 aa ff 00', bit 00 is ‘00’:
$ i2cdump -y 1 0x1b
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 00 55 aa ff 00 00 00 00 00 00 00 00 00 00 00 00 .U?............. //should be 55 aa ff 00
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Thanks.
2024-07-23 04:44 AM
Hello @Lu Entong,
This could be due to several reasons, such as incorrect handling of the I2C address or timing issues. Here are some steps that can help you:
- Check that the system clock is correctly configured.
- Configure I2C peripherals and GPIO pins correctly.
Could you also provide me with the exact part number of the M24C02 you're using so that I can assist you better?
Thanks for your contribution.
Dor_RH