cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Protocol of STM32F030R8T6

ADani
Associate III

I am trying to interface 24LC256 EEPROM to my STM32F030R8T6 discovery board using I2C protocol. I am analyzing SCL and SDA pins using DSO. I can achieve a start operation and place device id on the line. I need to transfer two 8bit data successively. 0x01 - High Byte and 0x11 Low Byte. But I could only place 0x01 on the SDA line when I place 0x11 it is not being transmitted and the stop bit is reached. Please help me to resolve this issue. 

#include <stdio.h>

#include <stdint.h>

#include <stm32f0xx.h>

void I2C_setup(void) /*I2C Setup*/

{

RCC->AHBENR|=RCC_AHBENR_GPIOBEN; /*GPIO B Clock Enable*/

GPIOB->MODER&=~GPIO_MODER_MODER6_0; 

GPIOB->MODER|=GPIO_MODER_MODER6_1;

GPIOB->MODER&=~GPIO_MODER_MODER7_0;

GPIOB->MODER|=GPIO_MODER_MODER7_1;

GPIOB->OTYPER|=GPIO_OTYPER_OT_6;

GPIOB->OTYPER|=GPIO_OTYPER_OT_7;

GPIOB->OSPEEDR|=GPIO_OSPEEDER_OSPEEDR6_0;

GPIOB->OSPEEDR|=GPIO_OSPEEDER_OSPEEDR7_0;

GPIOB->PUPDR&=~GPIO_PUPDR_PUPDR6;

GPIOB->PUPDR&=~GPIO_PUPDR_PUPDR7; 

 GPIOB->AFR[0]=(0x1<<24)|(0x1<<28); /*Set to alternate function along with no pullup and high speed*/

RCC->APB1ENR|=RCC_APB1ENR_I2C1EN;  /*I2C Enable*/

I2C1->TIMINGR= (uint32_t) 0X00901850;

I2C1->CR1|=I2C_CR1_PE; /*Peripheral Enable*/

}

int main(void)

{

I2C_setup(); /*Initialization*/

I2C1->CR2=0x50<<1; /*Device Address of 1010000*/

  I2C1->CR2&=~I2C_CR2_RD_WRN; /*Write Enable*/

I2C1->CR2|= 1<<16; /*1 Byte Transmission*/

I2C1->CR2|=I2C_CR2_START; /*Start data transfer*/

I2C1->TXDR = 0x01; /* High Byte EEPROM memory address*/

while(!((I2C1->ISR & I2C_ISR_TXE) == I2C_ISR_TXE)){};

I2C1->TXDR = 0x11; /* Low Byte EEPROM memory address */

while(!((I2C1->ISR & I2C_ISR_TXE) == I2C_ISR_TXE)){};

I2C1->TXDR = 0x11; /* Value to be placed in memory address */

while(!((I2C1->ISR & I2C_ISR_TXE) == I2C_ISR_TXE)){};

I2C1->CR2|=I2C_CR2_STOP; /*Stop data transfer*/

while(I2C1->CR2&I2C_CR2_STOP);

while(1)

{

}

return 0;

}

0 REPLIES 0