Skip to main content
Graduate
July 25, 2025
Solved

H523 can't run HW SPI

  • July 25, 2025
  • 3 replies
  • 227 views

Hello,

 

I spend a lot of time to tried running HW SPI on H523CET6.  On the other mcu like F411 it work without any problems. In this case SPI work only when I do it in software mode:

//=====================================================================================
#define DO_LO	HAL_GPIO_WritePin(LCD_MOSI_GPIO_Port, LCD_MOSI_Pin, GPIO_PIN_RESET);
#define DO_HI	HAL_GPIO_WritePin(LCD_MOSI_GPIO_Port, LCD_MOSI_Pin, GPIO_PIN_SET);
#define CLK_LO	HAL_GPIO_WritePin(LCD_CLK_GPIO_Port, LCD_CLK_Pin, GPIO_PIN_RESET);
#define CLK_HI	HAL_GPIO_WritePin(LCD_CLK_GPIO_Port, LCD_CLK_Pin, GPIO_PIN_SET);
//=====================================================================================
static void Transmit_Byte(uint8_t transfer){
//==========================================================
#define HW_SPI
//==============
#ifdef HW_SPI
	extern SPI_HandleTypeDef hspi1;
	HAL_SPI_Transmit(&hspi1, &transfer, 1, 100);
//==========================================================
#else
uint32_t i;
	for(i = 0 ; i < 8 ; i++){
		if((transfer & 0x80) != 0) { DO_HI; }
		else { DO_LO; }
		CLK_LO;
		transfer =(transfer << 1);
		CLK_HI;
	}
#endif
//===========================================================
}

 

I'm not pretty sure what I should to do more for properly running SPI in H523. My setup looks like:

0.jpg

 

1.jpg

 

2.jpg

3.jpg4.jpg

UART1 on PA9/PA10 working without any problem, but the HW SPI doesn't.  IOC file in attachment. I'd look at this via oscilloscope. CLK look like work properly, also MOSI he's not dead. Should I do any additional configurations or so?

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

    A lot of work put in this. I'd make SPI check receiver and tested what arrive. The data was properly, but the LCD still doesn't work. 

    This seems to work as long as I programmatically set the CS line to 0 befor each HAL_SPI_Transmit invoke and to 1 after the procedure return.

    I would like to remind  that it worked without any problems on F411 HW/SW SPI and in the software SPI version (for H523), where the CS line was permanently pulled to 0.

    Solution would looks like below:

    //=====================================================================================
    #define CS_LO	HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_RESET);
    #define CS_HI	HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
    //=====================================================================================
    static void Transmit_Byte(uint8_t transfer){
    	extern SPI_HandleTypeDef hspi1;
    	CS_LO;
    	HAL_SPI_Transmit(&hspi1, &transfer, 1, 100);
    	CS_HI;
    }

     

    3 replies

    Super User
    July 25, 2025

    > CLK look like work properly, also MOSI he's not dead.

    So CLK works? and MOSI works? The heck does "MOSI he's not dead" mean? What isn't working about SPI then?

    Don't see how UART configuration is relevant here.

    wegi01Author
    Graduate
    July 25, 2025

    UART is example it work and can running on this same APB2 BUS. I don't have logic analyzer and don't see what exactly ongoing on the MOSI just I see the change of states. But at the end what doing properly via software SPI, it doesn't work properly via hardware SPI, I don't know why. Also a lot of new settings in H5 series confusing me.

    wegi01AuthorAnswer
    Graduate
    July 31, 2025

    A lot of work put in this. I'd make SPI check receiver and tested what arrive. The data was properly, but the LCD still doesn't work. 

    This seems to work as long as I programmatically set the CS line to 0 befor each HAL_SPI_Transmit invoke and to 1 after the procedure return.

    I would like to remind  that it worked without any problems on F411 HW/SW SPI and in the software SPI version (for H523), where the CS line was permanently pulled to 0.

    Solution would looks like below:

    //=====================================================================================
    #define CS_LO	HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_RESET);
    #define CS_HI	HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
    //=====================================================================================
    static void Transmit_Byte(uint8_t transfer){
    	extern SPI_HandleTypeDef hspi1;
    	CS_LO;
    	HAL_SPI_Transmit(&hspi1, &transfer, 1, 100);
    	CS_HI;
    }