Keep clocking out in SCLK (without blocking) when not using SPI
Posted: 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:
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?
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;
}
These 2 phases are one after the other and cyclical (1Hz).
I'm struggling with the 2nd phase. Any ideas?