GithubHelp home page GithubHelp logo

nimaltd / ee24 Goto Github PK

View Code? Open in Web Editor NEW
145.0 8.0 41.0 3.07 MB

24xx EEPROM library for stm32 HAL

License: GNU General Public License v3.0

C 100.00%
stm32 stm32f1 stm32f2 stm32f4 stm32f0 hal eeprom 24cxx 24xx 24c01

ee24's Introduction

24xx EEPROM library for stm32 HAL


Please Do not Forget to get STAR, DONATE and support me on social networks. Thank you. ๐Ÿ’–




solve F1 i2c problem


void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(i2cHandle->Instance==I2C2)
  {
  /* USER CODE BEGIN I2C2_MspInit 0 */
   __HAL_RCC_I2C2_CLK_ENABLE();  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  add manualy
  /* USER CODE END I2C2_MspInit 0 */
  
    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**I2C2 GPIO Configuration    
    PB10     ------> I2C2_SCL
    PB11     ------> I2C2_SDA 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* I2C2 clock enable */
    __HAL_RCC_I2C2_CLK_ENABLE();
  /* USER CODE BEGIN I2C2_MspInit 1 */

  /* USER CODE END I2C2_MspInit 1 */
  }
}

example:

#include "ee24.h"

EE24_HandleTypeDef ee24;
uint8_t data[1024];
int main(void)
{
  ...
  ...
  ...
  if (EE24_Init(&ee24, &hi2c1, EE24_ADDRESS_DEFAULT))
  {
    EE24_Read(&ee24, 0, data, 1024, 1000);
  }
  while(1)
  {
  
  }
}

ee24's People

Contributors

leech001 avatar nimaltd avatar ruslanurya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ee24's Issues

Example for init

can you provide example for init of the EEPROM pins, as no clear documentation for that?

Erase chip function has a problem

In this function:

