uint32_t ctar0, ctar1, ctar_slave, mcr;
bool serialPrint_ONS=LOW;
long clkCTU=0;
unsigned long serialTMR=0;
void setup(){
Serial.begin(57600);
SPCR =0x40; // |= _BV(SPE); //From Arduino, dosn't work without it??
SPI0_MCR = 0x01000400;
SPI0_RSER = 0x00000000;
SPI0_CTAR0_SLAVE = 0x38000000; //0x11000000;
//take clock off pin 13
CORE_PIN13_CONFIG = PORT_PCR_MUX(1);
//put clock on pun 14
CORE_PIN14_CONFIG = PORT_PCR_DSE | PORT_PCR_MUX(2);
pinMode(SS, INPUT); //Pin 10
pinMode(MISO, INPUT); //Pin 12
pinMode(14, INPUT); //Clock
}
void loop(){
if (digitalReadFast(14)){
clkCTU++;}
if (serialPrint_ONS == LOW){
serialTMR = millis();
serialPrint_ONS = HIGH;}
if(millis() - serialTMR > 1000){
//These numbers show what bit you are looking at
Serial.println(" 33222222222211111111110000000000");
Serial.println(" 10987654321098765432109876543210");
Serial.println(" --------------------------------");
//Zeros are uses for placeholders
Serial.print("SPIO_MCR: 0000000");
Serial.println(SPI0_MCR,BIN);
Serial.print("SPIO_CTAR0_SLAVE: 00");
Serial.println(SPI0_CTAR0_SLAVE,BIN);
Serial.print("SPI_SR: 0");
Serial.println(SPI0_SR,BIN);
Serial.print("SPI_RSER: 0000000000000000000000000000000");
Serial.println(SPI0_RSER,BIN);
Serial.println(" --------------------------------");
Serial.print("SPI_RXFR ");
Serial.println(SPI0_RXFR0,BIN);
Serial.print("Clock (not accurate) ");
Serial.println(clkCTU);
Serial.println();
Serial.println();
Serial.println();
serialPrint_ONS = LOW;
}
}
What Logic Analyzer do you use? I want to get one.
Saleae probably runs much better on Windows, maybe Mac too? But if you use Linux, the software is so buggy it's pretty much unusable.
Here's what I have so far. The slave is interrupt based, but it works at 24Mhz (I don't have an oscope so I can't verify that I'm clocking 24Mhz). It works for 8 & 16 bits.
The examples serial.print several transfer statistics.
@ 24MHz, On 16 bit transfers, 1000 transfers per packet, looping 500 times, I get 1.25 MBpS (my FOR loop is probably slowing it down a lot).
The Slave is using the clock input on pin14, Master clock is pin13.
ChipSelect pin is 10 on both Master and Slave.
DataOut is Pin11 on the master.
DataIn is pin12 on the slave.
I have not set it up yet for slave to master transfers, so it is currently one-way master to slave. I intend to post some updates, make the library more universal, use other CTAR's, CS pins, and enable slave to master transfers. Please post or message any questions or comments. And feel free to suggest changes.
Teensy3.0 SPI Master & Slave Set (on GitHub)
What Logic Analyzer do you use? I want to get one.
I have uploaded a more complete library for using SPI master & slave.
Teensy 3.0 Master & Slave (on GitHub)