cancel
Showing results for 
Search instead for 
Did you mean: 

Change SPI MOSI-MISO Pins

herca.1
Associate II

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.

4 REPLIES 4

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

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
Associate II

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.

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