Keep clocking out in SCLK (without blocking) when not using SPI

leleroy
Posts: 4
Joined: Sat Dec 17, 2022 6:17 am

Keep clocking out in SCLK (without blocking) when not using SPI

Postby leleroy » Sat Dec 17, 2022 6:24 am

The SPI slave device is half-duplex and requires two different phases:

1. Sending it command via SPI - done and understood and done by:

Code: Select all

uint8_t spiTransferByte(spi_t * spi, uint8_t data)
{
    if(!spi) {
        return 0;
    }
    SPI_MUTEX_LOCK();
    spi->dev->mosi_dlen.usr_mosi_dbitlen = 7;
    spi->dev->miso_dlen.usr_miso_dbitlen = 7;
    spi->dev->data_buf[0] = data;
#if CONFIG_IDF_TARGET_ESP32C3
    spi->dev->cmd.update = 1;
    while (spi->dev->cmd.update);
#endif
    spi->dev->cmd.usr = 1;
    while(spi->dev->cmd.usr);
    data = spi->dev->data_buf[0] & 0xFF;
    SPI_MUTEX_UNLOCK();
    return data;
}
2. Immediately after sending it the command, I need to keep clocking pulses in the SCLK (in the same SPI frequency). This shouldn't block the CPU because I need to do other tasks.

These 2 phases are one after the other and cyclical (1Hz).

I'm struggling with the 2nd phase. Any ideas?

leleroy
Posts: 4
Joined: Sat Dec 17, 2022 6:17 am

Re: Keep clocking out in SCLK (without blocking) when not using SPI

Postby leleroy » Thu Dec 22, 2022 5:18 am

Using RMT is probably the right way to go!
No CPU load.

Code: Select all

https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/rmt.html#resource-allocation

Who is online

Users browsing this forum: No registered users and 103 guests