Compiled for R4, now it doesn't

Thank you for looking this. I don’t know if this is a problem anyone else has encountered, or whether I’ve done something wrong. I am looking for advice, so…

First I will give an overview of the problem, along with the hardware and software used to compile my Arduino Sketch, then I will provide the details (the error messages on compile and the code from the header files where the problem occurs and the Arduino sketch). Afterward, I’ll provide my tentative Ideas for what is wrong, though I don’t know how to solve the problem.

OVERVIEW:

This sketch COMPILES for the Arduino UNO R4 Minima using the following hardware/software:

Mac mini (M1) with OS 13 or 14 (I’m not near that computer now, so I can’t )
Arduino IDE 2.X (I uploaded it in late November 2023)

It DOES NOT COMPILE with my new system when I compile for the Arduino UNO R4 Minima using the following:.

MacBook (M3) with OS 14.5
Arduino IDE 2.3.2. I compile the same sketch for the UNO R4 Mini. It DOES NOT COMPILE.

However, with the MacBook with the same IDE and sketch DOES COMPILE when compiled for the Arduino UNO (R3).

DETAILS:

____ Error info - Below are the errors thrown when compiled and the code from the library .h and .cpp files and the Arduino sketch.

In file included from /Users/robertmauck/Documents/Arduino/libraries/PRDC_AD7193/src/PRDC_AD7193.cpp:27:0:
/Users/robertmauck/Documents/Arduino/libraries/PRDC_AD7193/src/PRDC_AD7193.cpp: In constructor 'PRDC_AD7193::PRDC_AD7193()':
/Users/robertmauck/Documents/Arduino/libraries/PRDC_AD7193/src/PRDC_AD7193.h:39:27: error: 'PIN_SPI_SS' was not declared in this scope
 #define AD7193_DEFAULT_CS PIN_SPI_SS
                           ^
