Skip to main content
Graduate
August 7, 2024
Solved

How can I interface an LCD with an STM32L412RBT6P microcontroller using SPI and DMA?

  • August 7, 2024
  • 3 replies
  • 5741 views

Hi,

I have an STM32L412RBT6P microcontroller and a CFAG12864T3-NFH LCD which uses an ST7565 controller. I want to use SPI to communicate with the LCD and leverage DMA to efficiently transfer data with lowest current consumption possible. Could someone provide an example code or any helping notes on how to set this up? Specifically, I'm looking for:

1. Initializing the SPI peripheral on the STM32L412RBT6P for communication with the ST7565 controller.

2. Configuring DMA to handle data transfers from memory to the SPI peripheral.

3. Sending initialization commands and data to the LCD with ST7565.

Any help would be greatly appreciated!

    This topic has been closed for replies.
    Best answer by MM..1

    1. I mean no SPI clock is based on PCLK2 then in transfer time PCLK must be 2x SPI speed. After transfer can swith down...

    MM1_0-1723562170654.png

    2. Too NO.

    3. Use partial update method for screen and switch to low power after transfer changes.

    By energy law is irelevant if you use low SPI speed with low current long time vs high speed short time. Avoid animation at all.

    L4 is SPI 1.3.x hw

    Specific handling of autonomous SPI operation in low power modes is out of this document scope. Version 2.x.x
    is capable to drive serial bus clocking in stop mode while raising asynchronous interrupts to handle data
    exchange. Version 3.x.x, additionally, can handle the data exchange between the peripheral and memory via
    smart DMA if implemented in the product. This is done without need for system wake-up, due to temporal
    domain's clock requests handled by the peripheral while the data transfers can be synchronized with other
    peripherals by internal triggers. Refer to documents targeting LPBAM control, such as AN5645 "STM32U5 Series
    power optimization using LPBAM" Guidelines for enhanced SPI communication on STM32 MCUs and MPUs - Application note

    3 replies

    Graduate II
    August 7, 2024

    It is probably possible to do something, either in a circular manner, or processing a linked-list or scatter-gather type mechanism.

    ST doesn't really have a slick way of managing the Chip Select pin, which complicates general purpose solutions.

    It's perhaps unrealistic to expect others to do your work and analysis and furnish you with a solution for a pair of parts you've chosen.

    There should be SPI+DMA examples amongst the CubeL4 code trees for the assorted DISCO or EVAL boards. The mechanics and associativity is covered in the Reference Manuals

    Zaim01Author
    Graduate
    August 8, 2024

    Hi Tesla DeLorean,

    I appreciate your response, but I’d like to clarify a few points. Firstly, while I understand the theoretical concepts like circular or scatter-gather mechanisms, I'm looking for concrete examples specific to the STM32L4xx and ST7565. Practical guidance is more helpful than theoretical suggestions.

    Regarding the management of the Chip Select (CS) pin, I agree it can be tricky. However, many in the community have likely faced and solved this issue. Sharing specific advice or examples would be valuable.

    I want to address the assumption that I expect others to do my work. That is not the case. This community is here to help each other, and many members have similar questions and benefit from shared solutions. My question is in line with the community's purpose.

    The ST7565 LCD controller is quite common, and I believe others have interfaced it with STM32 MCUs. Sharing practical experiences and solutions is what this community is about.

    While I’m looking into CubeL4 examples, specific guidance on adapting them to my setup would still be highly appreciated. This community exists for ST product users to support each other. If someone has experience with this setup, sharing practical examples or detailed steps would help many of us.

    Thanks

    Super User
    August 8, 2024

    Hi,

    here an example, just set your pins and spi you use...

    https://github.com/ArsalanAliMujtaba/ST7565-ST7565P-COG-3-Inch-LCD-Library-for-STM32Cube-IDE

     

    + DMA for such small display ? ...at first get it running without DMA.

     

    Zaim01Author
    Graduate
    August 8, 2024

    Thank you for your recommendations.

     

    Actually, I have used this library before and successfully got the LCD working with the MCU, and it's still functioning well with a CPU clock of 16 MHz. However, my application is focused on low power consumption, which is why I am trying to reduce the clock frequency to 1 MHz or even lower. 

     

    When I lower the clock speed, the system continues to operate correctly, but the text on the LCD becomes difficult to read and lacks fluency. After some research, I found that using DMA to handle the LCD could allow the CPU to enter low-power modes while the DMA manages the display updates. This approach seems like it could help maintain the performance of the display even at reduced clock speeds.

     

    Do you have any further insights on implementing DMA for this purpose, or suggestions on other methods to optimize the display performance for low-power applications?

    Graduate II
    August 8, 2024

    As first in normal run mode create display flush with SPI and DMA. After this work handle switch into low power modes with SPI ... supported is only Sleep , LP Run and LP Sleep. Read STM32L4 and STM32L4+ ultra-low-power features overview

    ST Employee
    August 9, 2024

    Hello @Zaim01,

    Here are some links from STMicroelectronics that can help you write code to configure and use SPI with DMA on STM32 microcontrollers, as well as specific examples for LCD screens using the ST7565 controller:

    • AN4776 Application Note: This document explains in detail how to configure and use the DMA controller on STM32 microcontrollers.
    • AN5050 Application Note: This guide helps you get started with STM32CubeMX to configure peripherals and generate initialization code.
    • STM32CubeL4 Firmware Package: This package contains code examples, libraries, and demonstration projects for STM32L4 microcontrollers. You can find specific examples for SPI and DMA.

    Additionally, here are some corrected and verified links for articles on STM32 SPI and using DMA with STM32:

    I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

    Thanks for your contribution.

    Dor_RH