Sorry to be a pain, but I ran into another problem. I can write to eeprom with the codes below without any problem but I am having a difficulty reading it and use for authentication:
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #define read_eeprom_byte(address) eeprom_read_byte ((const uint8_t*)address) //any other way to do this other than declare?
#define write_eeprom_byte(address,value) eeprom_update_byte ((uint8_t*)address,(uint8_t)value) //this as well?
static char passcode[10] = "secret" //default password
static char EEMEM e_passcode[10];
static char EEMEM e_passcode_check_byte;
uint8_t verify_password(char *str)
{
if (strncmp(passcode,str,strlen(passcode))==0){
return(1);
}
return(0);
}
void eeprom_set_newpasscode(char *pass)
{
uint8_t c=1;
write_eeprom_byte(&e_passcode_check_byte,c);
eeprom_update_block((void *)pass,(void *)e_passcode,sizeof(pass));
}
void eeprom_get_newpasscode(void)
{
char c[10];
if(read_eeprom_byte(&e_passcode_check_byte)==1){
eeprom_read_block((void *)c,(void *)e_passcode,sizeof(c));
return(c);
}
}
//inside main
char newpass[10] = "test";
eeprom_set_newpasscode(newpass);
passcode = eeprom_get_newpasscode(); //set the new passcode from eeprom to passcode |
This code won't compile with this error message:
avr-gcc -g -mmcu=atmega328p -Wall -W -Os -mcall-prologues -I. -Os -c main.c
In file included from main.c:19:0:
ip_arp_udp_tcp.h:46:1: warning: 'prog_char' is deprecated: prog_char type is deprecated. [-Wdeprecated-declarations]
main.c:74:1: warning: 'prog_char' is deprecated: prog_char type is deprecated. [-Wdeprecated-declarations]
main.c: In function 'eeprom_get_newpasscode':
main.c:119:9: warning: 'return' with a value, in function returning void [enabled by default]
main.c: In function 'main':
main.c:307:7: error: void value not ignored as it ought to be
make: *** [main.o] Error 1
I tried changing the function from void to char
Code C - [expand] |
1
2
3
4
5
6
7
8
| char eeprom_get_newpasscode(void)
{
char c[10];
if(read_eeprom_byte(&e_passcode_check_byte)==1){
eeprom_read_block((void *)c,(void *)e_passcode,sizeof(c));
return(c);
}
} |
and here is the error message that I got:
avr-gcc -g -mmcu=atmega328p -Wall -W -Os -mcall-prologues -I. -Os -c main.c
In file included from main.c:19:0:
ip_arp_udp_tcp.h:46:1: warning: 'prog_char' is deprecated: prog_char type is deprecated. [-Wdeprecated-declarations]
main.c:74:1: warning: 'prog_char' is deprecated: prog_char type is deprecated. [-Wdeprecated-declarations]
main.c: In function 'eeprom_get_newpasscode':
main.c:119:9: warning: return makes integer from pointer without a cast [enabled by default]
main.c:119:9: warning: function returns address of local variable [enabled by default]
main.c: In function 'main':
main.c:307:7: error: incompatible types when assigning to type 'char[10]' from type 'char'
main.c: In function 'eeprom_get_newpasscode':
main.c:121:1: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [main.o] Error 1
I only wanted to be able to save a new passcode to eeprom. If the new passcode is set, use it, if not use the default.
Thanks again and sorry for testing your patience.