2019-01-21 02:51 AM
if(HAL_I2C_IsDeviceReady(&hi2c2,0xA0,10,100)==HAL_OK){
sprintf((char*)TxBuff,"\r\ni2c device ready");
}
else{
sprintf((char*)TxBuff,"\r\ni2c device fail");
}
if(HAL_I2C_Mem_Write(&hi2c2,0xA0,mem_add,32,&data_send,1,10)==HAL_OK){
sprintf((char*)TxBuff,"\r\nI2C WRITE OK");
HAL_UART_Transmit(&huart2,TxBuff,strlen((char*)TxBuff),100);
}
else{
sprintf((char*)TxBuff,"\r\nI2C WRITE FAIL");
HAL_UART_Transmit(&huart2,TxBuff,strlen((char*)TxBuff),100);
}
HAL_Delay(10);
if(HAL_I2C_Mem_Read(&hi2c2,0xA0,mem_add,32,&data_recv,1,10)==HAL_OK){
sprintf((char*)TxBuff,"\r\nI2C READ OK");
HAL_UART_Transmit(&huart2,TxBuff,strlen((char*)TxBuff),100);
HAL_Delay(1000);
sprintf((char*)TxBuff,"\r\nAdd=%d Data=%d",mem_add,data_recv);
HAL_UART_Transmit(&huart2,TxBuff,strlen((char*)TxBuff),100);
}
else{
sprintf((char*)TxBuff,"\r\nI2C READ FAIL");
HAL_UART_Transmit(&huart2,TxBuff,strlen((char*)TxBuff),100);
}
-----------------------OUTPUT--------------------------------
<CR><LF>
i2c device ready<CR><LF>
I2C WRITE FAIL<CR><LF>
I2C READ FAIL<CR><LF>
I2C WRITE FAIL<CR><LF>
I2C READ FAIL<CR><LF>
I2C WRITE FAIL<CR><LF>
I2C READ FAIL<CR><LF>
-----------------------------------------------
Could anyone please let me know what extra steps need to carry out to make it work.