Page 1 of 1

ESP32C3 > SPI > Single Transfer Mode

Posted: Fri Dec 20, 2024 5:54 pm
by BugSimpson
I have another question about the SPI interface in single transfer mode.

You can fill the registers from SPI_W0_REG - SPI_W15_REG with data.

When I call my function, it sends the contents of SPI_W0_REG, but SPI_W1_REG is also filled with data.

How does it work that it also sends the second register?

Code: Untitled.c Select all


void spi_write_bytes( uint8_t *_data, uint8_t _length )
{
if (_length > 64)
{
_length = 64;
}

uint32_t words = (_length + 3) / 4; //16 max
uint32_t wordsBuf[16] = {0};
uint8_t *bytesBuf = (uint8_t *)wordsBuf;

for (uint8_t i = 0; i < _length; i++)
{
*bytesBuf++ = *_data++;
}

REG_WRITE( SPI_MS_DLEN_REG, ( 8 * _length ) -1 );

for (uint8_t i = 0; i < words; i++)
{
REG_WRITE( SPI_Wn_REG( i ), wordsBuf[i] );
}

REG_SET_BIT( SPI_CMD_REG, SPI_UPDATE_bm );
while ( REG_READ( SPI_CMD_REG ) & SPI_UPDATE_bm );

REG_SET_BIT( SPI_CMD_REG, SPI_USR_bm );
while ( REG_READ( SPI_CMD_REG ) & SPI_USR_bm );

spi_poll_trans_done_int();
}