The code I posted in the attachment is part of a library that uses mode 0,LSB first SPI (and this is the reason why I don't use HW SPI).
Have you tried something like this?
// http://arduino.cc/en/Reference/DueExtendedSPI
#include <SPI.h>
void setup() {
SPI.begin(10); // can use pins 4, 10, or 52 for CS.
SPI.setClockDivider(10, 17); // 4.94 MHz SCK
SPI.setDataMode(10, SPI_MODE0);
SPI.setBitOrder(10, LSBFIRST);
}
void loop() {
byte response = SPI.transfer(10, 0xFF);
}
If you need to use completely different pins for SPI (and still use hardware SPI), then USART0 could be configured for SPI Master, Mode 0, LSB first as follows (untested):
/*-----------------------------
Signal SPI Master Arduino Pin
-------------------------------
RXD0 MISO RX1 19
TXD0 MOSI TX1 18
RTS0 CS D2 2
SCK0 SCK SDA1 70
------------------------------*/
void setup() {
Serial1.begin(9600); // pre-initialize USART0
USART0config(); // setup SPI mode, clock and pins
}
void loop() {
USART0->US_THR = 0xAA; // transfer byte 0xAA
delay(1000);
}
void USART0config() {
USART0->US_WPMR = 0x55534100; // Unlock the USART Mode register
USART0->US_MR |= 0x401CE; // SPI MODE0 (LSBFIRST), 8_BIT, SPI_MASTER
USART0->US_BRGR = 17; // Clock Divider (SCK = 4.94MHz)
PIOA->PIO_WPMR = 0x50494F00; // Unlock PIOA Write Protect Mode Register
PIOB->PIO_WPMR = 0x50494F00; // Unlock PIOB Write Protect Mode Register
PIOB->PIO_ABSR |= (0u << 25); // CS: Assign A14 I/O to the Peripheral A function
PIOB->PIO_PDR |= (1u << 25); // CS: Disable PIO control, enable peripheral control
PIOA->PIO_ABSR |= (1u << 17); // SCK: Assign A16 I/O to the Peripheral B function
PIOA->PIO_PDR |= (1u << 17); // SCK: Disable PIO control, enable peripheral control
PIOA->PIO_ABSR |= (0u << 10); // MOSI: Assign PA13 I/O to the Peripheral A function
PIOA->PIO_PDR |= (1u << 10); // MOSI: Disable PIO control, enable peripheral control
PIOA->PIO_ABSR |= (0u << 11); // MISO: Assign A12 I/O to the Peripheral A function
PIOA->PIO_PDR |= (1u << 11); // MISO: Disable PIO control, enable peripheral control
}
This should work for USART1 (untested):
/*-----------------------------
Signal SPI Master Arduino Pin
-------------------------------
RXD0 MISO RX2 17
TXD0 MOSI TX2 16
RTS0 CS D23 23
SCK0 SCK A0 54
------------------------------*/
void setup() {
Serial2.begin(9600); // pre-initialize USART1
USART1config(); // setup mode, clock and pins
}
void loop() {
USART1->US_THR = 0xAA; // transfer byte 0xAA
delay(1000);
}
void USART1config() {
USART1->US_WPMR = 0x55534100; // Unlock the USART Mode register
USART1->US_MR |= 0x401CE; // SPI MODE0 (LSBFIRST), 8_BIT, SPI_MASTER
USART1->US_BRGR = 17; // Clock Divider (SCK = 4.94MHz)
PIOA->PIO_WPMR = 0x50494F00; // Unlock PIOA Write Protect Mode Register
PIOB->PIO_WPMR = 0x50494F00; // Unlock PIOB Write Protect Mode Register
PIOA->PIO_ABSR |= (0u << 14); // CS: Assign A14 I/O to the Peripheral A function
PIOA->PIO_PDR |= (1u << 14); // CS: Disable PIO control, enable peripheral control
PIOA->PIO_ABSR |= (0u << 16); // SCK: Assign A16 I/O to the Peripheral A function
PIOA->PIO_PDR |= (1u << 16); // SCK: Disable PIO control, enable peripheral control
PIOA->PIO_ABSR |= (0u << 13); // MOSI: Assign PA13 I/O to the Peripheral A function
PIOA->PIO_PDR |= (1u << 13); // MOSI: Disable PIO control, enable peripheral control
PIOA->PIO_ABSR |= (0u << 12); // MISO: Assign A12 I/O to the Peripheral A function
PIOA->PIO_PDR |= (1u << 12); // MISO: Disable PIO control, enable peripheral control
}