Skip to main content
Explorer II
November 9, 2023
Solved

STM32F401 SPI CLK not working

  • November 9, 2023
  • 3 replies
  • 3708 views

Hi guys,

I'm currently working on a project where I need to use the SPI protocol. 

After setting everything up in the .ioc file and generating the code. I wanted to check if the clock signal was properly working. So i hooked up my ossciloscop to the clk pin. To my surprise there was nog clk signal being generated.

 

I've attached a few pictures of the ioc view asswel as the code.

Could you guys help me out on this one?

 

Kind regards Erik

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    Incrementing from 23 to the integer limit. Probably getting a Hard Fault and not getting to the HAL_SPI_Transmit() at all.

    Hint: not i++

    3 replies

    djerikosAuthor
    Explorer II
    November 9, 2023

    Sorry guys forgot the photos

    Graduate II
    November 9, 2023

    You'll need to be Transmitting something to get clocks.

    It would be more helpful to show the code configuring the SPI, peripherals, pins, clocks, and the code transmitting, perhaps a 0x55 pattern, in a continuous loop.

    djerikosAuthor
    Explorer II
    November 9, 2023

    These are the files with the code, i'm trying to build the same project as Controllerstech in this video:

    https://www.youtube.com/watch?v=71SRVEcbEwc

    Graduate
    November 9, 2023

    The for loop in this function doesn't look too good...

     

    void ws2812_spi (int GREEN, int RED, int BLUE)
    {
    	uint32_t color = GREEN<<16 | RED <<8 | BLUE;
    	uint8_t sendData[24];
    	int indx = 0;
    
    	for (int i=23; i>=0; i++)
    	{
    		if(((color>>i)&0x01) == 1) sendData[indx++] = 0b110;
    		else sendData[indx++] = 0b100;
    	}
    
    	HAL_SPI_Transmit(&hspi1, sendData, 24, 1000);
    }

    Graduate II
    November 9, 2023

    Incrementing from 23 to the integer limit. Probably getting a Hard Fault and not getting to the HAL_SPI_Transmit() at all.

    Hint: not i++