earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
1.96k stars 406 forks source link

SPISlave getting data without shift on the FIFO queue depth #2314

Closed chelyuk closed 1 month ago

chelyuk commented 1 month ago

I need to create a program for SPI slave which should send response appropriately depends on receive bytes.

I am using the following approach:

void recvCallback(uint8_t *data, size_t len)
{
    memcpy((uint8_t* )recvBuff, data, len);
    gLen = len;
    sentBack = true;
}

void sentCallback()
{
        if (recvBuff[0] != 0)
        {
            SPISlave1.setData((uint8_t* )recvBuff, gLen);
        }
        else
        {
            SPISlave1.setData(DUMMY, sizeof(DUMMY));
        }
}

But at first master got 8 dummies and only then starting the communication with the 8 bytes shift. As far as I understand I need to disable the bit TXMIS for SPI: SSPMIS Register (Datasheet p. 521)

Could you advise is it possible with SPISlave library? Or what is proper way with SPISlave to achieve response with 1 byte delay and not with the whole FIFO queue depth?