I'm trying to get SPI1 working on Teensy-LC. For now I'm using the library functions, though I eventually want to start using the SPI FIFO. Here's a program that I think demonstrates my problem. I have pin 21(MOSI1) jumpered to pin 5(MISO1). Since I'm sending 3 bits of 1, I should receive 0x010101 as my result, but instead I'm getting 0xFFFFFF. In addition, if I ground pin 5(MISO), I still get 0xFFFFFF. Looking at the pins with my scope, I get a clock signal on pin 20, the CS signal on pin 6 is toggling correctly, but I get no signal on pin 21(MOSI). So it's almost like SPI1 is not wired to the port pins. Uncommenting SPI1.setMISO(5) and SPI1.setMOSI(21) in the program doesn't help.
Code:
// Hardware: Teensy-LC, jumper connecting pin 21 (MOSI1) to pin 5 (MISO1)
#include <SPI.h>
#define cs 6
unsigned long readADC(){
int i;
unsigned long adcdata = 0;
digitalWrite(cs, LOW);
for (i=0; i<3; i++) adcdata = (adcdata << 8) + SPI1.transfer(1);
digitalWrite(cs, HIGH);
return adcdata;
}
void setup(){
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH);
SPI1.begin();
//SPI1.setMISO(5);
//SPI1.setMOSI(21);
SPI1.beginTransaction(SPISettings(2400000ul, MSBFIRST, SPI_MODE0));
Serial.begin(9600);
delay(1000);
}
void loop(){
char c;
if (Serial.available()){
c = Serial.read();
switch(c){
case 'r':
Serial.println(readADC()); // read once to display in serial monitor
break;
case 's':
Serial.println("Now reading continuously, press a key to stop");
while(!Serial.available())
readADC(); // read continuously to look at oscilloscope
break;
}
}
}