/Users/robertmauck/Documents/Arduino/libraries/PRDC_AD7193/src/PRDC_AD7193.cpp:34:34: note: in expansion of macro 'AD7193_DEFAULT_CS'
   _spi(&AD7193_DEFAULT_SPI), _CS(AD7193_DEFAULT_CS), _MISO(AD7193_DEFAULT_MISO) {
                                  ^~~~~~~~~~~~~~~~~
/Users/robertmauck/Documents/Arduino/libraries/PRDC_AD7193/src/PRDC_AD7193.h:39:27: note: suggested alternative: 'PIN_SPI_CS'
 #define AD7193_DEFAULT_CS PIN_SPI_SS
                           ^
/Users/robertmauck/Documents/Arduino/libraries/PRDC_AD7193/src/PRDC_AD7193.cpp:34:34: note: in expansion of macro 'AD7193_DEFAULT_CS'
   _spi(&AD7193_DEFAULT_SPI), _CS(AD7193_DEFAULT_CS), _MISO(AD7193_DEFAULT_MISO) {
                                  ^~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1

—— LIBRARY FILES: relevant sections of PRDC_AD7193.h and PRDC_AD7193.cpp here:

From the header (.h) file here. NOTE, I have highlighted the lines where the error occurred since this doesn’t have line numbers

/**

* PRDC_AD7193.h - Analog Devices AD7193 ADC Library

* Author: Milos Petrasinovic <mpetrasinovic@pr-dc.com>

*/

#ifndef _PRDC_AD7193_H_

#define _PRDC_AD7193_H_

#include "Arduino.h"

#include <SPI.h>

// AD71983 Library debug

// #define DEBUG_AD7193

// SPI communication settings

#define AD7193_DEFAULT_SPI_FREQUENCY 1000000

#define AD7193_DEFAULT_SPI SPI

#define AD7193_DEFAULT_CS PIN_SPI_SS // Error here (‘in expansion of macro 'AD7193_DEFAULT_CS')

#define AD7193_DEFAULT_MISO PIN_SPI_MISO

From the .cpp file:

/**
 * PRDC_AD7193.cpp - Analog Devices AD7193 ADC Library
 * Author: Milos Petrasinovic <mpetrasinovic@pr-dc.com>
 */

#include "PRDC_AD7193.h"	// Error here ('PIN_SPI_SS' was not declared in this scope, etc.)

// PRDC_AD7193()
// Object constructor
// --------------------
PRDC_AD7193::PRDC_AD7193() :
  _spiSettings(AD7193_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE3),
  _spi(&AD7193_DEFAULT_SPI), _CS(AD7193_DEFAULT_CS), _MISO(AD7193_DEFAULT_MISO) {

}

—— ARDUINO SKETCH in Full:

/**
 * test_LCs.ino - Test Load Cell with AD7193 
 * Author: Milos Petrasinovic <mpetrasinovic@pr-dc.com>
 * PR-DC, Republic of Serbia
 * info@pr-dc.com
 * 
 * --------------------
 * Copyright (C) 2021 PR-DC <info@pr-dc.com>
 *
 * This file is part of PRDC_AD7193.
 *
 * PRDC_AD7193 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * PRDC_AD7193 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * This code adapted from above for demo of use by R. Mauck
 */

// Library
// --------------------
// PRDC AD7193
// Author: PRDC

#include <PRDC_AD7193.h>
#include <LiquidCrystal.h>
#include <SD.h>
#include <SPI.h>
#include "Time.h"
#include "RTClib.h"


// Define variables
// --------------------
File myFile;

#define SRAM_CS 1 //Use A0 for Uno R3.  Use 1 for Uno R4
#define SD_CS 10
#define AD7193_CS 0 //Use A1 for Uno R3. Use 0 for Uno R4

// SPI communications
PRDC_AD7193 AD7193;

// RTC
RTC_DS1307 RTC;
// Setup time variables that will be used in multiple places
DateTime currenttime;
long int myUnixTime;

// LCD
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// setup function
// --------------------
void setup() { 

  // Set CS pins high as soon as we can
  pinMode(SRAM_CS, OUTPUT); 
  digitalWrite(SRAM_CS, HIGH);

  pinMode(SD_CS, OUTPUT); 
  digitalWrite(SD_CS, HIGH);

  pinMode(AD7193_CS, OUTPUT); 
  digitalWrite(AD7193_CS, HIGH);

  // Communication settings
  Serial.begin(2000000);
  //while(!Serial.available()){};  // Not needed for Uno R4

  Serial.print("Initializing SD card...");

  if (!SD.begin(SD_CS)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  
  AD7193.setSPI(SPI);
  if(!AD7193.begin(AD7193_CS, PIN_SPI_MISO)) {
    Serial.println(F("AD7193 initialization failed!"));
  } else {
    AD7193.printAllRegisters();
    AD7193.setClockMode(AD7193_CLK_INT);
    AD7193.setRate(0x001);
    AD7193.setFilter(AD7193_MODE_SINC4);
    AD7193.enableNotchFilter(false);
    AD7193.enableChop(false);
    AD7193.enableBuffer(true);
    AD7193.rangeSetup(0, AD7193_CONF_GAIN_128);
    AD7193.channelSelect(AD7193_CH_0);
    Serial.println(F("AD7193 Initialized!"));
  }

  Serial.println("RTC setup");
  if (!RTC.begin()) {  // initialize RTC
    Serial.println("RTC failed");
  } else {
    if (!RTC.isrunning()) {
      Serial.println("RTC is NOT running!");
      // following line sets the RTC to the date & time this sketch was compiled
      RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
    } else {
      RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
      Serial.println("RTC is already initialized.");
    }
  }
}

// loop function
// --------------------
void loop(){
  uint32_t sampleCounter = 0;
  static uint32_t fileCounter = 0;

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  String fileName;
  fileName = "TF_" + String(fileCounter);
  Serial.print("Opening file for write with filename: ");
  Serial.println(fileName);
  myFile = SD.open(fileName, FILE_WRITE);
    // if the file opened okay, write to it:
  
  if (myFile)
  {
    for(sampleCounter=0; sampleCounter<100; sampleCounter++)
    {
      uint32_t ts = 0;
      uint32_t result = 0;
      ts=micros();
      myUnixTime = Get_TimeStamp();
      result = AD7193.singleConversion();

      // Write to serial debug
      Serial.print(ts);
      Serial.print("\t");
      Serial.print(myUnixTime);
      Serial.print("\t");
      Serial.println(result);
      
      // Write to LCD
      lcd.setCursor(0, 0);
      lcd.print(result);
      
      
      // Write to SD
      myFile.print(ts);
      myFile.print("\t");
      myFile.print(myUnixTime);
      myFile.print("\t");
      myFile.println(result);
    }
  } else {
    // if the file didn't open, print an error:
    Serial.println("Error opening file for write");
  }
  myFile.close();
  fileCounter++;
}

////////////////////
//  Get_TimeStamp - encapsulate data in case we change libraries
////
long int Get_TimeStamp() {
  /* GET CURRENT TIME FROM RTC */
  currenttime = RTC.now();

  // convert to raw unix value for return - could give options
  return (currenttime.unixtime());
}

TENTATIVE CONCLUSION/HYPOTHESIS:

There is a difference in the environment of the M1 mini and the M3 MacBook. That difference might involve one or more of the following:

  1. the Mac OS - though this I should note that the same issue is true on my old MacBook Air using IDE 1.8 (compiles for R3, but not R4).

  2. the Arduino IDE

  3. the internal (to the IDE) R4 board definition that is currently available (renesas_uno/1.2.0?) vs. the one I last used in May at home. Version

  4. the internal SPI definition that is currently available vs. the one I last used in May at home.

  5. something I haven’t thought of

Does anyone know what I’ve done wrong, or can do differently, or who has had this problem?

Thanks for any thoughts you might have.

When I see things like this in the compile log, my "what the L" meter twitches violently:

In file included from /home/me/Documents/sketchbook/Uno_R4_Minima/test/test.ino:30:0:
/home/me/Documents/sketchbook/libraries/PRDC_AD7193/src/PRDC_AD7193.h:113:0: warning: "AD7193_CONF_REFSEL" redefined
 #define AD7193_CONF_REFSEL      (0 << 20)            // REFIN1 Reference Select.
/home/me/Documents/sketchbook/libraries/PRDC_AD7193/src/PRDC_AD7193.h:112:0: note: this is the location of the previous definition
 #define AD7193_CONF_REFSEL      (1 << 20)            // REFIN2 Reference Select.

But, leaving that aside, for the R4, it's PIN_SPI_CS, not PIN_SPI_SS. Alter the library header file to change:

#define AD7193_DEFAULT_CS PIN_SPI_SS

to

#if defined(PIN_SPI_SS)
#define AD7193_DEFAULT_CS PIN_SPI_SS
#else
#define AD7193_DEFAULT_CS PIN_SPI_CS
#endif

and you should be able to compile with both.

1 Like

Problem solved! Thank you van_der_decken!

Apparently, PIN_SPI_SS is not defined in the R4 and PIN_SPI_CS is defined for that purpose. I'm not sure why I was able to compile on my earlier build for the R4, but this works now and I am happy.

Thank people who help you

Those of us who answer questions on here are doing so for free, out of community spirit. Please thank people who provide helpful answers and don't forget to give :heart:s as well.

It also helps if you click the :ballot_box_with_check: Solution button at the bottom of the reply that answered your question. This will make it easy for helpers to see that it is solved and for others with the same question to find the answer quickly.

Hi Delta-G,

I would like to port a Arduino UNO code to an R4, and there seem to have problems with AVR Library/functions.
Do you have a link where I can check-out some workarounds?
I am new at Arduino, but not at programming (OK, mostly FPGA, pure C and .... Z80 :thinking:).

Thanks for any help.

Thanks!

That is what I suspected.

Last question.
Where (how) can I get the source code for the AVR libraries/stuff?
I have tried to look at any Directory Arduino/AVR on my PC but I did not find anything in clear.

I will google of course ...

Hi,
What I meant with my last answer, is that I can not find the underlying C/C++/Assembler source files that comes along with the H files (Include files I have already found)

Cordialement

Thanks.
I have found what I think is what I need.
Thanks a lot and sorry for those simple questions

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.