[SOLVED]My library makes the compiling hang in mid-air, what have I done wrong?


I have been trying to write my own first library, in a project I am using both ADCs and DACs amongst other things and I want to make classes for these and then why not put these classes in library’s?

I begun with the DAC MAX5216 a 16bit buffered voltage output SPI DAC, here are my files:


#ifndef MAX5216_h
#define MAX5216_h

#include "Arduino.h"
// Class definition (this is a 'pre-declaration'.
class MAX5216
     MAX5216(int CSpin);          // Constructor, save the slave select pin to private holder.
     void begin();                // Initializes SPI settings to fit MAX5216.
     void write_mV(int mVval);    // To set DAC output with a milliVolts value, depends on actual DAC reference voltage.
     void write_DEC(int DECval);  // To set DAC output with a decimal value from 0 to 65535.
     int read();                  // Check what value the DAC is set to.
     void DAC_update(int code);   // This makes the actual SPI transfer and it is called from both public write_ options.
     int _CSpin;                  // Holder for slave select pin.
     int _last;                   // Holder for the values send to DAC.


#include "MAX5216.h"
#include "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI/SPI.h"

MAX5216::MAX5216(int CSpin)
  _CSpin = CSpin;

void MAX5216::begin()
  // MAX5216 DAC Setup
  // MSB first, shifts data on SCKs falling edge, clock idle Low, SCK freq « 50MHz. 
  SPI.setBitOrder(_CSpin, MSBFIRST);
  SPI.setDataMode(_CSpin, SPI_MODE1);
  SPI.setClockDivider(_CSpin, 2);

void MAX5216::write_mV(int mVval)
  if (mVval < 0)
    mVval = 0;
  else if (mVval > 3000)
    mVval = 3000;
  unsigned int code = 65535 * (mVval/3000.0);

void MAX5216::write_DEC(int DECval)
  if (DECval < 0)
    DECval = 0;
  else if (DECval > 65535)
    DECval = 65535;

int MAX5216::read()
  return _last;

void MAX5216::DAC_update(int code)
  _last = code;
  uint32_t MAXcode = code << 6 | 0x400000;
  byte byte1 = (MAXcode & ~(0x00FFFF)) >> 16;  // Extraxt B23-B16
  byte byte2 = (MAXcode & ~(0xFF00FF)) >> 8;   // Extraxt B15-B8
  byte byte3 = MAXcode & ~(0xFFFF00);          // Extraxt B7-B1

  SPI.transfer(_CSpin, byte1, SPI_CONTINUE);  // Send B23-B16 through SPI
  SPI.transfer(_CSpin, byte2, SPI_CONTINUE);  // Send B15-B8 through SPI
  SPI.transfer(_CSpin, byte3, SPI_LAST);      // Send B7-B1 through SPI

But when compiling:

#include <MAX5216.h>
#include <SPI.h>

void setup() {
  // put your setup code here, to run once:


void loop() {
  // put your main code here, to run repeatedly:


The compilation process(which maybe should be called something else) stops very early, the green progress bar is about half and all that shows is:

Using library MAX5216 in folder: C:\Users\David\OneDrive\Arduino\libraries\MAX5216 (legacy)
Using library SPI in folder: C:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\libraries\SPI 

C:\Users\David\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=10604 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due" -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\system/libsam -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\system/CMSIS/CMSIS/Include/ -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\system/CMSIS/Device/ATMEL/ -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\cores\arduino -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\variants\arduino_due_x -IC:\Users\David\OneDrive\Arduino\libraries\MAX5216 -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\libraries\SPI C:\Users\David\AppData\Local\Temp\build6335026798324731736.tmp\sketch_may28c.cpp -o C:\Users\David\AppData\Local\Temp\build6335026798324731736.tmp\sketch_may28c.cpp.o 
C:\Users\David\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=10604 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due" -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\system/libsam -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\system/CMSIS/CMSIS/Include/ -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\system/CMSIS/Device/ATMEL/ -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\cores\arduino -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\variants\arduino_due_x -IC:\Users\David\OneDrive\Arduino\libraries\MAX5216 -IC:\Users\David\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\libraries\SPI -IC:\Users\David\OneDrive\Arduino\libraries\MAX5216\utility C:\Users\David\OneDrive\Arduino\libraries\MAX5216\MAX5216.cpp -o C:\Users\David\AppData\Local\Temp\build6335026798324731736.tmp\MAX5216\MAX5216.cpp.o

And nothing else happens, never ever.
I have read all I can find online but this I cannot solve, please advise.


I find the new IDE strange, anyway I found the problem.
I had found the SPI.h file going through the arduino folder and icluded that path in the .cpp file, but looking at the compiler output that is not where the IDE looks for the SPI.h due to me typing #include “SPI.h” in the sketch.

Changing the direct path include of SPI.h in .cpp to the path shown in the compil output fixed it and now it works like a charm.