0
\$\begingroup\$

I am using stm32cubemx to create an I2C project. I am using nucleo64 L476RG to connect with I2C ds2482-100, and another 1-wire DS28EC20 is connected with I2C. I am very new to this project. The first thing I need to figure out is the I2C address for the MX_I2C1_Init() function, in the line hi2c1.Init.OwnAddress1 = ?.

My questions are:

  1. For this 3 parts system (microcontroller, I2C, 1-wire), I just want to read data from 1-wire DS28EC20. Is I2C a master or slave?

  2. Shall I find this I2C address in the ds2482-100 datasheet? I could not find the address!

\$\endgroup\$
0
0
\$\begingroup\$

The STM32 is the master, it will not be slave. Therefore you can leave the OwnAddress1 and OwnAddress2 to zeroes, these are not used when communicating with other chips.

Also the DS2482-100 I2C slave address is in the datasheet Figure 8. So it will be 0x30, 0x32, 0x34 or 0x36 depending on how the DS2482-100 address select pins are configured.

\$\endgroup\$
4
  • \$\begingroup\$ thanks,so you mean in MX_I2C1_Init() I could leave both ownAddress1 and OwnAddress2 to zeroes, but when I need to access I2C, such as HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout), I need to fill in a real address? such as 0x30...? \$\endgroup\$ – adam May 30 '19 at 21:29
  • \$\begingroup\$ Yes, exactly. If this answers your questions, please accept as answer. \$\endgroup\$ – Justme May 30 '19 at 21:48
  • \$\begingroup\$ cool, now I also notice when I use HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout), it mentions * @param DevAddress Target device address: The device 7 bits address value * in datasheet must be shifted to the left before calling the interface so I am confused about when I should add the last bit for read or write access? if I add the last bit 1, the address is changed? \$\endgroup\$ – adam May 30 '19 at 22:19
  • \$\begingroup\$ The addresses I listed are already in 8-bit form you can use with HAL. \$\endgroup\$ – Justme May 31 '19 at 5:40
0
\$\begingroup\$

You can simply find external device's address by using the function HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
You should create "for loop" to search all adress from 0 to 127 whenever it finds the adress for loop should be broken.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for information.I edited the answer. \$\endgroup\$ – emre iris May 30 '19 at 21:59
  • \$\begingroup\$ char hex_v[10]; for (int i=1;i<255;i++) { sprintf(hex_v, "%x", i); if( HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)hex_v, 1, 10000)== HAL_OK) { break; } } very confused why it is not break out, hex_v is 254 after the loop.... \$\endgroup\$ – adam May 30 '19 at 22:27
  • \$\begingroup\$ You give human printable strings to HAL as address, which does not work. Just give the address i. \$\endgroup\$ – Justme May 31 '19 at 5:43
  • \$\begingroup\$ thanks, I gave up hex and just use i=1,2,3,4...HAL_I2C_IsDeviceReady(&hi2c1, i, 1, 10000) and found the I2C address \$\endgroup\$ – adam May 31 '19 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.