Error when compiling for atmega1284 but not atmega2560

I get the following error when I compile for my standalone atmega 1284 chip :

"invalid conversion from 'char*' to 'xref2u1_t {aka unsigned char*}' [-fpermissive]" (full error message below)

for the same code which worked at my Atmega 2560 board.

The related portion of the code is as follows: (and the full code is below)

static char gps_lat[20]={"\0"};
LMIC_setTxData2(1, gps_lat, sizeof(gps_lat)-1, 0);

I tried char*, unsigned char*, and other variants instead of char, but these gave some other errors.

I have superficial knowledge of c++ and just trying to make already available examples work in coherence.

full error message :

In function 'void do_send(osjob_t*)':

error: invalid conversion from 'char*' to 'xref2u1_t {aka unsigned char*}' [-fpermissive]

LMIC_setTxData2(1, gps_lat, sizeof(gps_lat)-1, 0); 

                                                         ^
In file included from lmic.h:5:0,

note: initializing argument 2 of 'int LMIC_setTxData2(u1_t, xref2u1_t, u1_t, u1_t)'

 int   LMIC_setTxData2   (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed);

full related portions of code :

#include <lmic.h>
#include <TinyGPS.h>

   String datastring="";
   String datastring1="";
   char gps_lon[20]={"\0"}; 
   static char gps_lat[20]={"\0"};

void do_send(osjob_t* j){
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, gps_lat, sizeof(gps_lat)-1, 0);
    }

void getGPS () {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6;          
    flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6; 
    // Once the GPS fixed,send the data to the server.
    datastring +=dtostrf(flat, 0, 6, gps_lat); 
    datastring1 +=dtostrf(flon, 0, 6, gps_lon);
    Serial.println(strcat(strcat(gps_lon,","),gps_lat));
    strcpy(gps_lat,gps_lon);
    senddata ();
    }

void senddata(){
  while (txcompletion)
  {
    os_runloop_once();
     delay(1000);
  }
  txcompletion = true;
}


void loop() {
getGPS ();
}

I didn't include the setup intentionally becaıse I thought it wan't related, if necessary I can include it and other parts.

Full sketch, no snippets, and links to the two libraries you're using (preferably nice github links so we can view the code easily).

What core were you using when it worked with the atmega1284?

This is not a normal compatibility problem (ex, registers that don't exist on one chip or something) - it's some difference between the cores being used, as far as I can tell - but you need to give us more info.

Here is the link to lmic : arduino-lmic-v1.5/lmic.h at master · tftelkamp/arduino-lmic-v1.5 · GitHub

and the tinyGPS should be this : https://github.com/mikalhart/TinyGPS/blob/master/TinyGPS.h

Here is the hardware library I used for Atmega 1284 : GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535

And the Atmega 2560 core is the original one that comes with Arduino IDE.

(It WORKED with Atmega 2560, not 1284)

And the full sketch :

#include <Wire.h>
#include <RTClibExtended.h>
#include <LowPower.h>
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>

int rtcpin = 5;
int gpspin = 4;

 
#define wakePin 3    //use interrupt 0 (pin 2) and run function wakeUp when pin 2 gets LOW
#define ledPin 13 
//#define alarmingPin 7

volatile bool txcompletion = true; // helps send just once

static const PROGMEM u1_t NWKSKEY[16] = { 0xDB, 0x64, 0xF6, 0xCF, 0x4D, 0x5A, 0xAB, 0x96, 0xFC, 0xF5, 0xFF, 0x45, 0xF8, 0x35, 0xCF, 0xBC };
static const u1_t PROGMEM APPSKEY[16] = { 0x23, 0xB4, 0x10, 0x60, 0x8E, 0x41, 0xBE, 0x84, 0x41, 0x9B, 0x36, 0xE4, 0x69, 0xA5, 0x54, 0xD0 };
static const u4_t DEVADDR = 0x26011EEB;

void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }

