我正在尝试将以下芯片与STM32F4 https://www.nxp.com/docs/en/supporting-information/AN12207.pdf
连接我目前正在尝试使用具有中断的hal顺序传输来传输重复开始,但是它根本不起作用,我得到了NAK。
有人会给我一些见解,如何进行接口以及应该使用哪些HAL函数?
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初始化
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 */
}
答案 0 :(得分:0)
根据the datasheet of the chip,SCI2C通信不是纯I2C,而是基于SMBus,它是从I2C派生的。 STM32F4 HAL不支持SMBus,但是ST提供了X-CUBE-SMBUS软件包,可用于实现SCI2C协议。您必须深入研究协议的细节并创建自己的库,因为该协议是相当新的,而且我找不到可以使用的以前的实现。如果您可以使用它,我建议您将其上传到GitHub或类似的共享平台,从而为开源社区做出贡献。