Vous êtes sur la page 1sur 7

Serial Communication with Palm Pilot m515

By: Chad Meyer


Associated Project: Yes
Associated Part Family: CY825xxx, CY826xxx

Summary
This application note takes a closer look at how to use the UART user module to create a
reliable 8-bit serial communication with a Palm Pilot m515 and the PSoC microchip

Introduction
The Cypress Programmable System on Chip (PSoC) proves to be a very simple solution
for an 8-bit serial communication. In this application, it was to communicate with the
Palm Pilot m515, however since the serial communication is based off RS232 protocol, it
can just as easily communicate with anything that uses this protocol and 8-bit serial.

This application uses the following PSoC microcontroller resources:


- 8-bit Counter user module (to be used as a clock)
- UART user module

This application will also need to use the following external resources:
- Maxim MAX202CPE microchip

Serial communication explained


Serial communication is a common method used within embedded systems for
communication between different modules within the system. There are several
advantages to using serial communication:
- Minimizes the pin count to typically 3 pins (transmit, receive, and ground)
- Low power consumption
- Minimizes coding requirement (as opposed to TCP or UDP protocols)

RS 232 is a common protocol used in serial communication. Since all the bits (in this
application case – 8 bits) are transmitted or received on one pin, there becomes necessary
someway to determine what and when information is being sent.

Figure 1

The diagram above shows the expected waveform from the UART when using the
common 8N1 format. 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit. The RS-232
line, when idle is in the Mark State (Logic 1). A transmission starts with a start bit which
is (Logic 0). Then each bit is sent down the line, one at a time. The LSB (Least
Significant Bit) is sent first. A Stop Bit (Logic 1) is then appended to the signal to make
up the transmission.

The diagram above shows the next bit after the Stop Bit to be Logic 0. This implies
another word is following, and that would be its Start Bit. If there is no more data coming
then the receive line will stay in it's idle state (logic 1). We have encountered something
called a "Break" Signal. This is when the data line is held in a Logic 0 state for a time
long enough to send an entire word. Therefore if you don't put the line back into an idle
state, then the receiving end will interpret this as a break signal.

The data sent using this method is described as being ‘framed’. That is to mean that the
data is framed between a Start and Stop Bit. Should the Stop Bit be received as Logic 0, a
framing error will occur. This is common, when both sides are communicating at
different speeds (we will discuss this later).

The above diagram is only relevant for the signal immediately at the UART. RS-232
logic levels uses +3 to +25 volts to signify a "Space" (Logic 0) and -3 to -25 volts for a
"Mark" (logic 1). Any voltage in between these regions (i.e. between +3 and -3 Volts) is
undefined. Therefore this signal is put through a "RS-232 Level Converter". This is the
signal present on the RS-232 Port of the Palm Pilot (or computer or most any other
external device), shown below.

Figure 2

This is the purpose of the Maxim microchip MAX 202CPE. It is relegated with the job of
the RS-232 level converter mentioned earlier. It can take the signal from the PSoC, which
resembles a signal like Figure 1, and convert it to the signal of Figure 2. This is
accomplished by the MAX 202CPE and 5 external capacitors as shown in figure 3.
Figure 3

Figure 3 shows both the actual pinout (the left figure) and then how it would be set up
with the capacitors in place (the right figure). For more information about the Maxim
microchip, please visit their website www.maxim-ic.com.

Using the 8-bit Counter and UART User Modules


It was mentioned earlier that framing errors might occur when the two devices are
communicating at different speeds. Therefore when using serial communication in any
kind of embedded system, there must be a set rate (baud) that is used. For this
application, 9600 baud is set as the global communication speed. This means that it is
assumed that all other devices serially connected to the PSoC will be running at this rate
to ensure reliability and accuracy.

To accomplish this task, an 8-bit counter can be implemented as a clock, which the
UART will run off of. Using the 24V1 clocking resources, we will set N to 12. By
placing the Counter User Module in the DBA03 block we can use it’s broadcast as the
clock, which we set the UART to run off.
Figure 4

