cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous data transfer via SPI.

MMust.5
Senior II

I am using the code from this post to connect STM32F407  to ili9341 display 

TFT_DC_SET(); Enables recording of data to the display.

The speed for transferring data to the display is very important, so I need continuous data transfer.

 

The SPI_SR_BSY bit is responsible for continuous data transmission via SPI.
I don’t know how to write a function correctly to organize continuous data transfer and ensure safe execution of the function.

If I use such a function, then continuous data transfer is impossible, because the function contains
while((SPI1->SR & SPI_SR_BSY));

 

void TFT_SendData(uint8_t data)
{
while((SPI1->SR & SPI_SR_BSY)); //Here I wait while the SPI is busy. Because I can't change the state of TFT_DC_SET(); if SPI is busy.
TFT_DC_SET();
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = data;
while(!(SPI1->SR & SPI_SR_TXE));
while((SPI1->SR & SPI_SR_BSY)); //Here I wait while the SPI is busy in order to secure code execution outside the function.
}

 

For continuous data transfer, this code is required:

 

void TFT_SendData(uint8_t data)
{
TFT_DC_SET();
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = data;
while(!(SPI1->SR & SPI_SR_TXE));
}

 

But this code will not be safe.
Before TFT_DC_SET(); It does not check whether SPI is busy.
And after data transmission, it is not checked whether the SPI is busy.

I can check outside the function while((SPI1->SR & SPI_SR_BSY)); But then why do I need a function at all if I can’t put everything into it.

 

void TFT_SendData(uint8_t data)
{
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = data;
while(!(SPI1->SR & SPI_SR_TXE));
}

while((SPI1->SR & SPI_SR_BSY)); //Check that SPI is busy outside the function.
TFT_DC_SET(); //Enable data recording to the display.
TFT_SendData(data) ; //Continuous data transfer via SPI.
TFT_SendData(data) ; //Continuous data transfer via SPI.
TFT_SendData(data) ; //Continuous data transfer via SPI.
TFT_SendData(data) ; //Continuous data transfer via SPI.
TFT_SendData(data) ; //Continuous data transfer via SPI.
TFT_SendData(data) ; //Continuous data transfer via SPI.
//!!!!!The task is that I need to somehow see that data transmission via SPI ends here and I need to wait until the SPI_SR_BSY flag takes the value zero.
while((SPI1->SR & SPI_SR_BSY)); //Check that SPI is busy outside the function.

 

I need to find the last byte that was transmitted and only after this byte do I need to wait for the SPI_SR_BSY flag to take the value zero.

I think this can’t be done, then I need to find some way that will simplify the code so that for continuous transmission via SPI I don’t have to write while((SPI1->SR & SPI_SR_BSY)); outside the function.

Skx5i.jpg

1 REPLY 1
Uwe Bonnes
Principal II

Several options: -Wait for SPI_SR_TXE instead of waiting for not busy.  Only wait for not busy at the end of the block. - Write the batch of code to send in a block of RAM and use DMA transfer for continuos SPI transfer.