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.
It stucks while (!(I2C1->SR1 & 0x0002));
line, I could not find a solution. Please help me.
/* 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 |= 0x240; //made PB6 and PB9 as open drain
GPIOB->PUPDR = 0x00;
I2C1->CR2 = 0x0010; // made 16MHz clock hsi
I2C1->CCR = 0x0050; ////SM Mod, duty=0 pclk=16mhz
I2C1->TRISE = 0x0011; //1000 ns / 62.5 ns = 16 + 1
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)); ///////////////it stucks here///////////////////////////
I2C1->DR = word_adress; // (EV8_1 – reference manual)
while (!(I2C1->SR1 & (1<<7))); // Wait TxE bit set
}