AnsweredAssumed Answered

STM32F3Discovery I2C EEPROM not working

Question asked by AlStorm Prime on Jun 16, 2015
Latest reply on Jul 22, 2015 by AlStorm Prime
Greetings. 
I am trying to use STM32F3Discovery(STM32F303VCT6) I2C interface to communicate with 24C04 EEPROM device. And as for now all my attempts failed I've decided to ask for help.

I initialize I2C1, then a write 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


01./* Includes ----------------------------------------------------------*/
02.#include "stm32f30x.h"
03.#include "stdint.h"
04. 
05./* Prototypes ---------------------------------------------------------*/
06.void Init_I2C1(void);
07.uint8_t WR_eePROM(void);
08. 
09.main()
10.{
11.   
12. Init_I2C1();
13.  
14. WR_eePROM();
15. 
16. 
17. while (1) {}
18.  
19. return 0;
20.}
21. 
22. 
23./* Initializing I2C1 --------------------------------------------------*/
24.void Init_I2C1(void)
25.{
26.  GPIO_InitTypeDef GPIO_InitStruct;
27.  I2C_InitTypeDef  I2C_InitStruct;
28.  
29.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); // +
30.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); // +
31. 
32. 
33.   
34.   /*  */
35.   
36.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_4); // +
37.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_4); // +
38.   
39.  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; // +
40.  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; // +
41.  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // +
42.  GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;  // +
43.  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
44.     
45.  GPIO_Init(GPIOB, &GPIO_InitStruct); // +
46.   
47.  
48.    /* I2C_InitStuct*/
49.  I2C_InitStruct.I2C_Timing = 0x10C08DCF; //0xC062121F;  0x10C091CF;
50.  I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable; // +
51.  I2C_InitStruct.I2C_DigitalFilter = 0x00; // +
52.  I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; // +
53.  I2C_InitStruct.I2C_OwnAddress1 = 0x00; // +
54.  I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; // +
55.  I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
56. 
57. 
58.  I2C_Init(I2C1, &I2C_InitStruct); // +
59.   
60. /* Enable the I2C peripheral */
61.  I2C_Cmd(I2C1, ENABLE); // +
62. 
63. 
64.}
65. 
66. 
67./*---------------------------BYTE WRITE-----------------------------------*/
68. 
69. 
70.uint8_t WR_eePROM(void)
71.{
72.  // Wait if Bus is busy
73.  while(I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET) {}
74.   
75./* Configure slave address, nbytes, reload and generate start */
76.   I2C_TransferHandling(I2C1, 0xA0, 2, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
77.   
78. 
79./* Wait until TXIS flag is set */ 
80.  while(I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET)  { } 
81. 
82.  return 0;
83.}
84. 
85. 
86./*---------------------------------------------------------------------*/
87. 
88. 
89.void assert_failed(uint8_t* file, uint32_t line){while (1){}}

Outcomes