SPI_CLOCK_DIV128 not declared in this scope

Hi

I have a sketch that runs fine on my Uno, but I am now porting this project to the Due

My sketch compiles fine when I select the Uno, but when I select the Due I get this error

// Begin SPI
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(0);
SPI.setClockDivider(SPI_CLOCK_DIV128);

hdswitch_v0_20.ino: In function 'void setup()':
hdswitch_v0_20:588: error: 'SPI_CLOCK_DIV128' was not declared in this scope

I didn't change any declaration so how can it not be declared?

Rich

The due uses a different core to the Uno. Thus, the peripherals are different. So, the programming of the peripherals are different.

Check the Due documentation for SPI. You'll see it's different.

OK I had a look.... It says:

Extended SPI functionality for the Due

The Arduino Due's SPI interface works differently than any other Arduino boards. The library can be used on the Due with the same methods available to other Arduino boards or using the extended methods. The extended methods exploits the the SAM3X hardware and allows some interesting features like:

automatic handling of the device slave selection.
automatic handling of different device configurations (clock speed, data mode, etc) so every device can have its own configuration automatically selected.

So I am still confused. I did notice by commenting out the setClockDivider line my sketch now compiles, but I can't use my cheap Bus Pirate logic analyser to debug unless I slow down the SPI

Yes, the methods may be the same (as the SPI basically does the same job), but the values you can pass to those methods is different.

http://arduino.cc/en/Reference/SPISetClockDivider:
Arduino Due
On the Due, the system clock can be divided by values from 1 to 255. The default value is 21, which sets the clock to 4 MHz like other Arduino boards.

Extended method for Arduino Due
If you specify one of the Arduino Due's Slave Select (SS) pin in the call to setClockDivider(), the clock setting is applied only to the device connected to the specified SS pin. More info on extended methods: Due Extended SPI usage

Oh yeah so it does.... :blush: