Raspberry Pi Serial Console With MAX3232CPE

In addition to the audio, video, network and USB connectors, the Raspberry Pi also has 26 GPIO pins. These pins also include an UART serial console, which can be used to log in to the Pi, and many other things. However, normal UART device communicate with -12V (logical “1”) and +12V (logical “0”), which may just fry something in the 3.3V Pi. Even “TTL level” serial at 5V runs the same risk.

So in this short tutorial, I’ll show you how to use a MAX3232CPE transceiver to safely convert the normal UART voltage levels to 3.3V accepted by Raspberry Pi, and connect to the Pi using Putty. This is what you’ll need:

  • Raspberry Pi unit
  • Serial port in your PC or USB to serial -adapter
  • MAX3232CPE or similar RS-232 to 3.3V logic level transceiver
  • 5 x 0.1 uF capacitors (I used plastic ones)
  • Jumper wires and breadboard
  • Some type of female-female adapter

The last item is needed to connect male-male jumper wires to RaspPi GPIO pins. I had a short 2×6 pin extension cable available and used that, but an IDE cable and other types ribbon cable work fine as well. Just make sure it doesn’t internally short any of the connections – use a multimeter if in doubt!

The connections on Pi side are rather straightforward. We’ll use the 3.3V pin for power – the draw should not exceed 50 mA, but this should not be an issue, since MAX3232CPE draws less than 1 mA and the capacitors are rather small. GND is also needed, and the two UART pins, TXD and RXD.
Continue reading Raspberry Pi Serial Console With MAX3232CPE

Simple FAT and SD Tutorial Part 4

In the previous parts of this tutorial, we have built both an FAT library as well as a test program to communicate with the SD card. Now it’s time to wrap it up with final parts of code to read a file from SD card and print it out.

This part will utilize the previously made FAT library with a few tweaks – it turned out that some byte and word-sized values needed explicit casting to unsigned long so that the calculations worked as they should. The new library and all code shown here can be found from the updated project zip.

Initializing the SD card automatically

Instead of manually pressing 1, 2, and 3, we’ll now write a single function to initialize the SD card to SPI mode. For standard SD (not high capacity SDHC) cards, it’s enough to:

  1. Send clock pulses for 80 cycles (“read” 10 bytes)
  2. Send command 0x40 (it should return 1)
  3. Send command 0x41 until it returns 0 (it returns 1 while the card is busy)
  4. Send command 0x50 to set read block size (as well as write block size)

Here’s the code to do just that (sd_sector and sd_pos will be used shortly):
Continue reading Simple FAT and SD Tutorial Part 4

Simple FAT and SD Tutorial Part 3

Finally back! Sorry for taking a while, but getting the SD cards to work required quite a bit of research! In this part of the tutorial, we’ll start talking with the SD card. Once you get that working, adding the FAT library developed in the previous part will be easy.

This tutorial will most likely be the most challenging covered in my blog so far, so beware: You may need to do some troubleshooting on this one! If you encounter problems, I recommend you to ask any questions at the AVR Freaks tutorial forum topic, so more people might be able to help you than just me!

Basic hardware setup: ATmega88 with UART console

The 3.3V UART I covered just a while ago will form the basis for this project. Only change we will be doing is to replace ATtiny2313 with ATmega88. This is because SPI, SD and FAT code will eat up almost 3 kB of program memory, and the ATtiny chips with that much program memory and separate RX/TX and SPI pins are not that common, while ATmega88 is readily available (48 and 168 work as well, of course). To accommodate the new chip, the following hardware changes are made to the ATtiny2313 version:

  • ATmega88 will require two ground connections
  • In addition to VCC, also AVCC for analog circuitry needs to be wired to VCC
  • Additional capacitor between AVCC and GND is recommended (I used 10 uF)
  • Programming header MOSI/MISO/SCK are also in different place

Continue reading Simple FAT and SD Tutorial Part 3

3.3V UART with MAX3232CPE

Before diving right into SPI communications for my SD tutorial, I wanted to have a 3.3V development platform that could output some meaningful status information, not just light a LED if something goes wrong. In this post, I will outline the basic testing platform that will be used in the upcoming part 3 of that tutorial, and discuss a little about UART on AVR in the progress. Here’s what we’ll build:

If you want to build it yourself, you’ll need:

  • ATtiny2313 or other AVR chip with UART pins (RX/TX) separate from SPI pins (MOSI/MISO/SCK)
  • 20 MHz crystal (other speeds will work, too) and ~27 pF capacitors
  • 4k7 pullup resistor for ATtiny2313 RESET pin
  • 3.3V regulator such as LD1086V33 or some other 3.3V voltage source
  • 2 filtering caps for the regulator input/output sides, 10 uF
  • MAX3232CPE or similar RS-232 transceiver that works on a 3.3V voltage
  • RS-232 port on your computer or a USB to RS-232 dongle
  • RS-232 to breadboard connector (home-soldered example seen above)

Continue reading 3.3V UART with MAX3232CPE