Go Down

Topic: EEPROM overwite previous data? (Read 8967 times) previous topic - next topic

CrossRoads

Well, we're in slow summer period right now (late July-August), classes start up again Sept 6, I will probably around much less then!

The sketch works, I will be using it as additional test for checking out Bobuino's.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

I am still getting oã1?.}¢bz?ÿlc1?.}¢bz?ÿlc1dÞ~¢c{?ÿ  when I switch on.

I set my port 27 that I am using to 57600.

Where does the F0xx   E0xx C0xx  come from ?
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

port 27? Wow, I hadn't seen above 15.
Is that going to the IDE Serial Monitor or something else?
F012, etc are numbers you send to the serial port.
From the IDE Serial port, you type in F004, Enter, for instance to set the Seconds to 4

Does the stuff you see come out every 5 seconds?
I can send you a screen shot of it running when I get up in a few hours, so I am pretty sure it is something on your end.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

I have 2 Arduinos, one runs on port13 and the other on 27, which is handy when I have them both on for wireless/data links.

I have drawn out ( my printer died yesterday ) the memory map of the 1307, and the addresses for each byte say 00H  to 07H, so I was wondering where the F and E and C  come from?

Yes the symbols appear in short bursts every 5 seconds.

Its definitely something my end :-)  I am going groggy with all this, and have had about 8 hours sleep since Wednesday, so I think I might do some assembly and give my mind a break !  I have 3 projects on the go at once suddenly !
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

The F, E, and C were added as command discriminators, so I could enter F037 for instance, the software breaks it down as:
F, writing to a Register,
0, register to write to,
3, upper nibble of data to write,
7, lower nibble of data to write,
Then put the 3 & 7 together into 0x37,
and send out via the I2C
0x68, the DS1307 address
0x00, the register
0x37, the data

I then read back the first 8 registers as a group.

C, as in C0 to C7, was going to be used to read a register.
E, as in E008 to E03F , was going to be used to read a RAM address.
I just haven't written them.

Made it easy to enter any value manually for testing, and with reading all 8 back at once and displaying I could see that it was accepted.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

Right,  slept on it and decided to run it slower ( I have a somewhat suspect usb connection sometimes ) so I changed it to 9600 and it works !

Now I shall try modifying it for my project  Thanks again !
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

I am getting really confused ,  all I need to do is use the days, months and years from the RTC date  = " currdate"  and 4 bytes of data from the ram ( 07H - 0AH ) ?  of the DS1307.

I think I can do all the manipulation, but then I want to occasionally write the updated data to the 4 bytes,  without disturbing the preset time .

I cant believe how  I am struggling with this  !  Anybody got a working simple sketch that I can modify?

45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

John,
These 3 chunks of code should do what you want, add these to the pre- void setup () area.

Code: [Select]

byte RAM0 = 0;
byte RAM1 = 0;
byte RAM2 = 0;
byte RAM3 = 0;

Code: [Select]

// ****************************************
// Read the day of month, month, year
  // Reset the register pointer  
   Wire.beginTransmission(RTC_address);  
   Wire.send(0x04);  // to day of the month
   Wire.endTransmission();  

   Wire.requestFrom(RTC_address,3 );  
//   seconds = Wire.receive();  
//   minutes = Wire.receive();  
//   hours = Wire.receive();  
//   day_week = Wire.receive();  
   date_month = Wire.receive(); // sends back this  
   month = Wire.receive();  // and this
   year = Wire.receive();   // and this
 //  sqwe = Wire.receive();

Code: [Select]

// **********************************************************************
// Read the first 4 bytes of RAM
   // Reset the register pointer  
   Wire.beginTransmission(RTC_address);  
   Wire.send(0x08);  // to start of RAM
   Wire.endTransmission();  

   Wire.requestFrom(RTC_address,4 );  // Read back first four RAM addresses
  RAM0 = Wire.receive(); // or whatever you decide to the data
  RAM1 = Wire.receive();
  RAM2 = Wire.receive();
  RAM3 = Wire.receive();  

Code: [Select]


// ****************************************************************************
// Write the first 4 bytes of RAM
  // Reset the register pointer  
   Wire.beginTransmission(RTC_address);  
   Wire.send(0x08);  // to start of RAM
   Wire.send (RAM0); // or whatver you decide to call the data
   Wire.send (RAM1);
   Wire.send (RAM2);
   Wire.send (RAM3);
   Wire.endTransmission();  
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

#24
Aug 14, 2011, 07:25 pm Last Edit: Aug 14, 2011, 07:30 pm by Boffin1 Reason: 1
Thanks Bob,  I can actually understand most of that !!!

I will be using it in a stand alone board, so the keyboard shortcuts were getting me confused.

