cancel
Showing results for 
Search instead for 
Did you mean: 

Using SPI with DMA

BTurc.2
Senior

Hi All, I'm using an STM32F1 with a 240x240 LCD screen that comunicates with the micro by SPI (with DMA). The screen uses the ST7789 driver (I supose it is not important). I'm working with RGB565 color format.

The problem that I have is, for example, when I'm using the ST7789_Fill_Color(YELLOW); the SPI uses the DMA and the LCD shoul be yellow but it's not. If yellow is 0b1111 1111 1110 0000 the DMA only sends to SPI the LSB (0b0000 0000 1110 0000) witch is a wrong color.
When I do the same without DMA it work's fine!

The DMA is configures this way:

BTurc2_0-1688298032648.png

I tried every configuration possible but nothing works. My question is why the DMA only graps the first byte of a color and what I have to change in order to send the real color.

Thanks in advance!!!

 

1 ACCEPTED SOLUTION

Accepted Solutions

Sorry for wasting your time. I found the problem. It is not the DMA fault. The problem is with the library of the LCD.

Thanks all for the help!!

View solution in original post

19 REPLIES 19
Arman Ilmak
Senior

Hi.

Is your spi peripheral configured correctly?

Do you see any DMA error?

Could you share code?

The SPI is configured as so:

BTurc2_0-1688302636605.png

Maby something it is not configured propertly because I have this error:

BTurc2_1-1688302895891.png

This error sometimes dissapears and I don't know why!

Thanks for the help!

 

Arman Ilmak
Senior

As i can see the spi is configured as 8 bit data size and your dma is 16bits.

Make spi 16 bits and see if it works.

Maybe sharing inside of the function st7768_writedata would help much better.

you didnt set memory increment - so dma just doing 1 transfer . not very useful...

AScha3_0-1688306444836.png

check "memory" !

If you feel a post has answered your question, please click "Accept as Solution".

Initially I had it marked. I have been doing tests and it stayed unchecked. But the same thing happens.

Initially the DMA was configured at 8 bit but doing tests I changed It. The st7769_witedata():

static void ST7789_WriteData(uint8_t *buff, size_t buff_size)
{
ST7789_Select();
ST7789_DC_Set();
 
// split data in small chunks because HAL can't send more than 64K at once
 
while (buff_size > 0) {
uint16_t chunk_size = buff_size > 65535 ? 65535 : buff_size;
#ifdef USE_DMA
if (DMA_MIN_SIZE <= buff_size)
{
HAL_SPI_Transmit_DMA(&ST7789_SPI_PORT, buff, chunk_size);
while (ST7789_SPI_PORT.hdmatx->State != HAL_DMA_STATE_READY)
{}
}
else
HAL_SPI_Transmit(&ST7789_SPI_PORT, buff, chunk_size, HAL_MAX_DELAY);
#else
HAL_SPI_Transmit(&ST7789_SPI_PORT, buff, chunk_size, HAL_MAX_DELAY);
#endif
buff += chunk_size;
buff_size -= chunk_size;
}
 
ST7789_UnSelect();
}
Rodo
Senior

How is "disp_buf" declared? You may need to use "&" when calling ST7789_Write_Date ... like :

ST7789_Write_Date(&disp_buf,...

Sorry for wasting your time. I found the problem. It is not the DMA fault. The problem is with the library of the LCD.

Thanks all for the help!!

Hello @BTurc.2 .
I'm having the same problem as you. And I'm thinking it's the ST7789 library because everything else in my code is correct or as in the example. So you changed the library?

Would it be possible for you to send me your library? Or would it be possible to send me a github link?