Skip to main content
hbuca.1
Visitor II
December 24, 2019
Question

problem about writing some datas to eeprom by I2C using stm32f429-disc1

  • December 24, 2019
  • 0 replies
  • 450 views

Hi,

I have a problem about I2C and I saw some topics about my problem on the internet but there was no solution, I hope you help me by sheding light on this.

Problem : After sending adress by I2C, the ADDR flag in SR1 register is not set but at the same time AF Flag(acknowledge failure) is setting up. I do not use std peripherial libraries and I use stm32f429I-Discovery kit and AT24C256. I2C communicates at 80 kHz

It stucks 

while (!(I2C1->SR1 & 0x0002));

line, I could not find a solution. Please help me.

the code is below:

/* Includes ------------------------------------------------------------------*/
 
 #include "main.h"
 
 
 
 
 
 
 
 
 
 int main(void)
 
 {
 
 
 
 int slave_adress = 0x50; // eeprom adress
 
 int word_adress = 0x01; // I want to write in this register adress in eeprom.
 
 int data = 0x30; // the data I want to write
 
 
 
 
 
 
 
 
 
 
 
 RCC->AHB1ENR |= 1<<1; //enable port B
 
 
 
 
 
 RCC->APB1ENR |= 1<<21; // enable i2c_1 
 
 
 
 
 
 
 
 
 
 
 
 GPIOB->MODER = 0x82000; // made PB6-I2C1_CLK ve PB9-I2C_SDA pins as alternate function
 
 
 
 GPIOB->AFR[0] = 0x4000000; // made pb6 as af4 (i2c1_scl)
 
 GPIOB->AFR[1] = 0x40; // made pb9 as af4 (i2c1_sda)
 
 
 
 
 
 
 
 GPIOB->OTYPER |= 0x00; //made PB6 and PB9 as open drain by adding resistor in real, here no need to make open drain on code 
 
 
 
 
 
 GPIOB->PUPDR = 0x00;
 
 
 
 
 
 
 
 I2C1->CR2 = 0x0010; 
 
 I2C1->CCR = 0x0064; // I2C communicates at 80 kHz
 
 I2C1->TRISE = 0x0011; 
 
 
 
 I2C1->CR1 = 0x0001; //enable I2C
 
 
 
 
 
I2C1->CR1 |= 1<<8; //I2C Start
 
 
 
 while (!(I2C1->SR1 & 0x0001));// //wait for start bit,
 
 
 
 
 
 
 
 
 
 I2C1->DR = slave_adress; // Write to I2C Address register
 
 while (!(I2C1->SR1 & 0x0002)); //wait adress is sent (ADDR bit)/////////////it stucks here///////////////////////////
 
 
 
 
 
 
 
 
 
 I2C1->DR = word_adress; // (EV8_1 – reference manual)
 
 
 
 while (!(I2C1->SR1 & (1<<7))); // Wait TxE bit set
 
 
 
		I2C1->DR = data;
 
 
 
		
 
		while(!(I2C1->SR1 & 0x0080)); // Wait TxE bit set
 
		while(!(I2C1->SR1 & 0x0004)); // wait BTF(byte transfer complete)
 
		
 
		I2C1->CR1 |= 1<<9; // stop

I put here logic analyzer picture when I start the code,

 0690X00000Buw5ZQAR.png

This topic has been closed for replies.