Coder Social home page Coder Social logo

24c08 and EEPROM24XX_Save about ee24 HOT 5 CLOSED

nimaltd avatar nimaltd commented on August 23, 2024
24c08 and EEPROM24XX_Save

from ee24.

Comments (5)

nimaltd avatar nimaltd commented on August 23, 2024

hello. did you config eeprom24xxconfig.h ?
#define _EEPROM_SIZE_KBIT 8

from ee24.

kko123 avatar kko123 commented on August 23, 2024

sure. I think the error in (uint16_t)_EEPROM_ADR|(Address&0x0003),Address>>2
High address bits must be in HW_ADR, but you used low. What do you think?

from ee24.

nimaltd avatar nimaltd commented on August 23, 2024

from ee24.

igorzhur727 avatar igorzhur727 commented on August 23, 2024

Hello!
Thank you for your work!
But let me amend.
If we use a 24LC16 chip with a page size of 16 bytes, then when writing 4 bytes from address 14, 2 bytes will be written to addresses 14 and 15 and the other two bytes will be written at the beginning of the page to addresses 0 and 1. This memory feature is described in the datasheet. I corrected the code to write correctly.

bool EE24xx_Write(uint16_t address, uint8_t *data, size_t len, uint32_t timeout)
{
uint16_t p, b, w;
uint16_t start_num_of_page;
uint16_t end_num_of_page;
uint16_t end_adr_of_page;
uint32_t startTime = HAL_GetTick();
// Если память занята то ждем тайм-аут
while (ee24_lock == 1)
{
if (HAL_GetTick() - startTime >= timeout)
return false;
ee24_delay(1);
}
//------------------------------------------------------------------------------
ee24_lock = 1;
//------------------------------------------------------------------------------
#if (_EEPROM_USE_WP_PIN==1)
HAL_GPIO_WritePin(_EEPROM_WP_GPIO, _EEPROM_WP_PIN,GPIO_PIN_RESET);
#endif
//------------------------------------------------------------------------------
while(1)
{
p = len / _EEPROM_PSIZE; // число страниц для записи
b = len % _EEPROM_PSIZE; // остаток байт на странице

if( p > 0) w = _EEPROM_PSIZE;   // Если число записываемых байт больше чем размер страницы то пишем только одну страницу
else       w = b;               // Если число записываемых байт меньше чем размер страницы то пишем это число байт
//
start_num_of_page = (long)(address / _EEPROM_PSIZE);       // страница где начинается запись
end_num_of_page   =(long)((address+w) / _EEPROM_PSIZE);    // страница где заканчивается запись
//
if (end_num_of_page > start_num_of_page) 
{ // данные на страницу не вмещаются. пишем их раздельно. Вычисляем остаток байт на странице.
  end_adr_of_page = ((start_num_of_page+1) * _EEPROM_PSIZE)-1; // Конечный адресс на странице.
  w = (end_adr_of_page - address)+1; 
}

#if ((_EEPROM_SIZE_KBIT==1) || (_EEPROM_SIZE_KBIT==2))
if (HAL_I2C_Mem_Write(&_EEPROM_I2C, _EEPROM_ADDRESS, address, I2C_MEMADD_SIZE_8BIT, data, w, 100) == HAL_OK)
#elif (_EEPROM_SIZE_KBIT==4)
if (HAL_I2C_Mem_Write(&_EEPROM_I2C, _EEPROM_ADDRESS | (((address & 0x0100) >> 7)), (address & 0xff), I2C_MEMADD_SIZE_8BIT, data, w, 100) == HAL_OK)
#elif (_EEPROM_SIZE_KBIT==8)
if (HAL_I2C_Mem_Write(&_EEPROM_I2C, _EEPROM_ADDRESS | (((address & 0x0300) >> 7)), (address & 0xff), I2C_MEMADD_SIZE_8BIT, data, w, 100) == HAL_OK)
#elif (_EEPROM_SIZE_KBIT==16)
if (HAL_I2C_Mem_Write(&_EEPROM_I2C, _EEPROM_ADDRESS | (((address & 0x0700) >> 7)), (address & 0xff), I2C_MEMADD_SIZE_8BIT, data, w, 100) == HAL_OK)		
#else
if (HAL_I2C_Mem_Write(&_EEPROM_I2C, _EEPROM_ADDRESS, address, I2C_MEMADD_SIZE_16BIT, data, w, 100) == HAL_OK)
#endif
{
  ee24_delay(10);
  len -= w;
  data += w;
  address += w;
  if (len == 0)
  {
    #if (_EEPROM_USE_WP_PIN==1)
    HAL_GPIO_WritePin(_EEPROM_WP_GPIO, _EEPROM_WP_PIN, GPIO_PIN_SET);
    #endif
    ee24_lock = 0;
    return true;
  }
  if (HAL_GetTick() - startTime >= timeout) 
  {
    ee24_lock = 0;
    return false;
  }
}
else
{
  #if (_EEPROM_USE_WP_PIN==1)
  HAL_GPIO_WritePin(_EEPROM_WP_GPIO, _EEPROM_WP_PIN, GPIO_PIN_SET);
  #endif
  ee24_lock = 0;
  return false;		
}

}
}

from ee24.

nimaltd avatar nimaltd commented on August 23, 2024

@igorzhur727 . this is fixed now. please try again with 2.1.0

from ee24.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.