gpt4 book ai didi

c - 将 A71CH 与 I2C 连接

转载 作者:太空宇宙 更新时间:2023-11-04 04:12:00 25 4
gpt4 key购买 nike

我正在尝试将以下芯片与 STM32F4 接口(interface) 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 */

}

最佳答案

根据 the datasheet of the chip ,SCI2C通信不是纯I2C,而是基于SMBus ,它源自 I2C。 STM32F4 HAL不支持 SMBus 但 ST 提供 X-CUBE-SMBUS软件包,可用于实现 SCI2C 协议(protocol)。您必须深入研究协议(protocol)细节并创建自己的库,因为该协议(protocol)非常新,我找不到您可以使用的以前的实现。如果你让它工作,我会建议通过将它上传到 GitHub 或类似的共享平台来为开源社区做出贡献。

关于c - 将 A71CH 与 I2C 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com