bool ee24_eraseChip(I2C_HandleTypeDef* i2c)
{
  const uint8_t eraseData[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF\
    , 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  uint32_t bytes = 0;
  while ( bytes < (_EEPROM_SIZE_KBIT / 8) * 1024)
  {
    if (ee24_write(i2c, bytes, (uint8_t*)eraseData, sizeof(eraseData), 100) == false)
      return false;
    bytes += sizeof(eraseData);           
  }
  return true;  
}

If _EEPROM_SIZE_KBIT was less than 8, the while condition will be always false because for example 2 divided by 8 is 0 in non-floating values. I think the condition should be like this:
while ( bytes < (_EEPROM_SIZE_KBIT * 256))

Also I didn't find out what does this condition mean ๐Ÿค”. Anyway, thanks for your attention ๐Ÿ™๐Ÿป

(I made a little changes in inputs and I2C handler pointer, but it isn't the problem ๐Ÿ˜…)

24c08 and EEPROM24XX_Save

I fill first 16 bytes from this code:

uint8_t	ReadEEPROM[16];
ReadEEPROM[0] = eeprom.ip[0];
ReadEEPROM[1] = eeprom.ip[1];
ReadEEPROM[2] = eeprom.ip[2];
ReadEEPROM[3] = eeprom.ip[3];
ReadEEPROM[4] = eeprom.sn[0];
ReadEEPROM[5] = eeprom.sn[1];
ReadEEPROM[6] = eeprom.sn[2];
ReadEEPROM[7] = eeprom.sn[3];
ReadEEPROM[8] = eeprom.gw[0];
ReadEEPROM[9] = eeprom.gw[1];
ReadEEPROM[10] = eeprom.gw[2];
ReadEEPROM[11] = eeprom.gw[3];										
ReadEEPROM[12] = eeprom.srvip[0];
ReadEEPROM[13] = eeprom.srvip[1];
ReadEEPROM[14] = eeprom.srvip[2];
ReadEEPROM[15] = eeprom.srvip[3];
EEPROM24XX_Save(0,ReadEEPROM,sizeof(ReadEEPROM));

then i trying to fill another part of page:

ReadEEPROM[0] = (uint8_t)((eeprom.api_port & 0xFF00) >> 8);
ReadEEPROM[1] = (uint8_t)(eeprom.api_port & 0x00FF);										
ReadEEPROM[2] = (uint8_t)((eeprom.srvport & 0xFF00) >> 8);
ReadEEPROM[3] = (uint8_t)(eeprom.srvport & 0x00FF);										
EEPROM24XX_Save(16,ReadEEPROM,4);

when I read the first page some data was corrupted (netInfo.gw)

EEPROM24XX_Load(0,ReadEEPROM,sizeof(ReadEEPROM));
netInfo.ip[0] = ReadEEPROM[0];
netInfo.ip[1] = ReadEEPROM[1];
netInfo.ip[2] = ReadEEPROM[2];
netInfo.ip[3] = ReadEEPROM[3];
netInfo.sn[0] = ReadEEPROM[4];
netInfo.sn[1] = ReadEEPROM[5];
netInfo.sn[2] = ReadEEPROM[6];
netInfo.sn[3] = ReadEEPROM[7];
netInfo.gw[0] = ReadEEPROM[8];
netInfo.gw[1] = ReadEEPROM[9];
netInfo.gw[2] = ReadEEPROM[10];
netInfo.gw[3] = ReadEEPROM[11];		
servip[0] = ReadEEPROM[12];
servip[1] = ReadEEPROM[13];
servip[2] = ReadEEPROM[14];
servip[3] = ReadEEPROM[15];
		
EEPROM24XX_Load(16,ReadEEPROM,4);
api_port = ((uint16_t)ReadEEPROM[0] << 8) | ReadEEPROM[1];
servport = ((uint16_t)ReadEEPROM[2] << 8) | ReadEEPROM[3];

Which problem with this? If i used only first 16 bytes all is ok. When i trying to fiil more pages i received data coruption in first page.

Example of writing to eeprom

Library does not fully support writing operation.
It is important to remember about switching WP (Write Protection) pin before call write function.

        _Bool status = false;
	status = EE24_Init(&eeprom24, &hi2c1, EE24_ADDRESS_DEFAULT);

	uint8_t data[4] = {0xBE, 0xEF, 0xAB, 0xCD};

	HAL_GPIO_WritePin(EEPROM_WP_GPIO_Port, EEPROM_WP_Pin, GPIO_PIN_RESET);
        status = EE24_Write(&eeprom24, 0u, &data, 4, 1000);
	HAL_GPIO_WritePin(EEPROM_WP_GPIO_Port, EEPROM_WP_Pin, GPIO_PIN_SET);

	memset(&data, 0u, sizeof(data));
	status = EE24_Read(&eeprom24, 0u, &data, 4, 1000);

The rest of library is ok. Simple and working library.
Thanks :D

Problem with writing more then 16 bytes.

Chipset: STM32F410
EEPROM Chip: EE24AT02 (EE24_2KBIT)

Problem occurs when try to write more than 16 bytes:
Code:

  for (uint32_t i = 0; i < 32; i ++) {
    EEPROM_DATA[i] = i;
  }
  if (EE24_Init(&ee24, &hi2c1, EE24_ADDRESS_DEFAULT))
  {
    EE24_Write(&ee24, 0, EEPROM_DATA, 32, 1000);
  }

Result:

10 11 12 13 14 15 16 17
18 19 1A 1B 1C 1D 1E 1F
10 11 12 13 14 15 16 17
18 19 1A 1B 1C 1D 1E 1F

While the correct result should be:

00 01 02 03 04 05 06 07
08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17
18 19 1A 1B 1C 1D 1E 1F

What might be the problem?

How Save/Load "uint32_t" variables?

Hi,
I try to save and load 32-bit variables as follows:

Write:

uint32_t rel_temp[48]={
	300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,
	300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,
	300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300
};
EEPROM24XX_Save(0x0000,(uint8_t *)rel_temp,(48*4));
//EEPROM24XX_Save(0x0000,(uint8_t *)&rel_temp,(48*4));

Read:

uint32_t rel_temp[48];
EEPROM24XX_Load(0x0000,(uint8_t *)rel_temp,(48*4));
//EEPROM24XX_Load(0x0000,(uint8_t *)&rel_temp,(48*4));

But it doesn't work!
Is there a way to do this?
I use this method in w25qxx library and it works well.
Thanks!

Lib not read or write value

Hi, i try this code

if (ee24_isConnected()) {
        uint8_t memory_ready = 111;
        ee24_write(0, &memory_ready, sizeof(memory_ready), 100);
        ee24_read(0, &memory_ready, sizeof(memory_ready), 100);
    }

after finish running code value of memory_ready is '0'.
But all function return is TRUE.

Please help.

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.