cancel
Showing results for 
Search instead for 
Did you mean: 

SPI MOSI and SCK pulses on oscilloscope

ajimathew
Associate III

When I try to communicate my STM32L4P5-DK through SPI protocol. I fed the MOSI and SCK pin to the oscilloscope and checked the output there I got several doubts

1) when I send a data 0xAA to the slave ( HAl_SPI_Transmit(&hspi2,0xAA,1,10) ) with the baud rate of 187.5kBits/sec the time period was 5us app(each bit is shifted at falling edge as per my configuration) but here MOSI otput is not as expected     0xAA.jpeg

 

0xAA_.jpeg

2) when I try to send 0xFF the expected MOSI output is the MOSI pin should remain high for 8 falling edges of SCK but it was not that I got on the scope.The below picture shown the 0xFF data in  MOSI(Yellow) and SCK (Green)

0xFF.jpeg

 

3) also the SCK is not a continuous signal, SCK  maintains 0 for each 8 cycles with a regular period of time why?

 

1 ACCEPTED SOLUTION

Accepted Solutions
JTP1
Lead

Hello

Function HAL_SPI_Transmit second parameter must pointer to variable or array depending are you going to send one or several bytes.

Check here the basics how to use it:

https://controllerstech.com/how-to-use-spi-with-stm32/

Br J.T

View solution in original post

4 REPLIES 4
TDK
Guru

> HAl_SPI_Transmit(&hspi2,0xAA,1,10)

This is nonsense. The function wants a pointer to data.

uint8_t data[1] = {0xAA};
HAL_SPI_Transmit(&hspi2, data, 1, HAL_MAX_DELAY);

 

Delays between data bytes are nothing to be concerned about. They happen because your code is not fast enough to feed to peripheral. Use DMA if it's critical.

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

Hello

Function HAL_SPI_Transmit second parameter must pointer to variable or array depending are you going to send one or several bytes.

Check here the basics how to use it:

https://controllerstech.com/how-to-use-spi-with-stm32/

Br J.T

ajimathew
Associate III

@JTP1 

Also why clock pulse is not continuous?

 

Hello

Like @TDK said, delay comes from software execution time from the moment one bytes is sended to moment when sending of another byte starts. HAL_SPI_Transmit is blocking function so execution is halted due transmission.

This delay comes up most clearly when you send one byte in one function call. Delay is shorter if you send multiple bytes in array and then using DMA is fastest.

Br J.T