Serial Communication in Embedded Systems
Serial Communication in Embedded Systems
Embedded Systems
USART
• Universal
• Synchronous
• Asynchronous
• Receiver
• Transmitter
RS232
• RS232 is a long standing standard for
point to point serial communication.
• Transmission is carried out with voltage
levels between -5V and 5V or -12V and
12V.
Baud Rate
General Case
Baud = [Source Clock] / [Clock Divider]
EB63
Baud = [Source Clock] / (16 x [Clock Divider])
Sampling Rate
• In order to get reliable communication, the
USART must over sample the receive line.
• The higher the sampling rate the more
precise the USART can be.
• In general and in the case of the EB63, a
sampling rate of 16x the Baud Rate is
used.
Sampling Rate
Bit 1/0
Receiver
• The receiver must detect an incoming
transmission and then capture the data bits as
they arrive in the center of the Baud period.
• Each transmission includes one start and 1, 1.5
or 2 stop bits
• A start bit is the first part of the transmission and
the signal is low for one Baud period
• A stop bit is the last part of the transmission and
the signal is high for one to two Baud periods
after the last data bit.
Receiver
Sampling
clock
Baud
clock
Receiver
• The start bit is detected at the midpoint of
the baud period. Every baud period after
the start is detected the receiver captures
a data bit until all data bits are received.
This insures the bits are captured in the
center of the baud period.
Transmitter
• The transmitter uses the Baud Clock to
transition the serial signal to send data.
• In practice, the data is stored in a shift
register like logic. The transmitter first
sends the start bit followed each data bit
(MSB to LSB) shifting out of the shift
register. The transmission is ended with
the stop bits.
Transmitter
sc = f->ReadAt(UINT64_ZERO,(BYTE*)&n,(UINT)1,&nbytes);
if (FAILED(sc) || (nbytes == 0)) {
printf("Could not read from com2, sc=%x nb=%d\n",sc,nbytes);
return 0;
}
return n;
}
This function reads a single byte from the read buffer. Note: this is a blocking read. If the
buffer is empty when this is called it will not return until something comes into the
buffer for it to return.
3. Transmitting Data
int WriteOneInteger(PIFILE f, int n)
{
UINT nbytes;
SCODE sc;
sc = f->WriteAt(UINT64_ZERO,(BYTE*)&n,(UINT)1,&nbytes);
if (FAILED(sc)) {
printf("Could not write com\n");
return -1;
}
return 1;
}
endmodule
Receiver
CLK – Source Clock (T9 on
async_receiver ar( the Spartan III)
.clk(CLK), RxD – Receive Pin (T13 on
.RxD(RX), the Spartan III)
.RxD_data_ready(rdysrt), RxD_data_ready – data ready,
.RxD_data(data) pulses high when data is valid
//.RxD_endofpacket, RxD_endofpacket – asserts
after a period of time, used
//.RxD_idle
when receiving multiple
); sequential packets
RxD_idle – asserts after a time
out to signal nothing is being
received
Transmitter
CLK – Source Clock (T9
async_transmitter at(
on the Spartan III)
.clk(CLK),
.TxD_start(rdysrt), TxD – Transmit Pin (R13
.TxD_data(data), on the Spartan III)
.TxD(TX) TxD_start – start
//.TxD_busy() transmission, pulse this to
); begin sending data
TxD_busy – transmitter
busy, the transimitter is
already sending data