我正在一个项目中,我需要将STM32L152RDT6设置为I2C的从设备,但我无法获得它。 我尝试过,但是失败了:
HAL_I2C_SlaveRxCpltCallback(&hi2c1);
I2C_HandleTypeDef hi2c1;
uint8_t aRxBuffer[1];
uint8_t aTxBuffer[] = " ****I2C_TwoBoards communication based on Polling**** ****I2C_TwoBoards communication based on Polling**** ****I2C_TwoBoards communication based on Polling**** ";
if(HAL_I2C_Slave_Receive(&hi2c1, (uint8_t *)aRxBuffer, 1, 10000) != HAL_OK)
{
/* Transfer error in reception process */
Error_Handler();
}
else{
printf("succeed\n");
printf("I2C data: %d ",aRxBuffer[0]);
}
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *I2cHandle)
{
/* Turn LED6 on: Transfer in reception process is correct */
printf("Amazing\n");
}
我需要一个示例,请使用HAL库将STM32设置为I2C的从设备。
非常感谢您!