Spark Logic

"bit bang" SPI pins STM32F1

alexandros Mon Oct 09, 2017 10:09 am

Hello ,
i have a project that i use SPI1 in order to transfer data ,
PA7 MOSI1
PA6 MISO1
PA5 SCK1
PA4 NSS1

the board that i m using is hard to reach the MOSI pin PA7 basically its not breaked out anywhere i have to solder over MCU , i have access to PA6 though ,
So i am wondering before i make my next move , Is there any quick and easy way to Bit Bang data from MOSI1 to MISO1 ,

Replies

Pito Tue Oct 10, 2017 1:43 pm

Set/Clear GPIO pins:

// Set A6, A7, A15
// digitalWrite(PA6, HIGH);
// digitalWrite(PA7, HIGH);
// digitalWrite(PA15, HIGH);

GPIOA->regs->BSRR = 0b1000000011000000;

// Clear B6, B7, B15
// digitalWrite(PB6, LOW);
// digitalWrite(PB7, LOW);
// digitalWrite(PB15, LOW);

GPIOB->regs->BRR = 0b1000000011000000;

racemaniac Tue Oct 10, 2017 2:48 pm

Let’s maybe start with the basics, since i don’t think OP understands what bitbanging is

@OP: the standard pins of a peripheral like the SPI port are those pins, because the micro controller has built in hardware that allows you to communicate via that protocol in a fast & efficient way.
Bitbanging means that you don’t use such hardware, but rather implement that protocol using simple manipulation of the ports of the microcontroller. This is slower & less efficient (it costs the microcontroller a lot more work to achieve the same thing).
As you’re switching from using the built in peripheral to something completely custom, there is no “half way” mode. You cant use the default peripheral for everything except for the mosi pin, which you then “bitbang”.
You either bitbang it all, or nothing at all.
So if you choose to use spi on your 3d printer board on pins not supported by the stm32 hardware, you can indeed resort to bitbanging it to other pins. And from that point on, it doesn’t matter whether you still keep most pins of the SPI port of the stm32, or just go to entirely different pins. As soon as you’re no longer using the default pins, you can’t use the built in spi port anymore, and are going to a custom implementation for everything.

I hope this clears it up.

alexandros Tue Oct 10, 2017 3:04 pm

Perfectly clear , SPI its a train in standard rails , but i have to take the taxi…

Sign in to reply