RTC_DS3231 RTC;      //we are using the DS3231 RTC
TinyGPS gps;
//SoftwareSerial ss(8, 7); //Arduino RX, TX 
SoftwareSerial ss(13, 12);
   String datastring="";
   String datastring1="";
   char gps_lon[20]={""}; 
   static char gps_lat[20]={""}; // 

   const unsigned TX_INTERVAL = 0; //20 idi

static osjob_t initjob,sendjob,blinkjob;

const lmic_pinmap lmic_pins = {
    .nss = 11, //changed from 10 not to coincide int0 
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 9,
    .dio = {2, 22, 23}, // changed from 6 ve 7 to open space for miso mosi 
};

void do_send(osjob_t* j){
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println("OP_TXRXPEND, not sending");
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, gps_lat, sizeof(gps_lat)-1, 0); //gps_lat, changed with dataoutgoing 
        Serial.print("data=");
        Serial.println(gps_lat);
        Serial.println("Packet queued");
        Serial.println(LMIC.freq);
        delay(15000);
    }
    }

    void onEvent (ev_t ev) {
    Serial.print(os_getTime());
    Serial.print(": ");
    Serial.println(ev);
    switch(ev) {
        case EV_SCAN_TIMEOUT:
            Serial.println("EV_SCAN_TIMEOUT");
            break;
        case EV_BEACON_FOUND:
            Serial.println("EV_BEACON_FOUND");
            break;
        case EV_BEACON_MISSED:
            Serial.println("EV_BEACON_MISSED");
            break;
        case EV_BEACON_TRACKED:
            Serial.println("EV_BEACON_TRACKED");
            break;
        case EV_JOINING:
            Serial.println("EV_JOINING");
            break;
        case EV_JOINED:
            Serial.println("EV_JOINED");
            break;
        case EV_RFU1:
            Serial.println("EV_RFU1");
            break;
        case EV_JOIN_FAILED:
            Serial.println("EV_JOIN_FAILED");
            break;
        case EV_REJOIN_FAILED:
            Serial.println("EV_REJOIN_FAILED");
            break;
        case EV_TXCOMPLETE:
            Serial.println("EV_TXCOMPLETE (includes waiting for RX windows)");
            txcompletion = false;
            if(LMIC.dataLen) {
                // data received in rx slot after tx
                Serial.print("Data Received: ");
                Serial.write(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
                Serial.println(); //the rest of the code is a later addition
                Serial.print(F("Received "));
            Serial.print(LMIC.dataLen);
            Serial.print(F(" bytes for downlink: 0x"));
            for (int i = 0; i < LMIC.dataLen; i++) {
                if (LMIC.frame[LMIC.dataBeg + i] < 0x10) {
                    Serial.print(F("0"));
                }
                Serial.print(LMIC.frame[LMIC.dataBeg + i], HEX);
            }
            Serial.println();
            }
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;
        case EV_LOST_TSYNC:
            Serial.println("EV_LOST_TSYNC");
            break;
        case EV_RESET:
            Serial.println("EV_RESET");
            break;
        case EV_RXCOMPLETE:
            // data received in ping slot
            Serial.println("EV_RXCOMPLETE");
            break;
        case EV_LINK_DEAD:
            Serial.println("EV_LINK_DEAD");
            break;
        case EV_LINK_ALIVE:
            Serial.println("EV_LINK_ALIVE");
            break;
         default:
            Serial.println("Unknown event");
            break;
    }
}

    
void telltime()   
{
    char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    DateTime now = RTC.now();
  }


//-------------------------------------------------
void wakeUp()        // here the interrupt is handled after wakeup
{
  Serial.println("wakeup worked");
}

void getGPS () {
   bool newData = false;
   bool checkdata = true;
  unsigned long chars;
  unsigned short sentences, failed;

   for (unsigned long gpscheck = millis(); millis() - gpscheck < 600000;)
   {
    if (checkdata)
    {
   delay(1000);
   Serial.println("gps searching");
  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read(); //changed with serial 
     // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
      {newData = true;
      delay(100);
      Serial.println("new data true");// for debugging
      }
    }
  }

  if (newData)
  {
    checkdata = false;
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6;          
    flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6; 
    // Once the GPS fixed,send the data to the server.
    datastring +=dtostrf(flat, 0, 6, gps_lat); 
    datastring1 +=dtostrf(flon, 0, 6, gps_lon);
    Serial.println(strcat(strcat(gps_lon,","),gps_lat));
    strcpy(gps_lat,gps_lon);
    Serial.println(gps_lat); //Print gps_lon and gps_lat;
    telltime ();
    senddata ();
  }
    }
    else
    break;
   }
}

  void alarmset() {
    RTC.alarmInterrupt(1, true);
    attachInterrupt(digitalPinToInterrupt(10), wakeUp, LOW);                       //use interrupt 0 (pin 2) and run function wakeUp when pin 2 gets LOW
    digitalWrite(gpspin, HIGH);
    delay(1000);
    //digitalWrite(rtcpin, LOW);
    byte savedPCICR = PCICR;
    PCICR = 0;  // Disable all pin change interrupts
    delay(1000);
    void hal_sleep (void);
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);   //arduino enters sleep mode here
    detachInterrupt(1);                                    //execution resumes from here after wake-up
    //digitalWrite(rtcpin, HIGH);
    digitalWrite(gpspin, LOW);
    telltime();
    RTC.armAlarm(1, false);
    RTC.clearAlarm(1);
    RTC.alarmInterrupt(1, false);
    PCICR = savedPCICR;  // Restore any pin change interrupts that were disabled
    getGPS ();
    delay(1000);
  }