The figure above shows Counter User Module placed in the DBA03 block and the UART
User Module tied to that clock by having the DBA03 Broadcast selected as it’s clock in
the lower left-hand column.

Once the User Modules have been place and their parameters have been set, all that is left
to do is write the code that will control the PSoC and carry out whatever actions that is
desired for the project at had. At this time, it is good to take a step back and take and
overall look at how everything will be working together to make sure that complete
understanding of how PSoC serial communication is accomplished.

PSoC → Maxim → Palm Pilot m515


Microcontroller ← MAX202CPE ←

Figure 5

As shown in the above flow diagram between all the devices required implementing
serial communication. We see that a command/message is sent from the Palm Pilot (or
whatever device which is desired as long as it is capable of serial communication) and the
MAX202CPE microchip will intercept this message and convert it to the proper signal
for the PSoC. The PSoC will then receive this newly convert message and will carry out
whatever action that has been required. After this is accomplished, the PSoC can send a
message/command back to the Palm Pilot. Once again the MAX202CPE will convert the
signal properly so that the Palm Pilot will understand this message.

* It is important to note that not all applications will require the Maxim microchip. It
depends on whether or not the external device is using the RS232 signals. For instance, if
two PSoC microchips where connected serially, they would not require the RS232 signal
conversion between the two. It is important to identify these requirements when selecting
devices to connect to the PSoC.

Software
The option is left to the user of whether to use C/C++ or Assembly code to implement the
functions for the PSoC. C code was used in this application. Through the use of
predefined functions in the header files provided (defined by the User Modules selected),
one is able to effectively send and receive information efficiently without the hassle of
the protocol required with TCP and UDP transmissions. The following program is a
simple application of the serial communication, it will simply echo back the byte of
information received from and outside source.

When implementing more complex programs, it is a good idea to construct some sort of
“handshaking” protocol. This becomes increasingly important when implementing an
imbedded system which will be send several messages at all times, this way, information
will not be lost in the transmission and receiving of the messages. This application can be
used in conjunction with the Palm Pilot m515 (or any device which uses Serial
Communication) for much more complex programs. This application is an excerpt of a
project conducted at Washington State University that consisted of building a maze-
searching robot. The Palm was used as the Artificial Intelligence device and used the
PSoC as a decoder, motor controller, and odometry. For more information on this project
with PSoC please visit www.eecs.wsu.edu.

//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

// Libraries
////////////
#include "UART_1.h"
#include "Counter8_1.h"

// global variables
///////////////////
#define NAK_RESPONSE 0x00
// functions
////////////
BYTE getCommand(void);

void main()
{
BYTE instruct = 0x00; //byte which will represent command

// intitialize everything
Counter8_1_Start(); // Start the bit clock which is tied to the rest of the system
UART_1_Start(UART_PARITY_NONE);
UART_1_DisableInt();

while(run)
{
instruct = getCommand();

// simply echo’s back the message received


UART_1_SendData(instruct);
}
}

//////////////////////////////////////////////////////////////////////
// BYTE getCommand(void)
//--------------------------------------------------------------------
// description: when called, it will sit and wait for a command
// via the serial port, it will then send this command
// back to the PSoC
//////////////////////////////////////////////////////////////////////
BYTE getCommand(void)
{
BYTE bData = NAK_RESPONSE;
BYTE bRxStatus = NAK_RESPONSE;

/* wait for data to be received */


while( !( bRxStatus=bUART_1_ReadRxStatus() & UART_RX_COMPLETE ) );
/* preset response to error */

/* if no error condition then get byte received */


if ( ! (bRxStatus & UART_RX_NO_ERROR) )
{
/* no error received */
bData = bUART_1_ReadRxData();
}
return(bData);
}

Vous aimerez peut-être aussi