This may be a stupid question, but I'll ask it any way. Could not find the answer.
My code does compile but I have not gotten to the part where I can test it yet.
I have defined a structure and created an array of structures. It holds the configuration settings for my sensors. What determines the address within the atmega2560 eeprom in the code? Is it the "0" in (void*)0 ?
eeprom_read_block((void*)&systemConfiguration, (void*)0, sizeof(systemConfiguration));
eeprom_write_block((const void*)&systemConfiguration, (void*)0, sizeof(systemConfiguration));
The eeprom_read_block line is in the last part of setup().
My entire code (less the tabs) is:
/* This is the code for the Master Alarm Controller (MAC).
* atmega2560 with 4 hardware serial ports.
* structures do compile.
* Need to match the structures sensor nodes and remote interface panel (RIPs) nodes
* then need to test the code.
* added the EEPROM block writing and reading arrays of structures to the EEPROM
* NEED TO TEST ???not sure what controls the location in EEPROM
* see http://playground.arduino.cc/Code/EEPROMWriteAnything
*
* This code is for the mega2560
* It will use 3 serial ports. Serial. is for debug to the pc monitor terminal
* Serial1. is for RS485 comm with the sensors
* Serial2. is for RS485 comm with the remote control panels (RIPs)
* Serial3. light controls ????
*
*
*2015-12-27:
*comm with remote panels....structure to receive:
*panel unitID,
*unitID to change,
*parameter to change,
*type of change: silence alarm,
* cancel alarm,
* bypass unitID,
* min/max,
* mode: norm, day & night,
* save setup,
*
*
*/
#include <EEPROM.h>
//#include <EEPROMAnything.h>
#include <avr/eeprom.h>
#include <EasyTransfer.h>
//create 4 objects of EasyTransfer
EasyTransfer ET_RECV_SENSORS, ET_XMIT_SENSORS, XMIT_REM_PNLS, RECV_REM_PNLS;
#define ENABLE_XMIT_TO_SENSOR 7
#define MAX_TRIES_FOR_REPSONSE 3
#define MAX_WAIT_COUNT 1282 //1282 gives 10mSec time out.
#define NUMBER_OF_SENSORS 32 //EEPROM controls the max size
//an array of the structure systemConfiguration is saved in EEPROM. one structure is either 3 or 4 bytes.
//the atmega has 4096 bytes, so I could save data for up to 1000 sensors, but the RS485 is limited
//to 32 normal loads, or 128 1/4 loads.
enum sensorTypes {none, sonar,infraRed,simpleSwitch,lighting} type=none;
/* types of structures
* 1 struct for array of structures to save configuration to EEPROM
* 2 request info from sensor
* 3 receive info from sensor
* 4 request info from remote interface panel
* 5 receive info from remote interface panel
*/
// 1. define structure for eeprom array
typedef struct
{
/// byte unitID ; //this is also the index into the array of structures and index to mp3 files
//because this is the same as the index to the array we don't need it.
sensorTypes type; //not sure what the size of this is...may be a byte or an integer
byte minDistance;
byte maxDistance;
} eepromStructure;
eepromStructure systemConfiguration[NUMBER_OF_SENSORS]; //define an array of the setup for eeprom
// 2. define the structure for sensor status REQUEST
typedef struct
{
int buttonstate; //need to remove
int servoval; //need to remove
byte blinks; //need to remove
byte pause; //need to remove
byte unitID;
byte maxRange;
byte minRange;
} requestStatusStructure ;
requestStatusStructure requestFromSensor; // this is the actual structure to request status from sensors
// 3. define the structure for status returned from sensor
typedef struct
{
int buttonstate; //need to remove
byte unitID; //this is also the index into the array of structures
byte statusOnes;
byte statusZeros;
byte sensorError;
} statusStructure;
statusStructure receivedStatuses[NUMBER_OF_SENSORS]; //define an array of the status structure for all of the sensors
statusStructure receivedStatus; //this is the structure used for receiving status from the sensors
// 4. define the structure for request from remote interface panel (RIPs)
typedef struct
{
byte panelID; //address of the remote interface panel
byte unitID; //sensor address to change
byte maxRange; //maxRange for the Sonar sensor
byte minRange; //minRange for the Sonar sensor
} requestPanelStructure ;
requestPanelStructure requestFromRemotePanel; // this is the actual structure to request status from sensors
// 5. define the structure to receive info from remote interface panel (RIPs)
typedef struct
{
byte panelID; //address of the remote interface panel
byte unitID; //sensor address to change
byte maxRange; //maxRange for the Sonar sensor
byte minRange; //minRange for the Sonar sensor
int pnlSwitches; // this is the switch that is pressed on the RIP and may include:
// silence, cancel, bypass a sensor, day/night, continuous, saveConfiguration, audio on, audio off
} RecvPanelStructure ;
RecvPanelStructure recvFromRemotePanel; // this is the actual structure to receive info
// from remote interface panel
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup ++++++++++++++++++
void setup(){
Serial.begin (115200); //for serial debug
Serial1.begin(115200); //for sensor communication
Serial2.begin(115200); //for control panel communication
Serial3.begin(115200); // this may be used for controlling lighting
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET_XMIT_SENSORS.begin(details(requestFromSensor), &Serial1);//links data structure for XMITing request to Sensors
ET_RECV_SENSORS.begin(details(receivedStatus), &Serial1); //links data structure for RECVing info from Sensors
XMIT_REM_PNLS.begin(details(requestFromRemotePanel), &Serial2);
RECV_REM_PNLS.begin(details(recvFromRemotePanel), &Serial2);
pinMode(ENABLE_XMIT_TO_SENSOR,OUTPUT);
digitalWrite(ENABLE_XMIT_TO_SENSOR,LOW);
pinMode(13, OUTPUT);
pinMode(12, INPUT);
//enable pull-up
digitalWrite(12, HIGH);
//retrieve the saved setup values
eeprom_read_block((void*)&systemConfiguration, (void*)0, sizeof(systemConfiguration));
//next line is the code that will save the array of structures
// eeprom_write_block((const void*)&systemConfiguration, (void*)0, sizeof(systemConfiguration));
}//------------------------------------------------------------------------------------ end of setup ----------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ loop +++++++++++++++++++++++
void loop()
{
getStatus();
analyzeStatus();
checkRemotePanels();
checkLocalPanel();
delay(50);
}//----------------------------------------------------------------------------- end of loop -----------------------------------