SPI slave on teensy 4.1

Hi all,

I've configured an SPI peripheral as a slave. I can read correctly the bytes that the master sends me, but I can't reply.
RT1060 manual says it's possible to have a full duplex transfer in slave mode (see manual, p. 2855).

Is it possible to make the slave reply in a "dynamic manner" to the master? In particular, according to the byte received on the MISO line (master's MOSI), I would like to reply with different values on the MOSI line (master's MISO).

In pseudocode:
Code:
ISR():
  while (PCS asserted):
    wait for byte reception
    rx = RDR
   
    if (rx == 10):
      TDR = 3
   else: 
      TDR = 4

On an Arduino UNO, you can do something like this:
C++:
ISR(PCINT0_vect) {
    // check if SS is asserted
    while (digitalRead(SS) != HIGH) {
        /* As one byte has been completely shifted, the end of transmission flag, SPIF is set.
        We wait for the flag to be set. */
        while (!(SPSR & (1 << SPIF))) {
            // if SS went high, give up
            if (PINB & (1 << 2)) {
                return;
            }
        }
        /* store SPI Data Registry value in a buffer */
        const uint8_t rx = SPDR;
        
        /* reply with some logics */
        switch (rx) {
        case 10: 
            SPDR = 3;
            break;
        default:
            SPDR = 4;
            break;
        }
    }
}

I can't find any example and I'm not expert enough to fully understand how to get this done (and if it can work somehow).

Is this possible on a teensy 4.1?

Thanks,
Luca
 
Teeny 4.x in slave mode doesn't support generating output data mid-transfer. All data to be sent has to be in the transmit FIFO before the master asserts CS (begins a transfer).
 
Teeny 4.x in slave mode doesn't support generating output data mid-transfer. All data to be sent has to be in the transmit FIFO before the master asserts CS (begins a transfer).
Is there any older teensy version that support this working mode?

Do you know any of other micro that can do something like this?

Thank you :)
Luca
 
Standard SPI hardware in microcontrollers doesn't usually support it - you could bit-bang directly if the SPI clock is slow enough.
 
Standard SPI hardware in microcontrollers doesn't usually support it - you could bit-bang directly if the SPI clock is slow enough.
I naively though that since ATMEGA328P supports it, it is something easily supported by others.

My clock is slow enough that an Arduino UNO can reply correctly (see picture below) to all master transactions using interrupts, not sure if I can bit bang it.


Arduino replying:
1734950456245.png
 
Back
Top