
Originally Posted by
MichaelMeissner
Given the error messages, I assume eeprom_read_block and eeprom_write_block need to be defined as C functions instead of C++, so you might try wrapping the two functions in extern "C" { ... }:
Sounds good. Did it.
Got some errors about conflicting with some existing eeprom_read_block functions in EEPROM.h and avr_functions.h. Namely this, BTW:
Code:
sketch_oct04a.ino: In function 'void eeprom_read_block(unsigned char*, int, int)':
sketch_oct04a:34: error: declaration of C function 'void eeprom_read_block(unsigned char*, int, int)' conflicts with
In file included from C:\Program Files (x86)\Arduino\libraries\EEPROM/EEPROM.h:26:0,
from sketch_oct04a.ino:1:
C:\Program Files (x86)\Arduino\hardware\teensy\cores\teensy3/avr_functions.h:45:6: error: previous declaration 'void eeprom_read_block(void*, const void*, uint32_t)' here
sketch_oct04a.ino: In function 'void eeprom_write_block(unsigned char*, int, int)':
sketch_oct04a:41: error: declaration of C function 'void eeprom_write_block(unsigned char*, int, int)' conflicts with
In file included from C:\Program Files (x86)\Arduino\libraries\EEPROM/EEPROM.h:26:0,
from sketch_oct04a.ino:1:
C:\Program Files (x86)\Arduino\hardware\teensy\cores\teensy3/avr_functions.h:50:6: error: previous declaration 'void eeprom_write_block(const void*, void*, uint32_t)' here
So, I just renamed the functions to eeprom_read_block2 and eeprom_write_block2.
Now, we are still having the exact same problem as all along. "eeprom_read_block2 / eeprom_write_block2 Not declared in this scope"
Here I've stripped out everything from the code except the EEPROM stuff. Maybe that will help to figure it out. I might just be doing something horribly obvious wrong. Here is the entire sketch.
Code:
#include <EEPROM.h>
// These are addresses into EEPROM memory. The values to be stores are floats which
// need 4 bytes each. Thus 0,4,8,12,...
#define PGAIN_ADR 0
#define IGAIN_ADR 4
#define DGAIN_ADR 8
void setup()
{
}
void loop()
{
}
float readFloat(int address) {
float out;
eeprom_read_block2((void *) &out, (unsigned char *) address ,4 );
return out;
}
void writeFloat(float value, int address) {
eeprom_write_block2((void *) &value, (unsigned char *) address ,4);
}
extern "C" {
void eeprom_read_block2(unsigned char *o, int a, int n)
{
for(int i = 0;i < n;i++) {
*o++ = EEPROM.read(a++);
}
}
void eeprom_write_block2(unsigned char *o, int a, int n)
{
for(int i = 0;i < n;i++) {
EEPROM.write(a++,*o++);
}
}
}