Skip to main content
Sandeep Dhokne
Associate III
Jul 14, 2017 9:52 AM UTC
Solved

HAL I2C Communication Problem

Posted on July 14, 2017 at 11:52

Dear Sir/Madam,

I am working on STM32F405 mcu.

I developed my code on cubemx and HAL drivers.

I want to interface microchip adc 'MCP3428' via HAL I2C drivers but unfortunately i was failed.

Anybody of you please help me to resolved this issue.

Thank you.

    This topic has been closed for replies.
    john doe
    john doeBest answer
    Senior III
    Jul 14, 2017 5:45 PM UTC
    Posted on July 14, 2017 at 19:45

            status = HAL_I2C_Mem_Write(&hi2c1,                        // i2c handle

                                  (uint16_t)(dev_addr<<1),        // i2c address, left aligned

                                  (uint8_t)reg_addr,            // register address

                                  I2C_MEMADD_SIZE_8BIT,            //  8bit register addresses

                                  (uint8_t*)(&reg_data),        // write returned data to variable named reg_data

                                  cnt,                            // write how many bytes

                                  100);                            // timeout

    you'll have to read your data sheet for addresses and sizes, but the above code is how to read a register

    2 replies

    john doe
    john doeBest answer
    Senior III
    Jul 14, 2017 5:45 PM UTC
    Posted on July 14, 2017 at 19:45

            status = HAL_I2C_Mem_Write(&hi2c1,                        // i2c handle

                                  (uint16_t)(dev_addr<<1),        // i2c address, left aligned

                                  (uint8_t)reg_addr,            // register address

                                  I2C_MEMADD_SIZE_8BIT,            //  8bit register addresses

                                  (uint8_t*)(&reg_data),        // write returned data to variable named reg_data

                                  cnt,                            // write how many bytes

                                  100);                            // timeout

    you'll have to read your data sheet for addresses and sizes, but the above code is how to read a register

    Sandeep Dhokne
    Associate III
    Jul 17, 2017 11:39 AM UTC
    Posted on July 17, 2017 at 11:39

    Thank you so much.

    My problem is solved.