How to read and write to eeprom ic (24c16) using i2c in stm32f103
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-01-21 4:22 AM
- hi, i have to read and write to eeprom ic . i am able to write but i am not able to read from my ic .
- void write_eeprom_reg(uint16_t reg_addr, uint8_t value)
- {
- //uint8_t d[3];
- d[0]=(reg_addr>>8) & 0xFF;
- d[1]=(reg_addr) & 0xFF;
- d[2]=value;
- while(HAL_I2C_IsDeviceReady(&hi2c1,(uint16_t)(0x50<<1),3,100)!=HAL_OK)
- {
- }
- if(HAL_I2C_Master_Transmit(&hi2c1,(uint16_t)(0x50<<1),(uint8_t*)d,sizeof(d),1000)!=HAL_OK)
- {
- Error_Handler();
- }
- else
- {
- printf("Master transmitt Successfull\r\n");
- }
- }
- uint8_t read_eeprom_reg(uint16_t addr)
- {
- uint8_t buffer[]={0x05};
- //uint8_t buffer=addr;
- uint8_t value;
- while(HAL_I2C_IsDeviceReady(&hi2c1,(uint16_t)(0x50<<1),3,100)!=HAL_OK)
- {
- }
- while(HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)(0x50<<1), (uint8_t*)&buffer, 2, 100)!=HAL_OK)
- {
- if(HAL_I2C_GetError(&hi2c1)!=HAL_I2C_ERROR_AF)
- {
- Error_Handler();
- }
- }
- while(HAL_I2C_IsDeviceReady(&hi2c1,(uint16_t)(0x50<<1),3,100)!=HAL_OK)
- {
- }
- while(HAL_I2C_Master_Receive(&hi2c1, (uint16_t)(0x50<<1),(uint8_t*)&value,1,100)!=HAL_OK)
- {
- if(HAL_I2C_GetError(&hi2c1)!=HAL_I2C_ERROR_AF)
- {
- Error_Handler();
- }
- return value;
- }
- }
- This is the code i have done can anyone say me the error what i have done and what i need to add to it so that i can write to my eeprom ic and read from eeprom ic.
Thank you
Labels:
- Labels:
-
I2C
-
STM32F1 Series
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-01-21 6:35 AM
