Page 1 of 1
SPI over USART
Posted: Tue Jul 11, 2017 10:20 pm
by luca
Hi,
I'm developing on a STM32L073-Nucleo64 board with a STM32L073RZT6 on it.
For my purpose i need to use the SPI driver. The problem is that i need to use the following pins setup:
PA1 = Chip Select
PA2 = MOSI
PA3 = MISO
PA4 = Serial Clock
and according with the datasheet of STM32L073RZ those pins do not support any SPI driver with these specific settings.
I noticed that these pins can be used with the following setup:
PA2 = USART2_TX
PA3 = USART2_RX
PA4 = USART2_CK
Looking on the reference manual seems like that i can use the USART like an SPI but i cannot figure out how i should proceed.
There is any example or any tips for understand, if it's possible, what i should do for use the SPI over the USART ?
Re: SPI over USART
Posted: Tue Jul 11, 2017 10:33 pm
by steved
Are you stuck with that pin assignment? Its generally best to look at what functions are available on each pin as a first step; sometimes you have to experiment with combinations of pins to get everything you want. The SPI peripheral is available on PA4..PA7, if you're able to reassign pins.
It's possible that you could use the USART, since it claims to support synchronous communication of the type you want. However there's no support for this in ChibiOS (that I've found, anyway, not that I've looked hard) so it will be up to you to program the USART at the register level. Also be aware that some synchronous modes do 'bit stuffing', which ensures there's a transition on the data line every n clock cycles.
Re: SPI over USART
Posted: Wed Jul 12, 2017 7:48 am
by Giovanni
Hi,
There is no support for USARTs in SPI mode currently, it could be introduced but it would be a mess because the SPI driver would need to handle 2 peripheral types at the same time (because people would want to mix SPIs and USARTs in SPI mode).
Giovanni
Re: SPI over USART
Posted: Wed Jul 12, 2017 1:59 pm
by luca
Hi,
thanks for the answers. So there is no way to use the SPI on PA1, PA2, PA3, PA4 pins?
I know that there are many pins that support the SPI but unfortunately I'm forced to use those pins.
Thanks in advance,
Luca.
Re: SPI over USART
Posted: Wed Jul 12, 2017 2:44 pm
by steved
luca wrote:So there is no way to use the SPI on PA1, PA2, PA3, PA4 pins?
You can't use the internal SPI.
Basically you'll have to write some code.
I had a closer look at the USART, and it should be possible to make that generate SPI-like signals - then have a look at the SPI and UART drivers to get some ideas on how to integrate your driver into your code (you don't have to make it part of ChibiOS; it can be just another module in your project).
Alternatively, you could write some 'bit-banging' code to generate the signals - perfectly adequate if you don't need the SPI to run very fast, and you have the processor capacity.
Re: SPI over USART
Posted: Thu Jul 13, 2017 11:06 am
by luca
Hi steved,
thanks for the answer. I will take a look to the SPI and UART drivers as you suggested hoping to find a solution (i'm really newbie to the ChibiOS and embedded world).
Thanks,
Luca.