andreahmed
andreahmed

Reputation: 29

Interfacing A71CH with I2C

I'm trying to interface the following chip with STM32F4 https://www.nxp.com/docs/en/supporting-information/AN12207.pdf

I'm currently trying to transmit a repeated start using hal sequential transmission with an interrupt but it doesn't work at all, I get NAK.

Would someone give me insights how to interface it and which HAL functions should I use?

unsigned int axI2CWriteRead(unsigned char bus_unused_param, unsigned char addr,
                            unsigned char *pTx, unsigned short txLen,
                            unsigned char *pRx, unsigned short *pRxLen)
{
    extern I2C_HandleTypeDef hi2c3;
    bool recv_length = false;
    HAL_StatusTypeDef status;

    *pRxLen = 0;
    memset(pRx, 0, 2);
    uint8_t rxData[255] = {0};

    status = HAL_I2C_Master_Sequential_Transmit_IT(&hi2c3, 0x90, pTx, txLen, I2C_FIRST_FRAME);

    if (status != HAL_OK)
        return I2C_FAILED;

    while (HAL_I2C_GetState(&hi2c3) != HAL_I2C_STATE_READY)
        ;

    readblock = true;
    readblock_length = 0;
    status = HAL_I2C_Master_Sequential_Receive_IT(&hi2c3, 0x90, rxData, 255, I2C_LAST_FRAME);

    if (status != HAL_OK)
        return I2C_FAILED;
    while (HAL_I2C_GetState(&hi2c3) != HAL_I2C_STATE_READY)
        ;
    readblock = false;
    readblock_length = 0;


    *pRxLen = rxData[0] + 1;

    memcpy(pRx, rxData, *pRxLen);

    return I2C_OK;
}

I2C3 Initialization

static void MX_I2C3_Init(void)
{

  /* USER CODE BEGIN I2C3_Init 0 */

  /* USER CODE END I2C3_Init 0 */

  /* USER CODE BEGIN I2C3_Init 1 */

  /* USER CODE END I2C3_Init 1 */
  hi2c3.Instance = I2C3;
  hi2c3.Init.ClockSpeed = 100000;
  hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c3.Init.OwnAddress1 = 0;
  hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c3.Init.OwnAddress2 = 0;
  hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_ENABLE;
  if (HAL_I2C_Init(&hi2c3) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C3_Init 2 */

  /* USER CODE END I2C3_Init 2 */

}

Upvotes: 1

Views: 384

Answers (1)

Bora
Bora

Reputation: 496

According to the datasheet of the chip, the SCI2C communication is not pure I2C, but rather based on SMBus, which is derived from I2C. The STM32F4 HAL does not support SMBus but ST provides X-CUBE-SMBUS software package, which you can use to implement the SCI2C protocol. You have to dig into the protocol specifics and create your own library, since the protocol is pretty new and I could not find a previous implementation that you can use. If you get it working, I would recommend contributing to the open-source community by uploading it to GitHub or a similar sharing platform.

Upvotes: 0

Related Questions