Hi, had a function that draws a filled rectangle on the screen using SPI. I use to be able to send a 16 bit value "n" times but had to change it ATM to send a 256 byte buffer multiple times.
Even though I used SPI.transfer(buffer, count) the contents of the buffer were getting 0'ed after the first iteration. After looking at the code I can see why.
Unless I can be corrected, because the buffer is passed to both RX and TX the buffer will be overwritten by RX which is always 0's in my case.
Code with DMA workaround.
PS - Would be nice to have SPI.transfer16(val16, count) and SPI.transfer16(val16, count, resp1)
Even though I used SPI.transfer(buffer, count) the contents of the buffer were getting 0'ed after the first iteration. After looking at the code I can see why.
Unless I can be corrected, because the buffer is passed to both RX and TX the buffer will be overwritten by RX which is always 0's in my case.
Code with DMA workaround.
Code:
void cDMA_spi_send_value(uint8_t channel, uint16_t value, uint32_t n) // send a uint16_t multiple times
{
uint8_t buff[256 + 2];
buff[0] = value & 255;
buff[1] = value >> 8;
n *= 2;
int i = 0;
while (i <= 254)
{
buff[i + 2] = buff[0];
buff[i + 3] = buff[1];
i += 2;
}
cDMA_spi_send_do_wait_buffer(channel);
while (n >= 256)
{
dma_waiting = 1;
SPI.transfer(buff, NULL, 256, resp1);
n -= 256;
cDMA_spi_send_do_wait_buffer(channel);
}
if (n)
{
dma_waiting = 1;
SPI.transfer(buff, NULL, n, resp1);
cDMA_spi_send_do_wait_buffer(channel);
}
}
PS - Would be nice to have SPI.transfer16(val16, count) and SPI.transfer16(val16, count, resp1)