Solved: Errors with SoftSPI needed for testing a shield

I am getting an error I haven't been able to resolve, even after a LOT of searching, reading, and experimentation.

I need to use the SoftSPI functions to test a board. I cut my code down to show the error.

Here are the errors when I compile with IDE 1.8.10. My board is the RobotDyne Mega2560. Attached is the failing code.

I used the Greiman DigitalIO library: DigitalIO

Thank you for your help!

(Any examples other than the scope example Greiman provided would be helpful also)

Here is the code:

// The ATmega2560 in the Mega2560 has larger memory space :
// Flash  256k bytes (of which 8k is used for the bootloader)
// SRAM   8k bytes
// EEPROM 4k byte
//-------------------------------------------------------------------------
// Libraries used
//-------------------------------------------------------------------------
//#include "SoftSPI.h"
#include <DigitalIO.h>


//
//-------------------------------------------------------------------------
// Communications and SD Global Variables and compiler directives
//-------------------------------------------------------------------------
// uncomment DEBUGH to include hardware debugging 
// The arduino shield uses pins 38, 39, 40 to read buttons  and write LEDS
// Connecting the jumpers below and uncomming DEBUGH all the shield to simulate  testing
// Pin 41 is used as the select line to STB to chose Lights (high) or Buttons (low)
// UNPLUG CONNECTOR
// Jumpers on shield
// -- Pin 41 (Digital Connector simulating STB Select) to Pin 4 High is LEDs, Low is Buttons 
// -- Pin 40 (Digital Connector PG1 /RD simulating SCK Serial Clock) to Pin 1 CLK 
// -- Pin 39 (Digital Connector PG2 ALE simulating MISO Master In Slave Out) to Pin 3 DATK is Buttons Input
// -- Pin 38 (Digital Connector PD7 simulating MOSI Master Out Slave In) to Pin 2 DATA is LEDs Output
//
//#define DEBUG_STB_PIN (uint8_t) 41
//#define DEBUG_SPI_MOSI_PIN (uint8_t) 38
//#define DEBUG_SPI_MISO_PIN (uint8_t) 39
//#define DEBUG_SPI_SCK_PIN  (uint8_t) 40
//#define DEBUG_SPI_MODE (uint8_t) 2

const uint8_t DEBUG_STB_PIN = 41; //
const uint8_t DEBUG_SPI_MOSI_PIN = 38; // PD7 TO OUTPUT
const uint8_t DEBUG_SPI_MISO_PIN = 39; // PG2 ALE INPUT
const uint8_t DEBUG_SPI_SCK_PIN  = 40; // PG1 /RD OUTPUT
const uint8_t DEBUG_SPI_MODE = 2;

SoftSPI<DEBUG_SPI_MISO_PIN, DEBUG_SPI_MOSI_PIN, DEBUG_SPI_SCK_PIN, DEBUG_SPI_MODE> sspi;

unsigned long testPattern = 0xAAAAAAAA;
int K=0;
uint8_t BButtons = 255;

#define DEBUGHL 1
#define DEBUGHB 1

void setup() {

// Debug code when Arduino Shield is NOT plugged
// Only plugged into Arduino Shield
//
// Either DEBUGHL or DEBUGHB
#if defined(DEBUGHL) || defined(DEBUGHB)
// Initialization
pinMode(DEBUG_STB_PIN, OUTPUT);
digitalWrite(DEBUG_STB_PIN,LOW);
//  SoftSPI sspi;
sspi.begin();
#endif
}
//-------------------------------------------------------------------------
// Main loop MAIN MAIN MAIN
//-------------------------------------------------------------------------
void loop() {

#ifdef DEBUGHL
    testPattern = testPattern << 1; // Shift the 32 bit unsigned integer left 1 bit ie mul by 2 for next light
    if (testPattern == 0) { // If we have shifted thru all the lights then start again
      testPattern = 1;
    }
#endif

//---------------------------------------------------------------------
// TEST CODE for Hardware
//---------------------------------------------------------------------
// Test method with shield hardware and hardware test jumpers AND NOT plugged
#if defined(DEBUGHL) || defined(DEBUGHB)
if (K>=350) {
  // about once a second
  // When STB is HIGH LIGHTS are being written to the Front Panel
  // When STB is LOW Buttons are being read (Don't overwrite)
  // aka NSTB is HIGH Buttons are being read (Don't overwrite)
  // Interrupt and overwrite Buttons when STB goes HIGH (or NSTB goes Low)

 // Assert the select for lights
  digitalWrite(DEBUG_STB_PIN, HIGH); // This will also generate a Buttons Interrupt
 //
 #endif
 
 #ifdef DEBUGHL
  //
  // Simulate sending lights to Front Panel
  //
  // turn on a different light and shift to prepare the next light.
  Serial.print(F("Sndg lit tst pat "));
  Serial.println(testPattern, HEX); 
  sspi.send(testPattern); // Simulate sending of lights
  // The next rising edge of STB should generate an interrupt to read the Lights
 #endif

 #if defined(DEBUGHL) || defined(DEBUGHB)
   // Assert the select for buttons
   digitalWrite(DEBUG_STB_PIN, LOW); 
   //
 #endif
  
 #ifdef DEBUGHB
   //
   // Simulate reading of buttons
   //
   // Read the buttons
   BButtons = (uint8_t)sspi.receive(); // Simulate reading
   // Did we get any buttons? Should be only one zero bit
   if (BButtons!=0 && BButtons != 255) {
    // Print the buttons if any pushed
    Serial.print(F("Sim Rd of Buttons="));
    Serial.println(BButtons); 
   }
   #endif
#if defined(DEBUGHL) || defined(DEBUGHB)   
 K=0;// Restart the ~1 second counter
}
K++; // Increment the ~1 second counter
#endif

delay(19);
}

//-------------------------------------------------------------------------
// End of Main Loop
//-------------------------------------------------------------------------

Please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded the DigitalIO library from. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Added the link to the Greiman library per request to the initial post.

I just compiled the sketch posted for Mega 2560 and got no errors. I suspect something went wrong with your installation of the library.

Try this:

  • Delete the folder containing the DigitalIO library. If you don't know the folder location, you can find it listing in the Arduino IDE's console window after the compilation fails.
  • Download https://github.com/greiman/DigitalIO/archive/master.zip
  • (In the Arduino IDE) Sketch > Include Library > Add .ZIP Library
  • Select the downloaded file.
  • Click the "Open" button.
  • Try compiling again.

Thank you Pert. I deleted the library and then re-added using the Library Manager and it compiled without error. I will close this as solved.

However, my original very large program (not the snippet I posted here) still failed with the same re-added library. I suspect it is a conflict between SD.h, Ethernet.h, and DigitalIO.h. I will have to investigate and post a anew.

Unfortunately my code is huge and my intended publisher will not allow it to be published here until he has the opportunity to publish. Sigh.

You're welcome. I'm glad to hear that at least the snippet ss working now. That's a start. Enjoy!
Per