cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to use I2C communication using ST NUCLEO-F030R8 with AT24C64 and modifying code generated by STM32CubeMX. When I use HAL_I2C_IsDeviceReady function it returns HAL_OK but HAL_I2C_Mem_Write or HAL_I2C_Mem_Read function returns error

NAmat
Associate II

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.

0 REPLIES 0