void senddata(){
  while (txcompletion)
  {
    os_runloop_once();
     delay(1000);
  }
  txcompletion = true;
}
  

void setup() {
  Serial.begin(115200); 
  ss.begin(9600);
  //Initialize communication with the clock
  Wire.begin();
  pinMode(gpspin, OUTPUT);
  RTC.begin();
  RTC.adjust(DateTime(__DATE__, __TIME__));   //set RTC date and time to COMPILE time
  //clear any pending alarms
  RTC.armAlarm(1, false);
  RTC.clearAlarm(1);
  RTC.alarmInterrupt(1, false);
  RTC.armAlarm(2, false);
  RTC.clearAlarm(2);
  RTC.alarmInterrupt(2, false);
  RTC.writeSqwPinMode(DS3231_OFF);

  telltime ();
  while(!Serial);
  Serial.println("Starting");

}

//------------------------------------------------------------

void loop() {

    
               RTC.setAlarm(ALM1_MATCH_HOURS, 31, 18, 0);   //set your wake-up time here
    telltime ();
    alarmset ();


         RTC.setAlarm(ALM1_MATCH_HOURS, 53, 19, 0);   //set your wake-up time here
    telltime ();
    alarmset ();


}

The 1284 core has the -permissive flag disabled as I recall.

The 2560 core probably has it enabled.

Srnet, I don't know about the -permissive flag. Can I enable it without breaking other things? And how to do that?

archimedes:
Srnet, I don't know about the -permissive flag. Can I enable it without breaking other things? And how to do that?

Do a Google search for 'Arduino permissive'

Srnet, I searched google but did not find much except this. I understand they are talking about disabling the compiler error interruption so that the sketch would not stop compiling, because the error is real but so minor that would not affect the outcome. Is that what I should understand?

Strange, the first item I get for that search is;

Which explains the problem.

I read this one too actually. To my level of understanding they meant similar things. But.....no mention of a solution except for a link to a makefile in one post.

And here is the gcc explanation :

"-fpermissive : Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive allows some nonconforming code to compile."

archimedes:
I read this one too actually. To my level of understanding they meant similar things. But.....no mention of a solution except for a link to a makefile in one post.

From that link;

"This compiler flag {-fpermissive} was introduced in commit ba0c41b, in order to not break the build of some old libraries. I am not convinced it is a good thing to not let the library authors know about the problems with their bad code."

So you need to add the -fpermissive compiler flag if you want the code to compile, there will be a line in platform.txt that runs the compiler, search for a platform.txt that has the -fpermissive flag included, and then add it in the same way to the platform.txt for your chosen core.

Great! The problem is solved! Thank you soooo much!