STM32F3Discovery I2C EEPROM not working
Greetings.
I am trying to use STM32F3Discovery(STM32F303VCT6)I2C interface to communicate with24C04 EEPROM device. And as for now all my attempts failed I've decided to ask for help. I initialize I2C1, then awrite function calls for I2C_TransferHandling(I2C1, 0xA0, 2, I2C_SoftEnd_Mode, I2C_Generate_Start_Write); where 0xA0 is a EEPROM devise address and 2 is NBYTES number. After this program stuck in a while loop waiting for TXIS flag. By monitoring I2C_CR2 and I2C_ISR registers I've found that all my attamps ends up in two ways: First - I2C_CR2.Start bit hangs set(1) while I2C_ISR.Busy bit is set(1) - SDA and SCL lines are released Second- I2C_CR2.Start is reseted (0) while I2C_ISR.ARLO bit gets set (1)- SDA and SCL lines are released STM32F30x_DSP_StdPeriph_Lib V1.2.2 is used I will be very grateful for any help. Also please let me know If I forgot to specify anything. Here you can find my main.c/* Includes ----------------------------------------------------------*/ #include ''stm32f30x.h'' #include ''stdint.h'' /* Prototypes ---------------------------------------------------------*/ void
Init_I2C1(
void);
uint8_t WR_eePROM( void);
main() {Init_I2C1();
WR_eePROM();
while
(1) {}
return
0;
} /* Initializing I2C1 --------------------------------------------------*/ voidInit_I2C1(
void)
{GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
// +
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
// +
/* */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_4);
// +
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_4);
// +
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
// +
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
// +
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
// +
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
// +
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStruct);
// +
/* I2C_InitStuct*/
I2C_InitStruct.I2C_Timing = 0x10C08DCF;
//0xC062121F; 0x10C091CF;
I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
// +
I2C_InitStruct.I2C_DigitalFilter = 0x00;
// +
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
// +
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
// +
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
// +
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Init(I2C1, &I2C_InitStruct);
// +
/* Enable the I2C peripheral */
I2C_Cmd(I2C1, ENABLE);
// +} /*---------------------------BYTE WRITE-----------------------------------*/ uint8_t WR_eePROM( void
)
{// Wait if Bus is busy
while
(I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET) {}
/* Configure slave address, nbytes, reload and generate start */I2C_TransferHandling(I2C1, 0xA0, 2, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
/* Wait until TXIS flag is set */while
(I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET) { }
return
0;
} /*---------------------------------------------------------------------*/ voidassert_failed(uint8_t* file, uint32_t line){
while(1){}}
#stm32-i2c