cancel
Showing results for 
Search instead for 
Did you mean: 

SPI over USART2 on STM32L052K8?

Marco Ferdinandi
Associate II
Posted on January 16, 2018 at 12:09

Hi,

I would like to know how to use the USART2 on my board (integrating the STM32L052k8 mcu) to communicate in SPI with an external slave.

Is it possible? How can I do it? Is there an example or a snippet which I can use as starting point?

Finally: my first target is to build a transparent bridge USB - SPI (over the pins PA1 PA2 PA3 PA4). Is there an example or a guideline which I can follow?

Thanks in advance,

Marco
5 REPLIES 5
Posted on January 16, 2018 at 17:38

The pin routing does not describe an SPI use case for PA[1..4]

http://www.st.com/content/ccc/resource/technical/document/datasheet/dc/d6/6d/24/86/2a/40/d3/DM00108217.pdf/files/DM00108217.pdf/jcr:content/translations/en.DM00108217.pdf

 

You will need to bit-bang those GPIO pins.

There might be some way to use the USART in a synchronous mode, but you'll need to be able to address the start and stop bits, etc. I would suggest hooking to a logic analyzer and reviewing the signalling you can generate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 17, 2018 at 16:32

Hi,

thanks for the answer. At this point, is there a software library which implements SPI in software using pins as GPIO for my STM32L052k8 mcu?

Thanks in advance,

Marco
Posted on January 17, 2018 at 16:58

No, it isn't that complicated to implement

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 17, 2018 at 18:16

See AN4655.

JW

Posted on January 17, 2018 at 17:38

Configure required GPIO pins (INPUT, OUTPUT) then try to mimic the SPI timing. For each bit you want to send out you need to set the value of the output being MOSI and change the clock pin to make the other side clock-in the bit.

https://www.embeddedrelated.com/showcode/340.php