0

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!

Justin
  • 5,944
  • 21
  • 34
adam
  • 49
  • 6

2 Answers2

0

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.

emre iris
  • 127
  • 1
  • 9
  • 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.... – adam May 30 '19 at 22:27
  • You give human printable strings to HAL as address, which does not work. Just give the address i. – Justme May 31 '19 at 05:43
  • 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 – adam May 31 '19 at 18:14
0

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.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • 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...? – adam May 30 '19 at 21:29
  • 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? – adam May 30 '19 at 22:19
  • The addresses I listed are already in 8-bit form you can use with HAL. – Justme May 31 '19 at 05:40