lucamacavero
Member
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:
On an Arduino UNO, you can do something like this:
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
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