AnsweredAssumed Answered

Stm32F0 I2C comunication trouble

Question asked by podlisker.stan on Oct 29, 2015
What is wrong here?
I try to read 2 bytes data of temperature sensor LM73 by I2C of STM32F0Discovery based on STM32F051 micro. The micro is waiting RXNE event and doesn't exit from the loop.
I don't see any activity on SDA and SCL lines The signals have the pullup resistors.
Here is a code bellow:

void init_I2C1(void) {
  
I2C_InitTypeDef I2C1_InitStructure;       // I2C1 Configuration structure


 /** I2C1 GPIO Configuration  
  PB6   ------> I2C1_SCL
  PB7   ------> I2C1_SDA
  */
  /*Enable or disable the AHB peripheral clock */
  RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  
/* IC1 Configuration */
 // I2C_Cmd(I2C1,DISABLE);
  
  /*Configure GPIO pin : PB */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
  GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;  
  GPIO_Init(GPIOB, &GPIO_InitStruct);
  
  I2C1_InitStructure.I2C_Mode  = I2C_Mode_I2C;
  /*Timing register value is computed with the AN4235 xls file,
   fast Mode @400kHz with I2CCLK = 48MHz, rise time = 140ns, fall time = 40ns */
  I2C1_InitStructure.I2C_Timing = 0x00B01A4B;// 400KHz | 8MHz-0x00310309; 16MHz-0x10320309; 48MHz-50330309  I2C1_InitStructure.I2C_OwnAddress1 =0;
  I2C1_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C1_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
  I2C1_InitStructure.I2C_DigitalFilter = 0x00;
  I2C1_InitStructure.I2C_OwnAddress1 = 0x00;
  I2C1_InitStructure.I2C_Ack = I2C_Ack_Enable;  
  I2C1_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;  
  I2C_Init(I2C1, &I2C1_InitStructure);
  
  I2C_MasterRequestConfig(I2C1,I2C_Direction_Receiver); // Master reading mode   
  I2C1->CR1 |= I2C_IT_RXI;    // Enable RXNE Event
//  GPIO_SetBits(GPIOB,GPIO_Pin_8);// Power up 
  Delay(10);
  I2C_Cmd(I2C1,ENABLE);

/*Read function*/
void I2C1MasterBufferRead() {

    I2C_TransferHandling(I2C1,(LM73_BASE_ADDR),2,I2C_AutoEnd_Mode,I2C_Generate_Start_Read);
    while(I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == RESET);
    ucI2CReadBuff[0] = I2C_ReceiveData(I2C1);
    while(I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == RESET);    
    ucI2CReadBuff[1] = I2C_ReceiveData(I2C1);
    while(I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == SET);
    I2C_ClearFlag(I2C1,I2C_FLAG_STOPF); 
 }

 

Outcomes