cancel
Showing results for 
Search instead for 
Did you mean: 

is there any SHIFTOUT()?

Ala
Senior
4 REPLIES 4

According to https://www.arduino.cc/reference/tr/language/functions/advanced-io/shiftout/ , ShiftOut() in Arduino-ish is probably a bit-banged SPI.

You can bit-bang the pins in a similar manner, although you won't find a ready made routine for that in the "official" libraries such as Cube.

You might use USART in synchronous mode, or you may use SPI. You want to read the respective chapters in your mcu's Reference Manual (RM). To be able to use any peripheral, you first need to enable its clock in RCC, and then to set up the pins belonging to those peripherals in GPIO (again read the related chapter in RM). There is only a limited set of pins for each peripheral, see your mcu's datasheet.

You may be able to click through CubeMX without doing the due reading, but I don't use CubeMX (the clicky program) nor Cube (the associated library), so can't help with that.

JW

PS. Please change your username to a normal nick.

@Vincent Onde​ 

This might be an idea for one of the dozen of general "howto" appnotes. The venerable '595/'165 shift/latch combos are cheap and useful ways to extend IO, and many other chips employ the same or similar shift-latch structure. The appnote might list various methods - loopdelay bitbang, timer/DMA-based bitbang, synchronous USART, SPI, even "abusing" SAI and maybe some others too - discuss their relative advantages and drawbacks, link to the "specialized" appnotes, and give simple examples for them. It would be a great opportunity to discuss the SPI NSS issue in various STM32 families.

JW

Dear waclawek.jan

I took your advice and changed my Nick: Ala!

> I used CubeMX for picking USART pins and doing the initialization.

In synchronous mode, i.e. do you have a clock pin?

> but I'm still not quit sure if they are identical.

In your original code you used "MSBFIRST" - the USART in STM32 outputs data LSB first and it can't be changed, so you either need to swap bits in bytes your data in software before transmitting them, or use SPI which can be switched to both LSB and MSB first.

JW