cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 HAL I2C Driver - Wrong Slave Address

PR.19
Associate II

Hi, I have a board with STM32F501R8T6 and AT24C02 & DS1307 RTC are connected to I2C2. Earlier i had used custom I2C driver and interfaced them with a 8051 controller without any issues. Now since there is a need to change the I/0 pins config in ARM each time for read & write I had to chose the HAL library & use the Pins in I2C AF mode. I use STM32Cubemx for config.

To read the DS1307 registers i used

HAL_I2C_Mem_Read(&hi2c2,(uint16_t)0xD0<<1,0x0000,I2C_MEMADD_SIZE_8BIT,rxbuffer,3,1000); which returns HAL_OK and returns the value i had written using HAL MEM write command. However the clock never seemed to tick and i had changed RTC & crystal and still no luck. Finally today is when i found out that the data is being written and read from the EEPROM AT24C02 and not the RTC which is why the data is not advancing as it should in an RTC. The address for EEPROM is 0xA0. When I use 0xD0<<1 i noticed that inside HAL library the device address is 0x01A0. Is this a bug in HAL library? If i use 0xDO without left shift it returns HAL error. How can i access the RTC? Is there something wrong with my code or is there a bug in the HAL library??

1 ACCEPTED SOLUTION

Accepted Solutions

Don't left-shift 0xD0.

> If i use 0xD0 without left shift it returns HAL error.

This may indicate that the DS1307 does not respond. Maybe a hardware problem - bad solder joint on the DS1307? Did you observe the I2C bus using oscilloscope or logic analyzer?

JW

View solution in original post

2 REPLIES 2

Don't left-shift 0xD0.

> If i use 0xD0 without left shift it returns HAL error.

This may indicate that the DS1307 does not respond. Maybe a hardware problem - bad solder joint on the DS1307? Did you observe the I2C bus using oscilloscope or logic analyzer?

JW

PR.19
Associate II

I just removed the left shift & it worked fine!

This is ridiculous, I did the left shift because it says so on the HAL library and in all the forums i checked with so far! I can't understand how none ran into this issue.

Anyways thank you!