cancel
Showing results for 
Search instead for 
Did you mean: 

STM32476RG I2C mem write not seen in Memory read ?

RShiv.1
Senior

Hi,

Attached is the code where I am doing I2C write

//I2C write in memory*/

void I2C_write_mem()

{

/*** Mac ID read I2C read***/

  char MSG2[] = " start I2C3 write \n\r";

       HAL_UART_Transmit(&huart5,(uint8_t*)MSG2,sizeof(MSG2),1000);

       HAL_Delay(1000);

    uint16_t DevAddress = 0xA0;

     uint16_t MemAddress = 0x0010;

     uint8_t mac_id_buf2[6] = "";

    char print_msg1[100] = "";

   mac_id_buf2[0] = "AB";

   mac_id_buf2[1] = "12";

   mac_id_buf2[2] = "CD";

      mac_id_buf2[3] = "34";

      mac_id_buf2[4] = "FF";

      mac_id_buf2[5] = "57";

     if(HAL_OK == HAL_I2C_IsDeviceReady(&hi2c1,DevAddress,200,2000)){

  if(HAL_OK == HAL_I2C_Mem_Write(&hi2c1,DevAddress,MemAddress,I2C_MEMADD_SIZE_8BIT,(uint8_t*)&mac_id_buf2,0x0006,HAL_MAX_DELAY)) {

        strcpy(print_msg1,"SUCCESS HAL_I2C_Mem_write\r\n");

      HAL_UART_Transmit(&huart5,(uint8_t*)print_msg1,strlen(print_msg1),1000);

     //HAL_I2C_Mem_Write(&hi2c1,DevAddress,MemAddress,I2C_MEMADD_SIZE_8BIT,(uint8_t*)&mac_id_buf1[1],0x0002,HAL_MAX_DELAY);

    //sprintf(print_msg1,"%X %X %X %X %X %X\r\n", mac_id_buf1[0],mac_id_buf1[1],mac_id_buf1[2],mac_id_buf1[3],mac_id_buf1[4],mac_id_buf1[5]);

    //HAL_UART_Transmit(&huart5,(uint8_t*)print_msg1,strlen(print_msg1),1000);

     }

     else{

     strcpy(print_msg1,"ERROR in HAL_I2C_Mem_Write()\r\n");

     }

        }

   else{

    strcpy(print_msg1,"ERROR in HAL_I2C_IsDeviceReady()\r\n");

   }

}

also in while I am doing I2C read

//I2C mem read for memory*/

void I2C_read_mem()

{

/*** Mac ID read I2C read***/

  char MSG2[] = " start I2C2 read \n\r";

       HAL_UART_Transmit(&huart5,(uint8_t*)MSG2,sizeof(MSG2),1000);

       HAL_Delay(1000);

    uint16_t DevAddress = 0x40 << 1;

     uint16_t MemAddress = 0x0010;

     char mac_id_buf1[6] = "";

    char print_msg1[100] = "";

     if(HAL_OK == HAL_I2C_IsDeviceReady(&hi2c1,DevAddress,200,2000)){

  if(HAL_OK == HAL_I2C_Mem_Read(&hi2c1,DevAddress,MemAddress,I2C_MEMADD_SIZE_8BIT,(uint8_t*)&mac_id_buf1[0],0x0006,HAL_MAX_DELAY)) {

        strcpy(print_msg1,"SUCCESS HAL_I2C_Mem_Read\r\n");

      HAL_UART_Transmit(&huart5,(uint8_t*)print_msg1,strlen(print_msg1),1000);

    sprintf(print_msg1,"%X %X %X %X %X %X\r\n", mac_id_buf1[0],mac_id_buf1[1],mac_id_buf1[2],mac_id_buf1[3],mac_id_buf1[4],mac_id_buf1[5]);

    HAL_UART_Transmit(&huart5,(uint8_t*)print_msg1,strlen(print_msg1),1000);

     }

     else{

     strcpy(print_msg1,"ERROR in HAL_I2C_Mem_Read()\r\n");

     }

        }

   else{

    strcpy(print_msg1,"ERROR in HAL_I2C_IsDeviceReady()\r\n");

   }

}

this is for MCU STM32476RG Interfaced using I2C with M24M02 chip.

I am seeing successfull message in both I2C read and Write but not seeing the values which are being written..kindly let me know where the issue is.

thanks and regards

Ravi

This discussion is locked. Please start a new topic to ask your question.
4 REPLIES 4
RShiv.1
Senior

Hi ,

attached is the memory chip details.

--

Ozone
Principal

Do you see an ACK from the memory slave device on the bus ?

RShiv.1
Senior

Hi ,

yes I am getting success message

for write as well as read

SUCCESS HAL_I2C_Mem_write

SUCCESS HAL_I2C_Mem_Read

for both..is my addressing and others are fine..Kindly help me out.

thanks

Ravi

RShiv.1
Senior

Hi ,

I got the answer and now I2C write is working ...while I am reading I had to read from )0xA1 as the address and write at 0xA0...that solved the problem.

Thanks anyways for your inputs

regards

Ravi chandran