cancel
Showing results for 
Search instead for 
Did you mean: 

HAL I2C Communication Problem

Sandeep Dhokne
Associate II
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.

1 ACCEPTED SOLUTION

Accepted Solutions
john doe
Lead
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

View solution in original post

2 REPLIES 2
john doe
Lead
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

Posted on July 17, 2017 at 11:39

Thank you so much.

My problem is solved.