The DS3232RTC can be fixed with some patching:
Copy pgmspace.h to:
C:\Program Files (x86)\Arduino\hardware\aurduino\aurix\cores\aurduino\avr
and;
C:\Program Files (x86)\Arduino\hardware\aurduino_Dx\aurix\cores\aurduino\avr
We will include this in the next release.
TimeLib is trickier. There is a definition of "now()" in the Time-Master library which clashes with an existing definition or "now()" in the ShieldBuddy runtime library. The quick fix is to rename the now() in TimeLib.h and Time.c to TimeLibnow().
Finally, the RTC class needs to be manually instantiated in the sketch:
DS3232RTC RTC; // instantiate an RTC object manually on ShieldBuddy
It should now build but we cannot test if it will run properly.
I moved to just the example from the DS3232 rtc library that just sets the time via the terminal since my main program has so many other errors. I can confirm that it does not work even after the changes will put my logic anyalyzer on it later to see what it is sending to the chip
I did manage to get some readings from the ds3232 but there still seems to be issues with it. I have a sketch reading it and a BMP180 pressure sensor as a test and i noticed that on the DS3232 the time and date seem to just change to random date and times every time they are read in. The BMP180 sensor is also getting incorrect values on the reads. What seems interesting is that despite the fact the time and date is wrong the DS3232 seems to give me perfect readings on the temperature (a float variable) where as the doubles in the BMP180 sensor all seem to be wrong readings. The I2C bus looks good on the scope and i can see the commands being sent. Ignore the SPI stuff in the code i am starting to test that function as well so i am just using this sketch for the testing until i get the I2C working.
/*** Don't worry, the normal Arduino setup() and loop() are below this block! ***/
/* LMU uninitialised data */
StartOfUninitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have no initial values here e.g. uint32 LMU_var; */
EndOfUninitialised_LMURam_Variables
/* LMU uninitialised data */
StartOfInitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have an initial value here e.g. uint32 LMU_var_init = 1; */
EndOfInitialised_LMURam_Variables
/* If you do not care where variables end up, declare them here! */
// Arduino DS3232RTC Library
// https://github.com/JChristensen/DS3232RTC
// Copyright (C) 2018 by Jack Christensen and licensed under
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//
// Example sketch to display the date and time from a DS3231
// or DS3232 RTC every second. Display the temperature once per
// minute. (The DS3231 does a temperature conversion once every
// 64 seconds. This is also the default for the DS3232.)
//
// Set the date and time by entering the following on the Arduino
// SerialASC monitor:
// year,month,day,hour,minute,second,
//
// Where
// year can be two or four digits,
// month is 1-12,
// day is 1-31,
// hour is 0-23, and
// minute and second are 0-59.
//
// Entering the final comma delimiter (after "second") will avoid a
// one-second timeout and will allow the RTC to be set more accurately.
//
// No validity checking is done, invalid values or incomplete syntax
// in the input will result in an incorrect RTC setting.
//
// Jack Christensen 08Aug2013
#include "Wstring.h"
#include "Wcharacter.h"
#include <DS3232RTC.h> // https://github.com/JChristensen/DS3232RTC
#include <Streaming.h> // http://arduiniana.org/libraries/streaming/
#include <SFE_BMP180.h>
#include <Wire.h>
#include "Spi_Illd.h"
const uint8_t CAN_CS = 49; // SMART LCD SD
const uint8_t INET_CS = 47; // SMART LCD SD A15
const uint8_t SD2_CS = 48; // INET SHIELD SD
uint8_t RxData8 = 0;
uint8_t TxData8 = 0;
const uint8_t MAX31865_CS_0 = 44; //
const uint8_t MAX31865_CS_1 = 45; //
const uint8_t SD1_CS = 43;
#define ALTITUDE 180.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
/*** Core 0 ***/
SFE_BMP180 pressure;
DS3232RTC RTC; // instantiate an RTC object manually on ShieldBuddy
void setup() {
// put your setup code for core 0 here, to run once:
// Initialise the SPI
SoftSPi_CS_SpiInit(SD2_CS);
//pinMode(INET_CS, OUTPUT);
//pinMode(CAN_CS, OUTPUT);
disable_all_cs();
//
// delay(300);
// // Make an SPI transaction
// RxData8 = SoftSPi_CS_Spi_Transfer(SD2_CS, TxData8, SPIx_LAST);
// delay(50);
// RxData8 = SoftSPi_CS_Spi_Transfer(INET_CS, TxData8, SPIx_LAST);
// delay(50);
// RxData8 = SoftSPi_CS_Spi_Transfer(CAN_CS, TxData8, SPIx_LAST);
// delay(50);
Wire.setWirePins(UsePins_SDA1_SCL1);
// Wire.begin();
SerialASC.begin(115200);
if (pressure.begin())
SerialASC.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.
SerialASC.println("BMP180 init fail\n\n");
while(1); // Pause forever.
}
// setSyncProvider() causes the Time library to synchronize with the
// external RTC by calling RTC.get() every five minutes by default.
setSyncProvider(RTC.get);
SerialASC << F("RTC Sync");
if (timeStatus() != timeSet) SerialASC.println(" FAIL!");
SerialASC.println();
}
void loop() {
// put your main code for core 0 here, to run repeatedly:
static time_t tLast;
time_t t;
tmElements_t tm;
// check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
if (SerialASC.available() >= 12) {
// note that the tmElements_t Year member is an offset from 1970,
// but the RTC wants the last two digits of the calendar year.
// use the convenience macros from the Time Library to do the conversions.
int y = SerialASC.parseInt();
if (y >= 100 && y < 1000)
SerialASC << F("Error: Year must be two digits or four digits!") << endl;
else {
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else // (y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = SerialASC.parseInt();
tm.Day = SerialASC.parseInt();
tm.Hour = SerialASC.parseInt();
tm.Minute = SerialASC.parseInt();
tm.Second = SerialASC.parseInt();
t = makeTime(tm);
RTC.set(t); // use the time_t value to ensure correct weekday is set
setTime(t);
SerialASC << F("RTC set to: ");
printDateTime(t);
SerialASC << endl;
// dump any extraneous input
while (SerialASC.available() > 0) SerialASC.read();
}
}
t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
if (second(t) == 0) {
float c = RTC.temperature() / 4.;
float f = c * 9. / 5. + 32.;
SerialASC << F(" ") << c << F(" C ") << f << F(" F");
}
SerialASC << endl;
}
char status;
double T,P,p0,a;
// Loop here getting pressure readings every 10 seconds.
// If you want sea-level-compensated pressure, as used in weather reports,
// you will need to know the altitude at which your measurements are taken.
// We're using a constant called ALTITUDE in this sketch:
SerialASC.println();
SerialASC.print("provided altitude: ");
SerialASC.print(ALTITUDE,0);
SerialASC.print(" meters, ");
SerialASC.print(ALTITUDE*3.28084,0);
SerialASC.println(" feet");
// If you want to measure altitude, and not pressure, you will instead need
// to provide a known baseline pressure. This is shown at the end of the sketch.
// You must first get a temperature measurement to perform a pressure reading.
// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
SerialASC.print("temperature: ");
SerialASC.print(T,2);
SerialASC.print(" deg C, ");
SerialASC.print((9.0/5.0)*T+32.0,2);
SerialASC.println(" deg F");
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
SerialASC.print("absolute pressure: ");
SerialASC.print(P,2);
SerialASC.print(" mb, ");
SerialASC.print(P*0.0295333727,2);
SerialASC.println(" inHg");
// The pressure sensor returns abolute pressure, which varies with altitude.
// To remove the effects of altitude, use the sealevel function and your current altitude.
// This number is commonly used in weather reports.
// Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
// Result: p0 = sea-level compensated pressure in mb
p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
SerialASC.print("relative (sea-level) pressure: ");
SerialASC.print(p0,2);
SerialASC.print(" mb, ");
SerialASC.print(p0*0.0295333727,2);
SerialASC.println(" inHg");
// On the other hand, if you want to determine your altitude from the pressure reading,
// use the altitude function along with a baseline pressure (sea-level or other).
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
// Result: a = altitude in m.
a = pressure.altitude(P,p0);
SerialASC.print("computed altitude: ");
SerialASC.print(a,0);
SerialASC.print(" meters, ");
SerialASC.print(a*3.28084,0);
SerialASC.println(" feet");
}
else SerialASC.println("error retrieving pressure measurement\n");
}
else SerialASC.println("error starting pressure measurement\n");
}
else SerialASC.println("error retrieving temperature measurement\n");
}
else SerialASC.println("error starting temperature measurement\n");
SerialASC.println();
printDateTime(t);
float c = RTC.temperature() / 4.;
float f = c * 9. / 5. + 32.;
SerialASC << F(" ") << c << F(" C ") << f << F(" F");
SerialASC.println();
delay(5000);
SerialASC.println();
}
// print date and time to SerialASC
void printDateTime(time_t t)
{
printDate(t);
SerialASC << ' ';
printTime(t);
}
// print time to SerialASC
void printTime(time_t t)
{
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}
// print date to SerialASC
void printDate(time_t t)
{
printI00(day(t), 0);
SerialASC << monthShortStr(month(t)) << _DEC(year(t));
}
// Print an integer in "00" format (with leading zero),
// followed by a delimiter character to SerialASC.
// Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) SerialASC << '0';
SerialASC << _DEC(val);
if (delim > 0) SerialASC << delim;
return;
}
/*** Core 1 ***/
/* CPU1 Uninitialised Data */
StartOfUninitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have no initial values here e.g. uint32 CPU1_var; */
EndOfUninitialised_CPU1_Variables
/* CPU1 Initialised Data */
StartOfInitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have an initial value here e.g. uint32 CPU1_var_init = 1; */
EndOfInitialised_CPU1_Variables
void setup1() {
// put your setup code for core 1 here, to run once:
}
void loop1() {
// put your main code for core 1 here, to run repeatedly:
}
/*** Core 2 ***/
/* CPU2 Uninitialised Data */
StartOfUninitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have no initial values here e.g. uint32 CPU2_var; */
EndOfUninitialised_CPU2_Variables
/* CPU2 Initialised Data */
StartOfInitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have an initial value here e.g. uint32 CPU2_var_init = 1; */
EndOfInitialised_CPU2_Variables
void setup2() {
// put your setup code for core 2 here, to run once:
}
void loop2() {
// put your main code for core 2 here, to run repeatedly:
}
// SPI CHIP SELECT ROUTINES
void disable_sd1_cs(){
// disable sd1 TFT_LCD SD 53
pinMode(SD1_CS, OUTPUT);
digitalWrite(SD1_CS, HIGH);
}
void disable_sd2_cs(){
// disable sd2 CTE/TFT SHIELD SD 48
pinMode(SD2_CS, OUTPUT);
digitalWrite(SD2_CS, HIGH);
}
void disable_inet_cs(){
// disable sd3 SMART LCD SD A15
pinMode(INET_CS, OUTPUT);
digitalWrite(INET_CS, HIGH);
}
void MAX31865_CS0 (){
pinMode(MAX31865_CS_0, OUTPUT);
digitalWrite(MAX31865_CS_0, HIGH);
}
void MAX31865_CS1 (){
pinMode(MAX31865_CS_1, OUTPUT);
digitalWrite(MAX31865_CS_1, HIGH);
}
void disable_all_cs(){
disable_sd1_cs();
disable_sd2_cs();
disable_inet_cs();
MAX31865_CS0 ();
MAX31865_CS1 ();
}
13:40:49.481 -> BMP180 init success
13:40:49.481 -> RTC Sync
13:40:49.481 -> 19Jan1970 12:38:19
13:40:49.481 ->
13:40:49.481 -> provided altitude: 180 meters, 591 feet
13:40:49.481 -> temperature: 116.72 deg C, 242.10 deg F
13:40:49.481 -> absolute pressure: -1332.72 mb, -39.36 inHg
13:40:49.515 -> relative (sea-level) pressure: -1361.52 mb, -40.21 inHg
13:40:49.515 -> computed altitude: 180 meters, 591 feet
13:40:49.515 ->
13:40:49.515 -> 19Jan1970 12:38:19 24.00 C 75.20 F
13:40:54.529 ->
13:40:54.529 -> 30Jan1986 18:07:48
13:40:54.529 ->
13:40:54.529 -> provided altitude: 180 meters, 591 feet
13:40:54.529 -> temperature: 116.74 deg C, 242.13 deg F
13:40:54.563 -> absolute pressure: -1332.97 mb, -39.37 inHg
13:40:54.563 -> relative (sea-level) pressure: -1361.78 mb, -40.22 inHg
13:40:54.563 -> computed altitude: 180 meters, 591 feet
13:40:54.563 ->
13:40:54.563 -> 30Jan1986 18:07:48 23.75 C 74.75 F
13:40:59.577 ->
13:40:59.577 -> 10Feb2002 23:32:49
13:40:59.577 ->
13:40:59.577 -> provided altitude: 180 meters, 591 feet
13:40:59.577 -> temperature: 116.75 deg C, 242.16 deg F
13:40:59.645 -> absolute pressure: -1333.09 mb, -39.37 inHg
13:40:59.645 -> relative (sea-level) pressure: -1361.90 mb, -40.22 inHg
13:40:59.645 -> computed altitude: 180 meters, 591 feet
13:40:59.645 ->
13:40:59.645 -> 10Feb2002 23:32:49 23.75 C 74.75 F
13:41:04.631 ->
13:41:04.631 -> 22Feb2018 04:57:37
13:41:04.631 ->
13:41:04.631 -> provided altitude: 180 meters, 591 feet
13:41:04.631 -> temperature: 116.76 deg C, 242.16 deg F
13:41:04.699 -> absolute pressure: -1333.17 mb, -39.37 inHg
13:41:04.699 -> relative (sea-level) pressure: -1361.98 mb, -40.22 inHg
13:41:04.699 -> computed altitude: 180 meters, 591 feet
13:41:04.699 ->
13:41:04.699 -> 22Feb2018 04:57:37 24.00 C 75.20 F
13:41:09.683 ->
13:41:09.683 -> 05Mar2034 10:22:38
13:41:09.683 ->
13:41:09.683 -> provided altitude: 180 meters, 591 feet
13:41:09.683 -> temperature: 116.76 deg C, 242.16 deg F
13:41:09.751 -> absolute pressure: -1333.11 mb, -39.37 inHg
13:41:09.751 -> relative (sea-level) pressure: -1361.92 mb, -40.22 inHg
13:41:09.751 -> computed altitude: 180 meters, 591 feet
If i enter a string as it should work like 2019,10,15,15,00,00, this should set the time but what is does is lock up the shieldbuddy completely requiring a reset. I assume there are changes to serial input routines between mega2560 and shieldbuddy.