Skip to main content
herca.1
Associate II
January 13, 2020
Question

Change SPI MOSI-MISO Pins

  • January 13, 2020
  • 4 replies
  • 4026 views

Hello,

I am using STM32L100 in one of my projects. I designed a PCB for this and it appears that I made a mistake on the layout. SPI's MOSI and MISO pins are not correctly routed on the PCB layout they are just opposite of how they should be connected.

Is there a way I can change MOSI (PA6) and MISO (PA7) pins so I dont have to modify the PCB. I know you can bitbang SPI but I am not sure if I can accomplish that.

Thank you.

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
January 13, 2020

You can't swap the pins in software.

Their function reverses if you run the SPI as slave, but you'd need then to provide clock somehow.

It may be better to cut/reconnect the traces on the prototype, and then redesign the PCB for the final version with appropriate routing.

JW

Ozone
Principal
January 13, 2020

From experience, I need to agree with Jan.

On average, the (commercial) projects I was involved in required 3 hardware versions, i.e. two revisions.

The second corrected schematics/routing mistakes like yours, and the third dealt with EMI issues found during conformance tests.

herca.1
herca.1Author
Associate II
January 13, 2020

Thanks for the suggestions. The problem is I already manufactured too many of these boards.

I am still trying to figure out bitbanging solution. I really appreciate if anyone speeds up my progress with examples etc.

Thank you so much for answering.

waclawek.jan
Super User
January 13, 2020

SPI master bitbanging is relatively simple in principle, in pseudocode

for (i = 0; i < nr_of_bits; i++) {
 set_SCK_high();
 if (output_word & (1 << nr_of_bits)) {
 set_MOSI_high();
 } else {
 set_MOSI_low();
 }
 output_word <<= 1;
 set_SCK_low();
 input_word <<= 1;
 if (MISO_is_high()) {
 input_word++;
 }
}
 

Order of operations has to be adjusted according to required CPOL and CPHA.

The problem with STM32 is that it's too fast and delays have to be inserted, and then the whole operation may last too long.

JW