Sunday, September 10, 2017

FSX - Add a Keypad for ATC (Part 3)

Tutorial for Adding a Keypad Mapper for ATC to FSX — 

Purpose: Connect 5V Pro Micro Shield to 3.3V USB Shield

In "FSX - Add a Keypad for ATC (Part 2)" the hardware and software for a functional USB key stroke mapper or translator were presented. The hardware consisted of a 3.3V USB Shield that used a 3421E processor chip, and an Arduino-compatible microprocessor Pro Micro shield that was a 5V device. The Pro Micro shield was modified to include a 5V to 3.3V voltage converter so that the SPI wiring between the shields could be directly connected without concern for the 5V device burning out the 3.3V device which was not designed to withstand 5V signals. The Arduino-compatible Pro Micro shield seems to perform as expected on the lower 3.3V voltage even though the Arduino IDE programmer was set for a 5V Leonardo device.


Alternative: Use a Pro Micro as 5V Device

My initial testing and development using the MAX3421E USB shield was conducted with an Arduino Mega 2560 which was a 5V board. A hardware solution was needed to interface the SPI signals between the two boards, so that the Mega 5V SPI signals would not burn out the MAX3421E 3.3V processor.

One solution was to use a 74LVC245 8-bit level shifter chip that I had purchased from AdaFruit. Per the data sheet: 

"The SN74LVC245A is designed for asynchronous communication between data buses. The device transmits data from the A bus to the B bus or from the B bus to the A bus, depending on the logic level at the direction-control (DIR) input. The output-enable (OE) input can be used to disable the device so the buses effectively are isolated."

If "DIR" is set to Vcc, then the voltage levels are shifted from the "A" pins to the "B" pins, and if "DIR" is set to Gnd, then the voltage is shifted from the "B" pins to the "A" pins. The supply voltage to the 74LVC245 is 3.3Vcc, not 5V, and the chip will convert the 5V SPI signals to 3.3V SPI signals. It does not convert 3.3V to 5V, in reverse.



Image 1. Top view of 74LVC245 voltage level converter. Connect Vcc and DIR pins to 3.3V. Connect OE and GND to Gnd (0V, common) between the boards. Connect 5V Pro Micro SPI pins to three of the "A" pins and the corresponding 3421E USB shield SPI pins to "B" pins. The SPI MISO pins were initially directly connected between the two shields to allow SPI to function.

For this project, the Pro Micro is the SPI master, so that signals on three SPI pins (CS, MOSI, and CLK) are transmitted from the Pro Micro at 5V to the corresponding SPI pins (SS, MOSI, SCK) on the 3421E USB shield through the 74LVC245. The Pro Micro RST pin was also connected across a 74LVC245 "A-B" pin pair to the MAX3421E RESET pin. The MAX3421E RESET pin can be connected directly to Vcc rather than the Pro Micro RST pin. The MAX3421E INT pin (3.3V), which would send out an interrupt signal, was not connected to the Pro Micro.

The down side of using the 74LVC245 for SPI is that the MISO signal from the 3.3V 3421E shield must be direct connected to the Pro Micro SPI MISO pin since the 74LVC245 is not a bi-directional device. However, this wiring did allow SPI to function between the two boards and the 3421E shield was not damaged during initial testing. The MISO signal voltage was later buffered using a simple resistor voltage divider--comprised of a 5K resistor from the Pro Micro MISO pin to the 3421E MISO pin and a 10K resistor from the E3421E MISO pin to GND. This simple divider passed the 3.3V MISO signal to the 5V MISO pin. The MAX3421E INT pin could also be connected using a voltage divider.

Bi-directional Level Shifter

An alternative to the 74LVC245 or  resistor voltage divider circuit is a bi-directional voltage level shifter (http://randomnerdtutorials.com/how-to-level-shift-5v-to-3-3v/ , http://www.hobbytronics.co.uk/mosfet-voltage-level-converter).



Image 2. This level shifter purchased from eBay will shift four signals from 5V high to 3.3V low or low to high. Each signal is handled by a separate MOSFET/resistor circuit.

For this project, the Pro Micro SPI pins connect to the HV1 to HV4 pins, 5V to HV, and GND to GND. The 3421E USB Shield SPI pins connect to the LV1 to LV4 pins, 3.3V to LV, and GND to GND. A second board or resistor voltage dividers are needed for the INT and RESET connections between the boards.

Level shifters did work for this project but added components, boards, and wiring. Using shields with matching voltages greatly simplified the prototype.

(September 10, 2017)

No comments:

Post a Comment