AnsweredAssumed Answered

How to use the API of CUBE to send date "0x00" with I2C1 ?

Question asked by tong.wenfei on Jan 6, 2015
Latest reply on Jan 7, 2015 by Amel N
I have a temperature sensor,the TMP275.Today I want to test it with I2C,I have test it with Standard Library,I can read it with NUCLEO stm32f072 board.But when i use the cube Library to read it,it's break.I have used the Function "HAL_I2C_Master_Receive()",this is my code of send reg address "0x00",it breaked when i send it.
void TMP275_Read(void)
{
TxBuffer
  while(HAL_I2C_Master_Transmit(&hi2c1,(uint16_t) I2C1_WRITE_ADDRESS,(uint8_t*) TxBuffer, 1, 1000)!= HAL_OK)
      {
        /* Error_Handler() function is called when Timout error occurs.
           When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
           Master restarts communication */
        if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
        {
          Error_Handler();
        }
      }
  while(HAL_I2C_Master_Receive(&hi2c1, (uint16_t)I2C1_READ_ADDRESS,(uint8_t*) aRxBuffer, 2, 1000)!= HAL_OK)
      {
        /* Error_Handler() function is called when Timout error occurs.
           When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
           Master restarts communication */
        if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
        {
          Error_Handler();
        }
      }
}

 when i read it ,i have  initialized the TMP275,There is the code:
void TMP275_Init(void)
{
  aTxBuffer[0]=0x01;
  aTxBuffer[1]=0xfe;
  //aTxBuffer[2]=0x00;
 
    while(HAL_I2C_Master_Transmit(&hi2c1,(uint16_t) I2C1_WRITE_ADDRESS,(uint8_t*) aTxBuffer, 2, 1000)!= HAL_OK)
      {
        /* Error_Handler() function is called when Timout error occurs.
           When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
           Master restarts communication */
        if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
        {
          Error_Handler();
        }
      }
         
 
}

Outcomes