Skip to main content
Visitor II
February 8, 2024
Solved

STM32F103C8 using SPI2

  • February 8, 2024
  • 30 replies
  • 14200 views

Hello,

i am trying to interface 1.8 inch SPI TFT Display 128 x 160 to the STM32F103C8 using SPI2.

https://www.az-delivery.de/products/1-8-zoll-spi-tft-display

SPI1 is used for LoRa, i thought to connect TFT too to SPI1 using addresses but i am affraid to influence the

LoRa.

The library which i am using is from this website:
https://controllerstech.com/st7735-1-8-tft-display-with-stm32/

A year earlier i tried to interface LoRa to STM32F103C8 using SPI2 but without success.

Is it a general problem in STM32F103C8 using SPI2?

Any help is appreciated.

    This topic has been closed for replies.
    Best answer by hamo

    The problem was with the hardware.
    Finally i could get the SPI2 work together with SPI1 on the same Board.
    Many Bluepills are just not good this days.

    Anyway thank you all for being helpful.

    Best regards

    Mohamad

    30 replies

    Super User
    February 8, 2024

    @hamo wrote:

    Is it a general problem in STM32F103C8 using SPI2?


    No - it shouldn't be.

    hamoAuthor
    Visitor II
    February 8, 2024

    Then what is the problem

    Here is how i configured the stm32f103 usnig STM32CubeMX:

    SPI2.JPG

    Super User
    February 8, 2024

    @hamo wrote:

    Then what is the problem


    No idea!

    All you've said is that you failed with it previously - we have no way to tell what you were doing wrong.

    What debugging did you do? What did you discover?

     

    hamoAuthor
    Visitor II
    February 8, 2024

    Has someone had success with SPI2 interfacing anything to stm32?

    I am using KEIL IDE, it freezes as soon as it reaches HAL_SPI_Transmit().

    No idea why?

    Super User
    February 8, 2024

    So, again, what debugging have you done to find why it's freezing?

    Have you stepped into  HAL_SPI_Transmit() to see what's happening ?

    Have you looked at the SPI lines to see what's happening?


    hamoAuthor
    Visitor II
    February 9, 2024

    No, i stoped by HAL_SPI_Transmit(). It was late yesterday.
    Today i am going to debug it correctly and i will post the results here.
    My clock frequenz is max 72MHz and i looked at block diagram of blue pill and saw that SPI2 is on APB1 which has max 36MHz, so shall i change the cinfiguration in any way different than SPI1?

    Super User
    February 9, 2024

    @hamo wrote:

     i looked at block diagram of blue pill and saw that SPI2 is on APB1 


    "Blue Pill" is just a board; it doesn't affect the internals of the chip - that remains the same irrespective of what board it's mounted on!

    You need to be looking at the chip documentation - Datasheet and Reference Manual.

    https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#documentation 

    But, yes - getting the clock configurations correct is essential to everything!

    You say you're using STM32CubeMX - the 'Clock Configuration' tab there will flag any clock setting issues ...

    hamoAuthor
    Visitor II
    February 11, 2024

    Hello,

    i have debugged it and found out that when goes into hal_spi_transmit() it initilaize every thing correct and when it try to transmit the data it chosses to transmit data in 8 bit mode (which is correct) it waits till TXE flag is set to send data, but goes to time out which means that TXE flag is not set (i think).

    It keeps stuck there. I have tried to change RESET, CS and DC pins but without success.SPI2_debugging_1.JPG

    Super User
    February 12, 2024

    Read out and check/post content of SPI and relevant GPIO/AFIO registers.

    Observe SPI pins. Do you see SCK toggling?

    JW

    hamoAuthor
    Visitor II
    February 13, 2024

    Hello @waclawek.jan 

    i have used logic analyzer and figured out that there is no clock.

    Here is a capture of the SPI2:

    SPI2_Com.JPG

     

    The only toggle is when i reset the bluepill.

    Super User
    February 13, 2024

    What code is this?

    Have you got a basic SPI example working on SPI2?

    hamoAuthor
    Visitor II
    February 13, 2024

    This code is to make ST7735 TFT work.

    Which example do you mean?

    Super User
    February 13, 2024

    You just need the simplest SPI example you can find - one which does just SPI and nothing else.

    You need to get the basic comms working before adding complications like a TFT display!

    Otherwise you won't know if the problems are with the SPI itself, or elsewhere in all the mountains of other code.

    ST publishes basic peripheral examples; eg, in the Cube IDE ...

     

    EDIT:

     

    https://www.st.com/en/embedded-software/stm32cubef1.html

     

    hamoAuthor
    Visitor II
    February 13, 2024

    @AScha.3  thanks for for your reply.

    can you please share your STM32CubeMX settings?

    @Andrew Neil  thanks, i will do that surely

    Super User
    February 13, 2024

    My spi2 setting:  (+ pin speed: high )

    AScha3_0-1707838168356.png

     

     

    hamoAuthor
    Visitor II
    February 13, 2024

    @AScha.3 

    and which pins do you use for CS, RESET and DC?

    Are you clocking at max 72 MHz?

    Super User
    February 13, 2024

    Yes , core at 72 M.

    CS.. are just any I/O pins, that are close (for wiring...i hate, to have a wire cross the board. :) )