Description
This project is a Microchip PIC microcontroller with an RS232 serial interface on one side and an SPI interface on the other. The SPI interface uses the SSP port on a 16F819 device.Important - All mention of RS232 on this page actually refers to RS232 waveforms operating at 5V TTL levels not +/-12V levels which would destroy the PIC device. An appropriate converter between the two must be used.
By sending commands on the RS232 interface it is possible to send any sequence of bytes on the SPI interface from the PIC. These can enable or disable the chip select and read, write or exchange a sequence of bytes.
A complex SPI command can be built up out of a number of these simple commands like:
Enable chip select
Write n bytes
Read m bytes
Disable chip select
In addition to the generic commands described above there are also some commands that will initialise, load or dump an SD/MMC card. Initialisation of the the SD/MMC card enables the SPI mode of operation. The read and write functions operate on blocks of data on the SD/MMC card.
Pictures
The circuit is built on stripboard with a DIL packaged IC and conventional through-hole passive components. The PCB is glued into the base of a small box for convenience.
The PIC microcontroller is the only IC and mounted approximately in the centre of the PCB. The RS232 connector is on the right with the SPI connector on the left.
In this second picture the device is seen connected directly to an SD card.
PIC Software
The PIC software is written in assembler and this project was the development platform for the SPI library functions as well as the MMC/SD card functions.The complete information for this project is available for download. This includes the library functions for the RS232 and SPI interfaces as well as the circuit diagram, layout diagram and various C programs. This project is included in the library of PIC code that is available for download.
Circuit Diagram
The circuit diagram is very simple with only the RS232 interface (a connector), SPI interface (a connector), PIC (IC and decoupling capacitor) and ICSP (socket, 1 diode and 1 resistor).
Important - An SD/MMC card must operate at about 3.3V so the RS232 interface in that case must operate at 3.3V instead of 5V.
Important - In-circuit serial programming of the PIC device must operate at 5V so the SD card and 3.3V RS232 interface must be disconnected.
Circuit Layout
This simple PCB layout diagram shows the placement of the components on the stripboard. The view is from the top of the PCB, the same as in the photograph.