Help on SPI for Uno Wifi Rev. 2

I am trying to communicate to my Uno Wifi Rev. 2 via SPI from my Nano 33 BLE Sense. I have tested that using the same code on the Nano, which is the master, I can send and receive a byte to and from my Uno (the simple Uno board). After reading the datasheet for the ATMega 4809 and digging through the SPI library for that chip and some other files, I managed to write some code that will put the Uno Wifi to SPI slave mode and when it reads a single character it will send another character through SPI to the Nano. However, I am getting no response whatsoever from that board. I have tried using interrupts and also checking the Receive complete flag in the Interrupt Flags register but to no avail. Here's my code:

volatile char received;
volatile char response = 'A';
volatile bool read;
 
void setup()
{
    Serial.begin(115200);

    pinMode(SS, INPUT);
    pinMode(MOSI,INPUT);
    pinMode(MISO, OUTPUT);
    pinMode(SCK, INPUT);
 
    //enable SPI
    SPI0.CTRLA |= SPI_ENABLE_bm;
 
    //enable interrupts
    SPI0.INTCTRL |= SPI_IE_bm;
 
    SPI0.DATA = response++;
    read = false;
}
 
void loop(void){

    //wait to receive a byte
    /*while(!(SPI0.INTFLAGS & SPI_RXCIF_bm));
 
    received = SPI0.DATA;
 
    SPI0.DATA = response++;
 
    if(response > 'Z') response = 'A';*/

 
    if(read){
        Serial.print("Data received: ");
        Serial.print(received);
        Serial.println();
        read = false;
    }
}

//Interrupt service routine for SPI interrupts
ISR(SPI0_INT_vect){
    read = true;
    received = SPI0.DATA;
    SPI0.DATA = response++;
    if(response > 'Z') response = 'A';
}

Any help on this appreaciated! Thanks in advance!

I figured what was happening after all. The default SPI pins for the ATmega4809 are PORTA 4-7 and and in order to use the digital pins 8, 10-13 on the board which are PORTE 0-3, I had to use the port multiplexer first thing in setup():

PORTMUX_TWISPIROUTEA |= PORTMUX_SPI0_ALT2_gc;

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.