Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data not written on stm32f103c8t6? #23

Open
TecDroiD opened this issue Dec 10, 2023 · 11 comments
Open

data not written on stm32f103c8t6? #23

TecDroiD opened this issue Dec 10, 2023 · 11 comments

Comments

@TecDroiD
Copy link

Hi,

i'm currently trying to write and read a data structure into eeprom which looks basically like this

`
typedef struct s_machinecfg {
uint8_t version,
uint16_t datax,
uint16_t datay,
..
} t_machinecfg, *p_machinecfg;

typedef struct s_machine {
t_machinecfg config;
..
} t_machine, *p_machine;
...

void read_config() {
ee_read(0, sizeof(t_machinecfg), &self.config);
if (self.config.version != stdconfig.version) {
memcpy(&self.config, &std_config, sizeof(t_machinecfg));
write_config();
}
}
void write_config() {
ee_format(0);
ee_WriteToRAM(0, sizeof(t_machinecfg), &self.config);
ee_commit();
}

...
t_machine machine;

ee_init();
read_config();

`

later, I want to alter some values in my configuration and save it using write_config() but every time I restart the controller, I get the unaltered data. If I change my stdconfig in the program, former data is displayed, so first write must work.. but why doesn't the second one do?

Do you have any idea what my problem could be?

my eeConfig.h looks this way:
`
#ifndef __EECONFIG_H
#define __EECONFIG_H

#define _EE_USE_FLASH_PAGE_OR_SECTOR (63)
#define _EE_USE_RAM_BYTE (1024)
#define _EE_VOLTAGE FLASH_VOLTAGE_RANGE_3 // use in some devices
#endif
`

@nimaltd
Copy link
Owner

nimaltd commented Dec 12, 2023

hi. because you should not use format

@TecDroiD
Copy link
Author

Well I just tried format it didn't work before. Removed format now but same effect.

@nimaltd
Copy link
Owner

nimaltd commented Dec 13, 2023

And remove
if (self.config.version != stdconfig.version) {
memcpy(&self.config, &std_config, sizeof(t_machinecfg));
And try again. And debug step by step to see what is happening. It seems ok.

@TecDroiD
Copy link
Author

TecDroiD commented Dec 13, 2023

i debugged without my autowrite mechanics and it seems that after reading the first byte is 0 instead 0x10..

@nimaltd
Copy link
Owner

nimaltd commented Dec 13, 2023

Let me a while to check.

@nimaltd
Copy link
Owner

nimaltd commented Dec 13, 2023

@TecDroiD I have updated "ee.c". please check again and tell me the result. thanks

@nimaltd
Copy link
Owner

nimaltd commented Dec 16, 2023

did you check? @TecDroiD

@TecDroiD
Copy link
Author

sorry, was off for a few days. first short experiment doesn't look promising but I promise to do a complete debug today.

@TecDroiD
Copy link
Author

someone broke my blue pill. got a new one now.. and I cleaned the project twice between several debuggings and now it seems to work using uint8_t as first entry in my struct.
may I ask a stupid question? in ee_read you do read the data using *data = ... and increase the pointer after. then you write to ram buffer using ee_ram[i]. Is there any reason I can't see why you didn't use data[i], too?

@nimaltd
Copy link
Owner

nimaltd commented Dec 23, 2023

I am so glad it works. no reason :)

@nimaltd
Copy link
Owner

nimaltd commented Mar 28, 2024

I have updated the LIB. please try again for any devices you have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants