I am trying to save data that has been received over SPI. The data is converted to a static character string using dtostrf and saved to EEPROM via EEPROM.put. The program fails to compile with this error
"expected primary-expression before 'static' prev_h = EEPROM.get(0, static char);"
I dont really understand what this is asking me to change. My code can be seen below. Thank you
/* Slave */
#include <SPI.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
byte storage [8];
volatile byte pos;
volatile boolean process;
float buff[2];
static char bufout[16];
static char prev_h;
static char prev_t;
int write_count = 1;
void setup()
{
lcd.begin(16, 2);
lcd.clear();
prev_h = EEPROM.get(0, static char);
prev_t = EEPROM.get(1, static char);
pinMode(MISO,OUTPUT);
SPCR |= _BV(SPE);
SPCR |= _BV(SPIE);
pos = 0;
process = false;
Serial.begin(9600);
}
ISR(SPI_STC_vect)
{
byte gathered = SPDR;
if( pos < sizeof storage)
{
storage[pos++] = gathered;
}
else
process = true;
}
void loop()
{
if((write_count == 1) && (prev_h <= 0)) { // If no writes have been made and no previous readings (SPDR <= 0) && (prev_h <= 0) (millis() < 1500)
lcd.setCursor(0,0);
lcd.print("Initiating");
delay(375);
lcd.print(".");
delay(375);
lcd.print(".");
delay(375);
lcd.print(".");
delay(375);
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(11,0);
lcd.print(" ");
lcd.setCursor(12,0);
lcd.print(" ");
lcd.clear();
}
if((write_count == 1) && (prev_h > 0)){ // IF nothing in SPI data register and there IS previous readings
lcd.setCursor(0,0);
lcd.print("Prev Humid = ");
lcd.print(prev_h);
lcd.setCursor(0,1);
lcd.print("Prev Temp = ");
lcd.print(prev_t);
lcd.clear();
}
if( process ) // IF something has appeared in SPI data register
{
memcpy(buff,&storage,8);
dtostrf(buff[0],3, 0, bufout);
lcd.setCursor(0,0);
lcd.print("Humidity = ");
lcd.print(bufout);
lcd.print(" %");
write_count++;
EEPROM.put(0, bufout);
Serial.print(write_count);
storage[pos] = 0;
pos = 0;
process = false;
delay(1000);
memcpy(buff,&storage,8);
dtostrf(buff[0],3, 0, bufout);
lcd.setCursor(0,1);
lcd.print("Temp = ");
lcd.print(bufout);
lcd.print((char)223);
lcd.print("C");
write_count++;
EEPROM.put(1, bufout);
Serial.print(write_count);
storage[pos] = 0;
pos = 0;
process = false;
delay(1000);
}code here
Sorry I understand i should put my actual variable names there now but this is still not working. When i run the code with prev_h and prev_t where i previously had "static char" my LCD's text looks as though it is flickering and is also not displaying the data only "Prev Humidity =" and "Prev Temp = "
Thank you for your responses. Below is my master code. My intention is to have EEPROM.GET return the value from the previous reading of a DHT11 sensor. It currently returns nothing within the serial monitor. prev_h i have declared as a static char as that is the same type as bufout which is a string containing the data converted from the float that is transfered over SPI using dtostrf. I do this so i can display the value on the LCD.
it does work. see example just above. (if you use a parameter to pass the array to a save function, then your parameter has decayed into a pointer and then of course you end up saving the value of the pointer...)
I'll have to look at the source code for EEPROM put and get, it is not obvious how those determine the size of the arrays, particularly when not using a null terminated char array.
It is pretty obvious - they simply call sizeof to know how many bytes the variable needs to be represented.
that's why it does not work with a decayed array (the variable is just a pointer and thus sizeof will be the size of a pointer), but if your array is a global then there is no problem.
cStrings are not dealt with in a specific way, all the bytes are written like other arrays, regardless of the presence or not of an '\0'. (so you have to be sure of what you play with)