cancel
Showing results for 
Search instead for 
Did you mean: 

Help in intializing i2c

sh_azmoodeh
Associate II
Posted on November 21, 2016 at 19:32

hi all

i run a tiny project with STM32L433 and have a problem with i2c protocol ,

i have a MCP79410 microchip real time chip and use it for this project

after i initialize i2c with HAL DRIVER i should use HAL APIs

like HAL_I2C_MASTER_TRANSMIT();

ok , that so easy , but one problem occur : it function just write on the bus . its mean when i send address device than chip can write on the bus : for example i need to access contents in 0x02 register location on device target , after i use this function and write 0x02 on bus, i cant read any byte on bus because this function only write on the bus and when end , it close the bus , i need to content after called register address :( it same not possible

#hal_dr #stm32l4 #i2c #stm32l433
6 REPLIES 6
Arnold Bischof
Associate III
Posted on November 22, 2016 at 13:50

hello az.ahahab

try to use the method HAL_I2C_Master_Receive() instead.

sh_azmoodeh
Associate II
Posted on November 22, 2016 at 15:55

thanks arnold for replay

ok . np . problem is here . both this function only can read or write .

i should send address register first and than read content on this address!

it mean function we called HAL_I2C_Master_Receive() just can read from bus and cant write address we need than read the bus .

and problem is in parameter it can pull, attention this :

HAL_I2C_Master_Receive(&hi2c1,0xdf,I2C_DATA,3,5)

one : pointer of i2c we used

two: address device

three:pointer to save read data on bus

for:number of data on bus

five:timeout

ok , so i havent any parameter for called what register i need to save it content than save it content on my buffer(i2c_data)

problem is here

slimen
Senior
Posted on November 22, 2016 at 16:09

Hello,

I recommend you to have a look to the working examples under the STM32CubeL4 package, it may be helpful: STM32Cube_FW_L4_V1.5.0\Projects\STM32L476G_EVAL\Examples\I2C

You can inspire from the provided application, check your needed functions with regarding passed parameters.

Regards

sh_azmoodeh
Associate II
Posted on November 22, 2016 at 16:28

hey forumstm32

before i posted here i try its way , even i try f4 example pakages . on these example code , ST provided example only read routine only or write routine only . its mean on example code provided by st i cant found any example code contain what i need . its very simple and i havent any problem with e.x AVR, just i need write address register on the bus than read content of that register on the bus before rise stop bit on bus . :| perhaps we cant use hal driver in this mode . :| i confused

sh_azmoodeh
Associate II
Posted on December 12, 2016 at 16:37

I have this problem yet, please help me . i need make a connection with RTC chips , i need to make start bit and go into receive mode before stop bit event , in HAL FUNCTION its function is lost and no more create for this problem .

>:(

sh_azmoodeh
Associate II
Posted on December 22, 2016 at 12:31

i solved this problem but with cross-cut way:

i used this function but i cant guaranty that for work with all chips,otherwise this function work with chips that support random read sequence and it work greatly:

HAL_I2C_Mem_Read(); 

thanks all