esp32c3 > spi > send words fail

BugSimpson
Posts: 22
Joined: Fri Oct 11, 2024 2:14 pm

esp32c3 > spi > send words fail

Postby BugSimpson » Thu Dec 19, 2024 10:52 am

Hello,

Why is the last data packet (see picture) always one of the next transmission?

Code: Untitled.c Select all


void spi_write_words( uint16_t * _data, uint8_t _length )
{
if( _length > 16 ) _length = 16;

REG_WRITE( SPI_MS_DLEN_REG,( ( 16 * _length) -1 ) );
spi_write_buffer( (uint32_t*)_data, _length );

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 ){};
}

Code: Untitled.c Select all


void max7219_write( uint16_t* _data, uint8_t _length )
{
spi_write_words( _data, _length );
}

Code: Untitled.c Select all


    while (1)
{
uint16_t *pData, buffer[ 4 ];
pData = buffer;

for (uint8_t i = 0; i < 4; i++)
{
*pData++ = REG_DISPLAY_TEST << 8 | 1;
}
max7219_write( buffer, 4 );


pData = buffer;

for (uint8_t i = 0; i < 4; i++)
{
*pData++ = REG_DISPLAY_TEST << 8 | 0;
}
max7219_write( buffer, 4 );
}
sni.JPG
sni.JPG (86.12 KiB) Viewed 2011 times

MicroController
Posts: 2663
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: esp32c3 > spi > send words fail

Postby MicroController » Thu Dec 19, 2024 12:39 pm

Why is the last data packet (see picture) always one of the next transmission?
Maybe a bug in some other code?

Code: Select all

  spi_write_buffer( (uint32_t*)_data, _length );
should probably be

Code: Select all

  spi_write_buffer( (uint32_t*)_data, _length/2 );

BugSimpson
Posts: 22
Joined: Fri Oct 11, 2024 2:14 pm

Re: esp32c3 > spi > send words fail

Postby BugSimpson » Thu Dec 19, 2024 6:16 pm

The number of bytes is correct. Is it possible that there is still a bit that needs to be queried if the transmission is ready?

Who is online

Users browsing this forum: ChatGPT-User, PerplexityBot and 2 guests