Hi everybody,
I have a UNO and a datalogger shield(RTC and SD). I have this test program:
If I take off the unused C code the sd test works well, if i put the C code the SD is not detected.
The code for RTC works apart, but in this case it's not used.
Am I doing something wrong?
Thank you for help!
Best regards
Mauro Zanin
I have a UNO and a datalogger shield(RTC and SD). I have this test program:
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Dim timer1 As Timer
Dim y=2017,m=11,d=25,hh=13,mm=23,ss=00 As Int ' date and time fields with init time.
Dim rtcres As Boolean ' result of native code calls (true=OK)
Dim sd As SD
Public buffer(200) As Byte
Public raf As RandomAccessFile
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
sd.Initialize(10)
If sd.Exists("/")=False Then
Log("Nessuna scheda")
End If
For Each f As File In sd.ListFiles("/")
Log(f.Name, TAB, Round(f.Size / 1024), "kb", TAB, f.IsDirectory)
sd.OpenRead(f.name)
Log("Lunghezza:")
Log( sd.CurrentFile.Size)
sd.Stream.ReadBytes(buffer, 0, buffer.Length)
raf.CurrentPosition = 0
'read the data from the buffer
Log(buffer)
sd.close
Next
Log("Fine")
End Sub
#if C
#include <DS1307RTC.h>
#include <Time.h>
//#include <Wire.h>
#include <TimeLib.h>
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}
void setRTC(B4R::Object* bho)
{
tmElements_t tm;
int Hour, Min, Sec;
int Month;
int Day, Year;
//Serial.print("Start:");
// if (Month>12 || Month==0) return false;
tm.Hour = b4r_main::_hh;
tm.Minute = b4r_main::_mm;
tm.Second = b4r_main::_ss;
tm.Day = b4r_main::_d;
tm.Month = b4r_main::_m;
/*
Serial.print("Written Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(b4r_main::_y);
Serial.println();
*/
tm.Year = CalendarYrToTm(b4r_main::_y);
bool res=RTC.write(tm);
b4r_main::_rtcres=res;
return res;
}
void read(B4R::Object* unused) {
tmElements_t tm;
if (RTC.read(tm)) {
/*
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
*/
b4r_main::_hh=tm.Hour;
b4r_main::_mm=tm.Minute;
b4r_main::_ss=tm.Second;
b4r_main::_d=tm.Day;
b4r_main::_m=tm.Month;
b4r_main::_y=tmYearToCalendar(tm.Year);
b4r_main::_rtcres=true;
return true;
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Running SetTime");
Serial.println();
b4r_main::_rtcres=false;
return false;
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
b4r_main::_rtcres=false;
return false;
}
delay(9000);
}
delay(1000);
}
#end if
If I take off the unused C code the sd test works well, if i put the C code the SD is not detected.
The code for RTC works apart, but in this case it's not used.
Am I doing something wrong?
Thank you for help!
Best regards
Mauro Zanin