Which parts go before set-up and which in loop ?
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Only the variable definitions go before setup, the rest goes where ever you'r going to use it.
Maybe do the current time read and the RAM read once in setup, decide if you need to do store something there before getting into loop?

Then use, re-use the rest in loop as you need it.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

#26
Aug 14, 2011, 08:30 pm Last Edit: Aug 14, 2011, 08:34 pm by Boffin1 Reason: 1
Thanks, yes I got it going like that, now I am doing my manipulations ( and seem to have reset everything to 0 but it doesnt matter, its actually coming right at last !

Code: [Select]


#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
byte    date_month;
byte    month ;
byte    year;
byte prevdate ;
byte prevmonth ;
byte prevyear ;
byte prevbest ;

int trigger = 7;

void setup () {

  Wire.begin(); // no address, we are master
 Serial.begin (9600);  
pinMode ( trigger, INPUT );
digitalWrite ( trigger, HIGH);   //   sets pin 7 as trigger with pullup

//                                        update real time at bootup Read the day of month, month, year
  // Reset the register pointer  
   Wire.beginTransmission(0x68);  
   Wire.send(0x04);  // to day of the month
   Wire.endTransmission();  

   Wire.requestFrom(0x68,3 );  
//   seconds = Wire.receive();  
//   minutes = Wire.receive();  
//   hours = Wire.receive();  
//   day_week = Wire.receive();  
   date_month = Wire.receive(); // sends back current month  
   month = Wire.receive();  // and this
   year = Wire.receive();   // and this
 //  sqwe = Wire.receive();

  Serial.print ("bootup date_month " );
   Serial.println (date_month, HEX);
      Serial.print ("bootup month " );
   Serial.println (month, HEX);
      Serial.print ("bootup year " );
   Serial.println (year, HEX);

}

void loop () {
// ****************************************

if ( trigger == LOW ) { checkdate () ;}

// **********************************************************************
// Read the first 4 bytes of RAM
   // Reset the register pointer  
   Wire.beginTransmission(0x68);  
   Wire.send(0x08);  // to start of RAM
   Wire.endTransmission();  

   Wire.requestFrom(0x68,4 );  // Read back first four RAM addresses
 prevdate = Wire.receive(); // or whatever you decide to the data
 prevmonth = Wire.receive();
 prevyear= Wire.receive();
 prevbest = Wire.receive();  

Serial.print ("prev date " );
   Serial.println (prevdate, HEX);
      Serial.print ("prev month " );
   Serial.println (prevmonth, HEX);
      Serial.print ("prev year year " );
   Serial.println (prevyear, HEX);

Serial.print ("prev best " );
   Serial.println (prevbest, HEX);
// ****************************************************************************
// Write the first 4 bytes of RAM
  // Reset the register pointer  
   Wire.beginTransmission(0x68);  
   Wire.send(0x08);  // to start of RAM
   Wire.send (prevdate); // or whatver you decide to call the data
   Wire.send (prevmonth);
   Wire.send (prevyear);
   Wire.send (prevbest);
   Wire.endTransmission();
   
} // end loop

void checkdate () {
 
 // Read the day of month, month, year
  // Reset the register pointer  
   Wire.beginTransmission(0x68);  
   Wire.send(0x04);  // to day of the month
   Wire.endTransmission();  

   Wire.requestFrom(0x68,3 );  

   date_month = Wire.receive(); // sends back current month  
   month = Wire.receive();  // and this
   year = Wire.receive();   // and this


  Serial.print ("todays date_month " );
   Serial.println (date_month, HEX);
      Serial.print ("todays month " );
   Serial.println (month, HEX);
      Serial.print ("todays year " );
   Serial.println (year, HEX);
}  // end checkdate function


45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

John_Smith

#28
Aug 15, 2011, 12:35 am Last Edit: Aug 15, 2011, 12:38 am by Boffin1 Reason: 1
OK I have my event logger basically running, but I now have to calculate the number of days since the last event. ( max 99 )

Without using a lookup table for months days and leap years etc, if I can find how to convert the previous event date to unix time, I could simply subtract it from the current unix time to give me elapsed seconds, and divide by 60*60*24

I can get the current unix time with the time.h library with time_t now() , but I cannot see how to give it another date to calculate from?

Any ideas ?

I could go back to my original idea of splitting the unix code for the previous event, into bytes and saving them in the RTC ram, but its a big number ( 10 digits decimal )
45 years of editing projects with a knife and soldering iron, then I found Arduino !

CrossRoads

Look in the time.h library and see how it calculates, then mimic that.

Or, when you get current time to store it as the previous time, then request unix time also (instead?) and store that also (instead?)
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up