2018-04-10 03:49 AM
I DON'T KNOW ADDRESS OF M24M01-RMN6TP slave.
if((HAL_I2C_Master_Transmit(&hi2c1,(devAddess),(uint8_t *)&buffer,3,100))==HAL_OK)
{ HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_4); HAL_Delay(200);}if((HAL_I2C_Master_Receive(&hi2c1,(devAddress),(uint8_t *)&buffer,3,100))==HAL_OK){ HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_3); HAL_Delay(200);} }#m24m #m24m02 #eeprom-memory #hal #i2cSolved! Go to Solution.
2018-04-10 06:02 AM
HAL wants a 16 bit address shifted to the left. try (uint16_t)(devAddress << 1) instead of (devAddress)
on the premise your EEPROM is configured to read at 0x50, the shifted address is 0xA0 - 0x50 << 1 is 0xA0
The code is very well commented. Look in STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c
here's a code snippet to scan the I2C bus of a HAL project:
printf('Scanning I2C bus:\r\n'); HAL_StatusTypeDef result; uint8_t i; for (i=1; i<128; i++) { /* * the HAL wants a left aligned i2c address * &hi2c1 is the handle * (uint16_t)(i<<1) is the i2c address left aligned * retries 2 * timeout 2 */ result = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 2, 2); if (result != HAL_OK) // HAL_ERROR or HAL_BUSY or HAL_TIMEOUT { printf('.'); // No ACK received at that address } if (result == HAL_OK) { printf(' 0x%X ', i); // Received an ACK at that address } } printf('\r\n');2018-04-10 06:02 AM
HAL wants a 16 bit address shifted to the left. try (uint16_t)(devAddress << 1) instead of (devAddress)
on the premise your EEPROM is configured to read at 0x50, the shifted address is 0xA0 - 0x50 << 1 is 0xA0
The code is very well commented. Look in STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c
here's a code snippet to scan the I2C bus of a HAL project:
printf('Scanning I2C bus:\r\n'); HAL_StatusTypeDef result; uint8_t i; for (i=1; i<128; i++) { /* * the HAL wants a left aligned i2c address * &hi2c1 is the handle * (uint16_t)(i<<1) is the i2c address left aligned * retries 2 * timeout 2 */ result = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 2, 2); if (result != HAL_OK) // HAL_ERROR or HAL_BUSY or HAL_TIMEOUT { printf('.'); // No ACK received at that address } if (result == HAL_OK) { printf(' 0x%X ', i); // Received an ACK at that address } } printf('\r\n');2018-04-11 01:39 AM
Hi
doe.john.016
Thanks for your quick reply,It was very helpful for me.
pawan sharma
india