I try to convert an existing Teensy 2.0 application to Teensy 3.0 and I face some issues. The code shift out data on the SPI line, and looks like this:
This code works fine on a teensy 2 and hangs on the teensy 3. if I change the isr code to:
it also works - but of course this code run's slower. I also experimenting with additional SPI_LOAD_BYTE(0); and delay, for example like this:
without success... Any hints why my isr code hangs?
best regards
michu
Code:
#define SPI_LOAD_BYTE(data) SPDR=data
#define SPI_WAIT_TILL_TRANSMITED while(!(SPSR & _BV(SPIF)))
static void isr2() {
SPI_WAIT_TILL_TRANSMITED;
SPI_LOAD_BYTE(0);
SPI_WAIT_TILL_TRANSMITED;
SPI_LOAD_BYTE(0);
}
void startSPI(uint8_t divider) {
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(divider); // 0.25 MHz
SPI_LOAD_BYTE(0);
}
void setup() {
startSPI(SPI_CLOCK_DIV32);
REGISTER_ISR_TIMER(isr2(), 32ms); //call isr method each 32ms
}
This code works fine on a teensy 2 and hangs on the teensy 3. if I change the isr code to:
Code:
static void isr2() {
SPI_LOAD_BYTE(0);
SPI_WAIT_TILL_TRANSMITED;
SPI_LOAD_BYTE(0);
SPI_WAIT_TILL_TRANSMITED;
}
Code:
void setup() {
startSPI(SPI_CLOCK_DIV32);
delay(200);
SPI_LOAD_BYTE(0);
REGISTER_ISR_TIMER(isr2(), 32ms); //call isr method each 32ms
}
without success... Any hints why my isr code hangs?
best regards
michu