7 years, 7 months ago.

Switch and ports

Hello guys. I am now doing a project on protocol converter. I need have two switches on my mbed LPC1768 to choose the type of input protocol and output protocol. The number of protocols are 4 or 5. Anyone can suggest a switch for me? and how to connect it? Another question is that I want to connect my mbed to controller and camera with RS232 wires in serial. So do I need to buy two ports of RS232 and connect them to p9,p10 and p13 p14?

Thank you very much!!

3 Answers

7 years, 7 months ago.

Hi Neal, there are several threads about RS232 on the mbed site.

For example: http://mbed.org/forum/helloworld/topic/3473/?page=1#comment-17491

Here is an answer that I posted before on RS232:

Checkout the schematic of a Code Red development board. This board uses a MAX3232.


The MAX232 has the same pinout as the MAX3232. The only difference is that the MAX3232 needs 3V3 instead of 5V. The MAX232 works fine with mbed. No level shifters or anything needed.

Connections are:

  • mbed TX should go to one of the TIN pins on the MAX
  • mbed RX should go to one of the ROUT pins on the MAX
  • MAX TOUT goes to the TX pin 3 on a male RS232 connector
  • MAX RIN goes to the RX pin 2 on a male RS232 connector
  • connect mbed GND to pin 5 on the RS232 connector

Common problem is that TX and RX pins are switched depending on whether you use a male or female RS232 connector. You need to use a null modem cable between two male RS232 connectors or a straight cable between male and female. Depending on terminal settings you may also have to connect DTR/DSR and RTS/CTS.

FYI: There are also several breakout boards available with a max232 and a standard 9pin RS232 connector (eg sparkfun).

See http://mbed.org/forum/news-announcements/topic/1050/

Accepted Answer

One easy question. I cannot find a RS232 port on RS website. Do you know where is it available on the Internet?

posted by Neil Powell 27 Nov 2012

You need to look for the max232 or max3232 device. RS carries them and so do most other component shops.

Also checkout http://mbed.org/cookbook/Breakout-Boards regarding RS232 breakout boards like this one


posted by Wim Huiskamp 27 Nov 2012
7 years, 7 months ago.

Regarding the switches you could use bcd encoded switches, these are economical on I/O pins. You need 2 inputs for 4 positions (00,01,10,11) and 3 inputs for 5 position (can be used to 8 positions). Then need an output to select each switch (two outputs in your case), note the switch is selected by taking the common to OV.

Have pullups on the inputs pins and signal diodes to each switch bcd pin, i.e. one diode to each switch contact (4 diodes required)Cathode to switch contact, Anodes commoned to the pullup resistor and input line. The deselected switch has all the diodes biased 'off' so is not read. Look up diode logic if you haven't used this technique before. The active switch being read is selected by a logic 0 to the common pin.

The advantage of this metod is only 4 I/O lines required to read 2 switches and 4 positions, or 5 I/O lines for 2 switches and 5 positions.

Thanks a lot

posted by Neil Powell 24 Nov 2012
7 years, 7 months ago.

Connecting switches to mbed is straightforward:

Find a suitable momentary or single throw switch.

  • Connect a pull-up Resistor to 3v3 on one end of the switch and connect this also to a DigitalIn pin
  • Connect the other end of the switch to GND
  • Read the digital input and use that value


You need 2 Digital inputs for 4 codes and 3 inputs for 8 separate codes.

#include "mbed.h"
DigitalIn in0(p19);
DigitalIn in1(p20);

int main() {
   printf("Value is %d\n\r", (in1<<1) | (in0));


Note that you could even get rid op the pull-up Rs by using the pinmode.

Regarding the RS232 interface: Yes, you probably want to use two separate serial channels, one between the controler and mbed and another one between mbed and your camera. This is assuming you need two-way communication between all devices.

You can use one RS232 driver interface like the max232 (or max3232) to translate between RS232 voltage levels and mbeds 3V3 voltage levels. This is possible because the max232 actually has 2 transmitters and 2 receivers inside.

But I cannot find a RS232 port on the Internet. And how to connect port to mbed? Thank you

posted by Neil Powell 23 Nov 2012