title: STM32 I2C Issues with NFC Chip
body: <p>I've created a PCB with a <a href="https://www.mouser.com/ProductDetail/STMicroelectronics/STM32F207ZET6?qs=L6eUzyzWLAvlPJjr0ZD%2FHw%3D%3D" rel="nofollow noreferrer">STM32F207ZET6</a> and it has an <a href="https://www.mouser.com/ProductDetail/771-NT3H2211W0FTTJ" rel="nofollow noreferrer">NXP NFC</a> chip connected via I2C.
  The problem that I am having is that I can not communicate with the NFC chip. </p>
  
  <p>I have verified the I2C connection between the ARM chip and NFC.
  I have verified that both chips are getting the correct power.<br>
  I am using stm32cube IDE with a stlink-v3.
  I configured the I2C1 pins and wrote the following code.</p>
  
  <p><strong>What I have tried</strong></p>
  
  <ul>
  <li>I have tried to use <code>HAL_I2C_IsDeviceReady()</code> to see if the NFC was connected. This returns true, but it also returns true on every address that I put in there.</li>
  <li>I have tried to send commands and also read them back into a buffer array. All that was returned was 0.</li>
  </ul>
  
  <pre><code>    cmds[1] = 0x60;
      cmds[2] = 0x00;
      HAL_I2C_Master_Transmit(&amp;hi2c1, nfc_Adr_w, cmds, 2, HAL_MAX_DELAY);
  
      HAL_Delay(15);
  
      HAL_I2C_Master_Transmit(&amp;hi2c1, nfc_Adr_w, cmds, 1, HAL_MAX_DELAY);
  
      HAL_I2C_Master_Receive(&amp;hi2c1, nfc_Adr_r, buffer, 1, HAL_MAX_DELAY);
  </code></pre>
  
  <p>Any help would be greatly appreciated, thank you.</p>
  
  <p><strong>Full Code</strong></p>
  
  <pre><code>#include "main.h"
  
  /* Private variables ---------------------------------------------------------*/
  I2C_HandleTypeDef hi2c1;
  
  /* Private function prototypes -----------------------------------------------*/
  void SystemClock_Config(void);
  static void MX_GPIO_Init(void);
  static void MX_I2C1_Init(void);
  
  unsigned char buffer[150];
  unsigned char cmds[3];
  _Bool results = 0;
  uint8_t devices = 0u;
  int deviceReady = 0u;
  /* Private user code ---------------------------------------------------------*/
  
  /**
    * @brief  The application entry point.
    * @retval int
    */
  int main(void)
  {
      uint8_t nfc_Adr_w = 0b10101010;
      uint8_t nfc_Adr_r = 0b10101011;
    /* MCU Configuration--------------------------------------------------------*/
  
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
  
    /* USER CODE BEGIN Init */
  
    /* USER CODE END Init */
  
    /* Configure the system clock */
    SystemClock_Config();
  
    /* USER CODE BEGIN SysInit */
  
    /* USER CODE END SysInit */
  
    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_I2C1_Init();
    /* USER CODE BEGIN 2 */
  
    /* USER CODE END 2 */
  
    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
  
    while (1)
    {
      /* USER CODE END WHILE */
  
        //HAL_I2C_Master_Transmit();
  
        //HAL_I2C_Master_Receive();
        cmds[0] = 0x00;
        cmds[1] = 0x60;
        cmds[2] = 0x00;
        HAL_I2C_Master_Transmit(&amp;hi2c1, nfc_Adr_w, cmds, 2, HAL_MAX_DELAY);
  
        HAL_Delay(15);
  
        HAL_I2C_Master_Transmit(&amp;hi2c1, nfc_Adr_w, cmds, 1, HAL_MAX_DELAY);
  
        HAL_I2C_Master_Receive(&amp;hi2c1, nfc_Adr_r, buffer, 1, HAL_MAX_DELAY);
  
  //    deviceReady = HAL_I2C_IsDeviceReady(&amp;hi2c1, 0x3C, 3u, 10u);
  //    printf("Searching for I2C devices on the bus...\n");
          /* Values outside 0x03 and 0x77 are invalid. */
  //      for (uint8_t i = 0x03u; i &lt; 0x78u; i++)
  //      {
  //        uint8_t address = i &lt;&lt; 1u;
  //        /* In case there is a positive feedback, print it out. */
  //        if (HAL_OK == HAL_I2C_IsDeviceReady(&amp;hi2c1, address, 3u, 10u))
  //        {
  ////            printf("Device found: 0x%02X\n", address);
  //          devices++;
  //          results = 1;
  //        }
  //        if (HAL_TIMEOUT == HAL_I2C_IsDeviceReady(&amp;hi2c1, address, 3u, 10u)) {
  //            devices++;
  //        }
  //        deviceReady = HAL_I2C_IsDeviceReady(&amp;hi2c1, address, 3u, 10u);
  //      }
  //      /* Feedback of the total number of devices. */
  ////        if (0u == devices)
  ////        {
  //////        printf("No device found.\n");
  ////        }
  ////        else
  ////        {
  ////          printf("Total found devices: %d\n", devices);
  ////        }
        HAL_Delay(1000u);
        devices = 0u;
      /* USER CODE BEGIN 3 */
    }
    /* USER CODE END 3 */
  }
  
  /**
    * @brief System Clock Configuration
    * @retval None
    */
  void SystemClock_Config(void)
  {
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  
    /** Initializes the CPU, AHB and APB busses clocks 
    */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
    if (HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) != HAL_OK)
    {
      Error_Handler();
    }
    /** Initializes the CPU, AHB and APB busses clocks 
    */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  
    if (HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
    {
      Error_Handler();
    }
  }
  
  /**
    * @brief I2C1 Initialization Function
    * @param None
    * @retval None
    */
  static void MX_I2C1_Init(void)
  {
  
    /* USER CODE BEGIN I2C1_Init 0 */
  
    /* USER CODE END I2C1_Init 0 */
  
    /* USER CODE BEGIN I2C1_Init 1 */
  
    /* USER CODE END I2C1_Init 1 */
    hi2c1.Instance = I2C1;
    hi2c1.Init.ClockSpeed = 100000;
    hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
    hi2c1.Init.OwnAddress1 = 0;
    hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
    hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    hi2c1.Init.OwnAddress2 = 0;
    hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
    if (HAL_I2C_Init(&amp;hi2c1) != HAL_OK)
    {
      Error_Handler();
    }
    /* USER CODE BEGIN I2C1_Init 2 */
  
    /* USER CODE END I2C1_Init 2 */
  
  }
  
  /**
    * @brief GPIO Initialization Function
    * @param None
    * @retval None
    */
  static void MX_GPIO_Init(void)
  {
    GPIO_InitTypeDef GPIO_InitStruct = {0};
  
    /* GPIO Ports Clock Enable */
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();
  
    /*Configure GPIO pin Output Level */
    HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
  
    /*Configure GPIO pin : LED_Pin */
    GPIO_InitStruct.Pin = LED_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(LED_GPIO_Port, &amp;GPIO_InitStruct);
  
  }
  
  /* USER CODE BEGIN 4 */
  
  /* USER CODE END 4 */
  
  /**
    * @brief  This function is executed in case of error occurrence.
    * @retval None
    */
  void Error_Handler(void)
  {
    /* USER CODE BEGIN Error_Handler_Debug */
    /* User can add his own implementation to report the HAL error return state */
  
    /* USER CODE END Error_Handler_Debug */
  }
  
  #ifdef  USE_FULL_ASSERT
  /**
    * @brief  Reports the name of the source file and the source line number
    *         where the assert_param error has occurred.
    * @param  file: pointer to the source file name
    * @param  line: assert_param error line source number
    * @retval None
    */
  void assert_failed(uint8_t *file, uint32_t line)
  { 
    /* USER CODE BEGIN 6 */
    /* User can add his own implementation to report the file name and line number,
       tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    /* USER CODE END 6 */
  }
  #endif /* USE_FULL_ASSERT */
  
  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  </code></pre>