Adding Interface Connectors

Cool as it looks, the OLED display we’ve just installed on our prototyping board is just a display. Microcontrollers (and by extension, this prototyping board) are meant to interface with all sorts of electronics so they can control them. It’s in the name. I’m talking sensors and actuators, for the most part. But also storage devices, radios, and even other microcontrollers.

The Maple Mini gives access to every peripheral in the STM32F103 it carries. Thanks to the ground work we’ve done earlier, notably laying down a “power grid”, it’s easy to bring the pins for those peripherals out to individual connectors. Here’s the Maple Mini pin map once again :

In this episode, I’m adding three connectors to the board : one USART, one SPI and one I²C. Everything on the right side of the map.

Why ? I’ll figure it out later. There’s always a use for a standard serial interface, especially those three.

Let’s get to it.

1.1.        USART2 Connector

Pins PA2 and PA3 are marked “Serial2” on the pin map. That’s a stage name, in fact those are the pins for the USART2 peripheral of the STM32F103. I’m not gonna tell you what a USART is, chances are you already know and/or can Google it.

Based on my experience, I know I need to have one GPIO along with the transmit and receive pins of a USART. For example, I could use it to control an RS485 transceiver, and through that gain the ability to interface with all sorts of industrial equipment.

Looking at the Maple Mini pin map, I noticed that the pins for USART2 can also be configured as two channels of timer TIM2, and that a third channel is on PA1, the pin right next to them. So of course I chose that pin as the extra. Now my USART connector it’s going to have a lot of versatility. It could even output three-phase PWM signals in the event I want to drive a brushless motor.

Remember the SWD connector we soldered ages ago ? It has VCC (3.3 V) on its first pin. I’m going to keep this pattern going for all the connectors on this prototype board. Who knows, it could save this board one day, if I get distracted and plug a cable on the wrong header.

Because of the way I laid out my board’s “power grid”, I had to put the pin header on the bottom side of the board. No big deal, that’s what I already did for the SWD header. Here’s the end result, from below. SWD header on the right side, USART2 header on the left side :

Notice the wires don’t cross. Always try to avoid crossing wires on your prototypes, it’ll make your life easier if you ever need to repair or modify your board.

For reference, here’s the pinout from the top side :

1.2.        I2C2 Connector

Pins PB10 and PB11 can be multiplexed to one of the F103’s I²C bus controllers. But that’s not all, they can also be muxed to USART3. That means we’re potentially looking at a second USART connector. And that means it’d be a great idea to give it the same pinout as the USART2 connector.

As luck would have it (or perhaps good ST engineering) the USART2 and USART3 pins are in the same order, so we don’t need to cross wires to achieve identical pinouts.

I still need an extra GPIO on that connector. PB2 is closest but remember, we’ve already used it for the OLED display interface. The next pin is PB0.

And thus, we get this nice clean interface :

Notice the nice clean taps into the 3.3 V and ground rails.

For reference, here’s the pinout :

1.3.        SPI1 Connector

And the big one for last… the SPI1 controller can be muxed to pins PA4 through PA7. As you’ve seen with the OLED display, it’s also a good idea to bring a pair of GPIO along with an SPI bus. And then of course some 3.3 V power and a ground are always useful. This means we’re looking at an 8-pin header :

I picked the closest GPIO I could route without crossing wires : PA0 and PC15. Here’s the detailed pinout :

Such clean wiring… it’ll be a shame it hide it all under that big OLED display, but you know what they say : inner beauty is important.

The three connectors I’ve just described can be used to connect countless type of device. For specifics, you’ll have to look around : this particular section of my site focuses on the Maple Mini, not on its applications.

 

1.4.        Connector Design Philosophy

So, before we start using those connectors (in another episode) I thought I might share some of my design expertise with you. If you think you know better than me and/or you don’t like technical rants, feel free to ignore this section. But you really shouldn’t, because I’ll be reallllll judgmental if you ever show me one of your prototypes and its interfaces look like crap.

I’ve just shown you a bunch of interface connectors I’ve built. They work well for the particular prototype I’m building. And if you’re building the exact same, don’t worry, you’re in good hands. But it’s very likely you really want to create your own prototype. So I’m going to try to tell you the essence of coming up with generic interface connectors for prototypes.

Imagine this : you’re building a prototype board, nobody is the boss of you, there’s nothing you’re maintaining compatibility with. You can use any type of connector you want. You can have them carry any signals you want, even duplicate signals. How do you choose ?

There’s no wrong idea except one : you really mustn’t design a connector that doesn’t have at least one ground pin. That’s wisdom for the ages, right there.

Beyond that, you need to think about practicality and possibly cost. You do not want to use a PCI Express x16 socket just to carry one GPIO and one ground pin. Not unless you lost a bet.

For almost any scenario involving a microcontroller, the practical approach is to use standard 2.54 mm pitch pin headers. You’ve seen them on everything from Arduinos and Raspberry Pi’s to PC motherboards. They are inherently compatible with those “Dupont wires” you can find everywhere and with prototype boards. And they are the cheapest type of connector there is, by virtue of being just pins with a minimum of plastic to keep them together.

Once you’ve selected the connector type, you still need to determine what signals they should carry. Here, I’m building a prototyping board without a specific application in mind… so I don’t know what I’m going to connect to each interface in the future. The best approach in this case is to keep your options open :

  •         Power is always a good idea. 3.3 V in this case. If we’re just going to connect a small sensor to the STM32, this will save us the trouble of building a separate power source for it. Most sensors eat far less current than what the Maple Mini can provide. It can even power the big OLED display.
  •         You’ll want to bring out every pin of the interface you want to use, obviously. Remember how the OLED module was a write-only SPI device, but we still made use of the STM32’s data input pin to control the display ? Maybe someday I’ll use that connector for something else and I’ll need full-duplex SPI. Then it’ll already be there.
  •         Additional GPIO are always a good idea. For example, many I²C devices also have an interrupt output. That’s because I²C is a strictly master-slave interface : slave devices can’t interrupt the microcontroller over I²C because they can’t initiate transfers on their own. Hence the need for at least one extra pin. The OLED module also required discrete signals in addition to the SPI interface.

Based on my own experience with countless devices, a good rule of thumb is that any SPI connector should carry at least two extra GPIO’s. Any I²C or UART connector should carry at least one extra GPIO. I can’t even recall the last time I ran into an exception to that rule.

We haven’t yet dealt with other peripherals like timers and ADC’s but the time will come. I’m told that if I write too many words, no matter how good they are, internet dwellers will get bored and leave. So I’m pacing myself.

Last but not least, try to keep the pinout of all your connectors identical, or at least similar enough. We all get distracted. You never know when you might plug the wrong cable on the wrong interface. When that happens, you do not want that mistake to vaporize your prototype because “VCC” on your I²C connectors is “GND” on your UART connectors. Plus, if you have multiple connectors for identical interfaces, keeping their pinouts identical will let you swap interfaces easily.

I could go on for quite a while, but I’m going to stop there for now. One thing I want to convey is that imagining and assembling a prototype board always takes more time than you think it will. You wake up, you start soldering, and before you know it it’s midnight. That’s why I’m writing this : to offload my brain and have some recipes I can implement without having to think about it. It makes my life easier and I’m hoping it makes yours too.