How to Control a TTL Serial Device With the Basic Stamp

How to Control a TTL Serial Device With the Basic Stamp thumbnail
Serial communication is often established through USB connections.

The easiest way to control a serial TTL device is by using the Serial Peripheral Interface, or SPI, method of communication. TTL refers to transistor-transistor logic, which describes the internal construction of the serial device. Electrically, TTL means that the device operates on +5V and 0V levels, which are common voltage levels in SPI communication. The Basic Stamp microcontroller contains a specific command that enables SPI, the "SHIFTOUT" command. Only three electrical connections are required for SPI communication, and the best way to design this type of circuit is to begin on paper.

Things You'll Need

  • AD5161 digital potentiometer datasheet
  • Paper
  • Pencil
  • Basic Stamp reference manual
Show More

Instructions

  1. SPI Electrical Connections

    • 1

      Locate the SDI, CLK and CS pins on the serial device. Analog Devices' AD5161 digital potentiometer will be used as an example of a serial device. Draw a square signifying the potentiometer and draw lines for three pins. Refer to the AD5161 datasheet and label the pins "SDI," "CLK" and "CS."

    • 2

      Write "Serial Data Input" next to SDI and write "Serial Clock Input" next to CLK. Draw a line over the top of CS and write "Chip Select Input" next to it. The line signifies that the CS is active low, requiring a 0V level to activate the Chip Select Input.

    • 3

      Locate three available input/output pins on the Basic Stamp. Refer to the Stamp reference manual for the pin description. Draw a square to the left of the potentiometer and draw lines for three output pins. This square signifies the Stamp. Label the pins "output 1," "output 2" and "output 3."

    • 4

      Draw lines connecting the three pins of the Stamp to the three pins of the potentiometer. Connect Stamp output 1 to potentiometer SDI, connect Stamp output 2 to potentiometer CLK and connect Stamp output 3 to potentiometer CS.

    The Stamp Program

    • 5

      Send a logic "low," or 0V, out of Stamp pin 3. Write "LOW 3" under the previous diagrams. This sends a 0V level out of pin 3, and it remains at 0V until the program ends or until it is programmed to be a logic "high." The potentiometer CS pin is "active-low," which requires a steady 0V level to "turn-on" the programming features of the device.

    • 6

      Write "SHIFTOUT" under the LOW command and refer to the Stamp manual for its parameters. The complete command with its parameters is: SHIFTOUT Dpin, Cpin, Mode, OutputData.

    • 7

      Set the first parameter of the SHIFTOUT command. Write a " 2" next to SHIFTOUT, as in the following: SHIFTOUT 2. The "2" assigns the Dpin, or data pin, to Stamp output 2. The data travels from output 2 to the potentiometer SDI pin. That data controls the resistance level of the potentiometer.

    • 8

      Set the second parameter of the SHIFTOUT command. Add a "1" to the command, as in the following: SHIFTOUT 2,1. The "1" assigns the Cpin, or Clock pin, to Stamp output 1. The Clock signal is a steady alternation of +5V and 0V. The Clock signal is connected to the CLK pin of the potentiometer, and it controls the flow of data to the potentiometer.

    • 9

      Set the third parameter of the SHIFTOUT command. Add "MSBFIRST" to the command, as in the following: SHIFTOUT 2,1,MSBFIRST. This sets the Mode parameter, which orients the data that is sent out of the Stamp. It will be sent with the Most Significant Bit first, meaning the numeric data value is sent left-to-right. The AD5161 datasheet specifies that data must be oriented MSB-first.

    • 10

      Complete the SHIFTOUT command by setting the OutputData parameter. Add "128" to the command, as in the following: SHIFTOUT 2,1,MSBFIRST,128. Sending a decimal number, from 0-255, sets the amount of resistance in the potentiometer. Sending the number 128 is similar to setting a volume knob halfway on a stereo.

    • 11

      End the programming sequence by setting CS to a logic high. Write "HIGH 3" under the SHIFTOUT command. This places the CS pin at a 5V level. This action "turns-off" the programming functions of the potentiometer, maintaining the resistance at the previously set level of 128. When you want to change the level, set CS low again and send another data byte in a SHIFTOUT statement.

Tips & Warnings

  • In SPI communication, there is a fourth connection called SDO, or Serial Data Output. Connection to the SDO pin is optional. The SDO is used for chaining two devices together or it is used for communication back to the microcontroller. If unused, the SDO pin is left open, with no connection to anything. The Clock speed is a fixed value within the Stamp and cannot be set by the user. In the SHIFTOUT command, the Mode can be MSBFIRST or LSBFIRST, depending upon the serial device. The Data parameter of SHIFTOUT may be in the form of decimal, binary or hexadecimal.

  • Read the serial device's datasheet before making actual connections. The datasheet will tell you how to set up SPI communication for that particular device. Improper connections will cause functioning errors.

Related Searches:

References

Resources

  • Photo Credit usb connector image by Albert Lozano from Fotolia.com

Comments

You May Also Like

Related Ads

Featured