Hi!
I can't find information anywhere on this.
This sketch compiles ok if i choose target Mega1280.
Now i have a 2560 that i would like to use but if i select Mega2560 as target, the compiler throws an error:
/usr/lib/gcc/avr/4.7.0/../../../avr/lib/avr6/crtm2560.o: In function __bad_interrupt': ../../../../crt1/gcrt1.S:195: relocation truncated to fit: R_AVR_13_PCREL against symbol
__vector_45' defined in .text section in /usr/lib/gcc/avr/4.7.0/../../../avr/lib/avr6/crtm2560.o
collect2: error: ld returned 1 exit status
Another !funny effect is that if i comment out certain lines (344, 350 or 367), it compiles ok.
This minimized sketch really doesnt do a lot besides reporting free RAM, reading a DS1820 temp sensor, accessing a SD card and clears the TFT screen.
It has the UTFT and UTouch libs loaded.
Anyone experienced user who has a clue of what's going on?
Sketch below:
#include <UTFT.h>
#include <UTouch.h>
#include <stdlib.h>
#include <OneWire.h>
#include <MemoryFree.h>
#include <SD.h>
File myFile;
#include <DallasTemperature.h>
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(9);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Declare which fonts we will be using
extern uint8_t BigFont[];
// Uncomment the next two lines for the Arduino 2009/UNO
//UTFT myGLCD(ITDB24D,19,18,17,16); // Remember to change the model parameter to suit your display module!
//UTouch myTouch(15,10,14,9,8);
// Uncomment the next two lines for the Arduino Mega
UTFT myGLCD(ITDB32S, 38,39,40,41); // Remember to change the model parameter to suit your display module!
UTouch myTouch(6,5,4,3,2);
int x, y, z, zz;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";
char SdFnCA[7],SdDataCA[99];
float TempC;//celsius, fahrenheit;
int MaxSettings=1; //--------------------------------
String sSett[9],sSettIni[9];
String spc20=" ";
int SettItem=0;
float fSett[9];
long zt;
String S,SdData, SdFn;
String sAppName,sAppVer,sAppNameUC;
void SdInit()
{
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(53, OUTPUT);
if (!SD.begin(53)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
}
void SdSave()
{
SdData.toCharArray(SdDataCA, 99);
SdFn.toCharArray(SdFnCA, 15);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
SD.remove(SdFnCA);
myFile = SD.open(SdFnCA, FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to ");
Serial.println(SdFnCA);
Serial.print("Data:");
Serial.println(SdDataCA);
myFile.println(SdDataCA);
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void SdLoad()
{
char CZ;
int i=0;
//SdData.toCharArray(SdDataCA, 99);
SdFn.toCharArray(SdFnCA, 15);
// re-open the file for reading:
myFile = SD.open(SdFnCA);
if (myFile) {
Serial.print("Reading from ");
Serial.println(SdFnCA);
Serial.print("Data:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
CZ=myFile.read();
SdDataCA[i]=CZ;
i++;
Serial.write(CZ);
}
// close the file:
myFile.close();
SdDataCA[i]=0;
Serial.print("Done. Data=");
Serial.println(SdDataCA);
SdData=SdDataCA;
Serial.println(SdData);
} else {
// if the file didn't open, print an error:
Serial.print("");
Serial.print("*** Error opening ");
Serial.println(SdFnCA);
}
}
void ScrClr()
{myGLCD.clrScr(); myGLCD.setFont(BigFont);}
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void ChkFree()
{
Serial.println("");
Serial.print("freeRAM=");
Serial.print(freeMemory());
Serial.print(" (");
Serial.print(freeRam());
Serial.println(") B");
}
String FixRoundErr(String S)
{
float zf;
String SF;
zf=StrToFloat(S);
S=FloatToStr(zf,0,5);
SF=RemoveZeros(S);
return SF;
}
String RemoveZeros(String S)
{
int z,zz;
char ZC;
zz=S.length()-1;
Serial.println("");
Serial.println("S="+S);
for (z=zz; z>0; z--)
{
ZC=S.charAt(z);
if (ZC!=48)
{
if (ZC==46) {S=S.substring(0,z);}
break;
}
S=S.substring(0,z);
}
//Serial.println(" S final="+S);
return S;
}
float StrToFloat(String str)
{
char carray[str.length() + 1]; //determine size of the array
str.toCharArray(carray, sizeof(carray)); //put str into an array
return atof(carray);
}
String FloatToStr(float f, int l, int d )
{
String S;
char zCA[20];
dtostrf(f,l,d,zCA);
//zCA+=0;
S=zCA;
return S;
}
void ShowTemp()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
TempC=sensors.getTempCByIndex(0);
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(TempC);
//TempC=sensors.getTempCByIndex(0);
S=FloatToStr(TempC,4,1);
myGLCD.print(S+"'C",LEFT,224);
}
void SaveThis()
{
fSett[z]=StrToFloat(stCurrent);
SdFn=sSettIni[z];
SdData=stCurrent;
SdSave();
}
void LoadIniFiles()
{
for (z=0; z<MaxSettings; z++) {LoadThis(); }
}
void LoadThis()
{
SdFn=sSettIni[z];
SdLoad();
S=FixRoundErr(SdData);
fSett[z]=StrToFloat(S);
}
void loadInit()
{
sAppVer="0.1";
sAppName="TESTTEST";
sAppNameUC=sAppName;
sAppNameUC.toUpperCase();
}
void setup()
{
myGLCD.InitLCD();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
loadInit();
Serial.begin(9600);
sensors.begin();
ShowTemp(); // Compiles ok if i comment this line...
ChkFree();
SdInit();
LoadIniFiles(); // ...or if i comment this line
ChkFree();
}
void loop()
{
while (true)
{
ScrClr(); // also compiles if i comment this line
}
}