Uploaded by Sameer Ahamed

McBSP IEEE

advertisement
The Function Extension for the McBSP of TMS320C6000 Series DSP
CHEN Zhe
FANG Bo
Shaanxi Road Traffic Intelligent Detection and Equipment
Engineering Research Center
Chang’an University
Xi’an, China
zchen@chd.edu.cn
Institute of Xi’an Aeronautical Computing Technique
Xi’an, China
Abstract—Multi-channel Buffered Serial Port (McBSP) is a
standard component of TMS320C6000 series DSP, and also is a
kind of enhanced serial port. McBSP characterizes its good
expansibility, and can be extended to various type of interface
port. After the principle of McBSP is analyzed, the configuration
method, operation mode and program routines are presented for
configuring the McBSP as General Purpose Input Output
(GPIO), Universal Asynchronous Receiver/Transmitter (UART)
or Serial Peripheral Interface (SPI). Experiments show that
every extended function of the McBSP works well in practical
computer system.
Keywords-McBSP; GPIO; UART; SPI
I.
INTRODUCTION
Due to high processing speed and excellent expansible
interface, TMS320C6000 series DSP has great potential
application in the field of radar, sonar, medical equipment and
image processing, etc.
TMS320C6000 series DSP integrate a great number of onchip peripherals, including Multi-channel Direct Memory
Address or Extended Direct Memory Address (DMA/EDMA)
controller, Multi-channel Buffered Serial Port (McBSP), Multichannel Audio Serial Port (McASP) and Host Port Interface
(HPI), etc. These on-chip peripherals can greatly simplify
computer system design.
Here we focus on the function expansibility of McBSP and
will mainly introduce the methods of configuring it as General
Purpose Input Output (GPIO), Universal Asynchronous
Receiver/Transmitter (UART), and Serial Peripheral Interface
(SPI).
II.
GENERAL INTRODUCTION TO MCBSP
The basic functions of the McBSP of TMS320C6000 DSP
include full-duplex serial communication, double buffered data
register which allows continuous data stream, receiving and
sending independent frame synchronous signal and clock
signal, choosing the clock in chip or out of chip in data
transmission, automatically-buffered serial port data in reading
and writing when DMA is working for McBSP [1]. The
interface signals of McBSP include sending clock CLKX,
sending frame synchronization FSX, data sending DX,
receiving clock CLKR, receiving frame synchronization FSR,
data receiving DR and external clock CLKS [1]. Owing to
these functions of McBSP, it can be easily configured as the
GPIO, UART or SPI in design.
The specific methods of configuring McBSP as GPIO,
UART or SPI interface will be introduced as follow in detail.
III.
CONFIGURING MCBSP AS GPIO
In system design, GPIO is often used to setup simple sign
or monitor certain state. By setting a certain bit of signal as “1”
or “0”, or acquiring a certain output state to trigger event,
McBSP can easily implement the function of GPIO.
When configuring McBSP as GPIO, we only need to set
RRST and XRST bit in SPCR register as 0 and XIOEN and
RIOEN bit in PCR register as 1. Then McBSP is in reset state
and the serial port pin is GPIO. By setting the value of
correspondent bit in PCR register, CLK, FSX, DX, CLKR and
FSR can be configured as input or output and DR and CALKS
are fixed as inputs [1]. Certainly, when a certain signal is
initialized as input, it must be initialized again to change it into
output. The input and output value on GPIO pin is mapped in
the correspondent bit of PCR register. The initialized program
of a certain pin is as follow:
// Sending end is in reset state.
RESET_BIT(MCBSP_SPCR_ADDR(1), XRST);
// Receiving end is in reset state.
RESET_BIT(MCBSP_SPCR_ADDR(1), RRST);
//Set CLKX as GPIO output.
SET_BIT(MCBSP_PCR_ADDR(1), CLKXM).
IV.
CONFIGURING MCBSP AS UART
Universal Asynchronous Receiver Transmitter (UART) is a
common communication interface in computer system and
used as serial-to-parallel converter of data. In practice, 8252 or
special UART device (for example, 16C450) is used to
implement the serial-to-parallel conversion. By configuring
MBSP as UART interface, the flexibility of system design can
be greatly improved and the using of periphery chips and the
system power consumption can be reduced.
The McBSP of C6000 itself doesn’t have the function of
UART. But by setting it, we can configure it as a standard
UART interface. If attached to level converting circuit, McBSP
can be configured as standard RS232 or RS422 protocol
interface. In this way, it can be easily connected to PC [2].
According to its work principle, UART works in
asynchronous transfer mode and so it doesn’t need clock
The Project was supported by the Special Fund for Basic Scientific
Research of Central Colleges, Chang’an University and sponsored by Open
Fund of Shaanxi Road Traffic Intelligent Detection and Equipment
Engineering Research Center.
978-1-4244-9857-4/11/$26.00 ©2011 IEEE
during transfer. Its transfer protocol contains four parts: start
bit, data bit, parity bit and stop bit. In the data transmission
time order of UART, the start bit is indicated by level
converting from high to low, which provides a proper moment
for McBSP to check data. The McBSP itself is also a kind of
asynchronous interface with flexible software-configured data
format. So, the software-configured McBSP can be easily
designed as UART. There are two methods to configure
McBSP as UART. One is serial interface mode and the other is
GPIO mode [3].
received McBSP data must be parsed to obtain real data. For
example, 0x0000 denotes “0” while 0xFFFF denotes “1”. In
the process of parsing, start bit and stop bit must be given up to
make sure received data would be rightly restored.
Word to be send
10001010
A. Serial Interface Mode UART
1) Basic Principle.
The UART serial asynchronous data received by McBSP
include not only frame information but also data information.
In order to completely check the transmitted data, the Tx of
UART must be attached to DR and FSR of McBSP at the same
time. While in transmitting data port, the DX of McBSP is
directly connected with the Rx of UART. Fig. 1 shows the
hardware connection.
Standard UART
UART
Tx
TMS320C6000
McBSP
DR
FSR
Rx
DX
Figure 1. Connection between UART and McBSP
As for the data format in processing, TMS320C6000
regards 1bit UART data as a 16bits word, that is to say, 1bit
UART data needs to be expanded to 16bits McBSP data. Fig. 2
shows the expanding method. So, if an 8bits data will be
transmitted from McBSP interface, the method in Fig. 2 must
be applied to expand it, at the same time a start bit (0x0000)
and a stop bit (0xFFFF) should be inserted into it. Because the
stop bit is processed as 8bits and in this way 1.5 stop bit can be
easily set. In practice, McBSP doesn’t have this kind of data
expansion function. But it can be solved by programming.
In the course of transmission, inner sampling rate generator
divides the frequency of CPU clock, therefore provides the data
sampling clock for McBSP. Because 1bit UART data
corresponds to 16bits McBSP data, McBSP clock should be 16
times of UART baud rate. The baud rate in SRGR register can
be computed by the following equation:
CPU _ CLK _ Frequency
SRGR. CLKGDV=
−1
16 * Baud _ Rate
In data transmitting, 1byte data for sending must be
expanded to sequential eight 16bits data and a start bit and a
stop bit should be added to every data segment of UART. After
expanding, data can be written in the transmission register
DXR of Mc BSP and be sent in UART format. Likewise, the
Sending buffer
0x0000(Start)
0x0000(D0)
0xFFFF(D1)
0x0000(D2)
0xFFFF(D3)
0x0000(D4)
0x0000(D5)
0x0000(D6)
0xFFFF(D7)
0xFFFF(Stop)
0x0000(Start)
Frame start
Frame end
...
0xFFFF(Stop)
...
Figure 2. Extension of UART Data
In practical use, if CPU expends a great deal of time to
“carry” data, the system efficiency must be reduced. So DMA
or EDMA is operated to carry data, which will greatly save
processing time for CPU. When sending data, DMA is started
and data are written from buffer into the DXR of McBSP.
When receiving, DMA is also started and the data received
through McBSP interface will be sent to data buffer set by user.
Before the end of transmission, CPU can perform other tasks.
2) Specific Configuration
According to the instruction in 3.1.1, McBSP should be
configured as UART transmission mode at first and then DMA
or EDMA is started to transmit data. In the configuration of
McBSP, the three registers MCR, RCER and XCER are in
default mode and the configuration of registers SPCR, RCR,
XCR, SRGR and PCR are very important. The configuration of
DMA or EDMA is decided by the chosen channel.
TMS320C6000 series DSP provide multi-channel DMA or
EDMA. Generally, UART transmission through McBSP needs
two channels, one for sending and the other for receiving.
When transmitting, DMA writes a 16bits data in McBSP_DXR
and waits for writing the second data when McBSP_DXR is
empty. When data buffer is empty, interrupt is triggered to
notify CPU to turn to execute next data segment sending
routine. In the course of receiving, DMA is started after
McBSP_RXR has received data. After finishing 11
transmissions, DMA triggers interrupt. Then interrupt service
routine (ISR) begins to parse data, completing data receiving.
In processing, the expansion of sending data and the
parsing of receiving data are very important, which will
directly affect whether the sending and receiving data are true
or false. The specific program of sending expanding data can
refer to the following:
// Point to transmitting buffer
xmitbufptr=(unsigned short *)xmitbuf;
for(i=0;i<(sizeof(xmitbuf)/sizeof(unsigned int));i++)
{
//Take out one 16bits datum
//Clear buffer
raw_data = *recvbufptr;
xmitbufptr[i] = 0x0000;
recvbufptr++;
}
//0x0000 is 0,0xFFFF is
xmitbufptr =(unsigned short *)xmitbuf;
1recv_val=VoteLogic(raw_data);
for (i = 0; i < BUFFER_SIZE; i++)
// Parse 1bit UART data
{
recv_char+=recv_val<<cnt;
// Take out a bit for expansion
}
xmit_char = xmit_msg[i];
}
// Specific expansion
//Store the parsed data in recv_msg[i]
for (cnt = -1; cnt < 10; cnt++)
recv_msg[i]=recv_char;
{
}
if (cnt == -1)
*xmitbufptr++ = 0x0000;
else if (cnt == 8 || cnt ==9)
*xmitbufptr++ = 0xFFFF;
else if (xmit_char & (1 << cnt))
*xmitbufptr++=0xFFFF;
B. GPIO Mode UART
1) Basic principle
After configuring the pin of CLKX, FSX, DX, CLKR,
FSR, DR and CLKS in C6000 McBSP as GPIO mode, they
can be attached to UART interface by using software. In this
paper, we will focus on the case that DR and DX are served as
GPIO and are connected with UART. Fig.3 shows actual
circuit diagram.
else
*xmitbufptr++=0x0000;
}
Standard UART
UART
}
The following program shows how to throwing start bit and
stop bit, which is the key operation of parsing data.
// Point to receiving buffer
TMS320C6000
McBSP
Tx
DR
Rx
DX
recvbufptr= (unsigned short *)recvbuf;
// Process all data in receiving buffer
for (i = 0; i < BUFFER_SIZE; i++)
{
recv_char = 0;
// Process every UART data
for (cnt = -1; cnt < 10; cnt++)
{
// Throw start bit and stop bit
if(cnt == -1 || cnt == 8 || cnt == 9)
{
*recvbufptr++;
}
else
{
Figure 3. Connection between UART and GPIO
Working in the mode of GPIO, other McBSP registers are
not necessary to be set purposely, just working in the mode of
default. But there are three problems that should be concerned:
the checking of UART baud rate, UART data processing
before sending and UART processing received data.
The checking of UART baud rate is automatic. By
checking the start bit and the length of the first data bit, 1/2
baud rate can be obtained. The way is to read DR_STAT bit of
PCR register and count time by using software. After UART
has received data, it waits for 1/2 baud rate and then read the
value of DR_STAT bit, namely, the data bit of UART. Before
UART sends data, it writes DX_STAT bit of PCR register, that
is, UART sending data. Writing “0” denotes start bit and
writing “1” denotes stop bit. The data in the middle are sent in
bit and the sending frequency accords with checking baud rate.
2) Setting method
After configuring McBSP as GPIO, it sends and receives
data by using software. In the process of sending and receiving
data, the step of parsing data by bit is inevitable. By
programming baud rate checking, GPIO sending and receiving
data subroutine, which can greatly simplify interface data
processing. The baud rate checking subroutine is as follow:
unsigned int SoftUartSpeedDetect(void)
{
volatile unsigned int speedcounter, i;
MCBSP_IO_ENABLE(1);
A. Basic principles
When configuring McBSP as SPI, the McBSP registers
should be set correctly and sequentially. When configuring
McBSP_CLKX as SPI_CLK, and the clock frequency should
be set according to the need of system. Data format can be
selected as 8bit, 12bit, 16bit or 32bit
B. Specific Configuration
In configuration McBSP as SPI, operations on the McBSP
registers should be performed in sequence. The following
routine is an example for initialization.
speedcounter = 0;
// Reset sending and receiving port
while( (int)MCBSP_DRSTAT(1));
RESET_BIT(MCBSP_SPCR_ADDR(0),XRST);
while(!(int)MCBSP_DRSTAT(1))
RESET_BIT(MCBSP_SPCR_ADDR(0),RRST);
{
//Configure registers SPCR PCR RCR XCR SRGR
// Count start bit
spi_config();
speedcounter++;
//Start sampling rate generator
}
SET_BIT(MCBSP_SPCR_ADDR(0),GRST);
while( (int)MCBSP_DRSTAT(1))
asm("nop 2");
{
// Numbers of delay bit before CLK starting
// Count the first data bit
speedcounter++;
LOAD_FIELD(MCBSP_SPCR_ADDR(0),3,CLKSTP,
CLKSTP_SZ);
//Enable receiving and sending of serial port
}
SET_BIT(MCBSP_SPCR_ADDR(0),XRST);
MCBSP_DX_IO_H(1);
SET_BIT(MCBSP_SPCR_ADDR(0),RRST);
/* wait long enough for one char */
asm("nop 2");.
for(i=11*speedcounter;i>0;i--)
VI.
{
//Count data are divided by 2 to obtain actual baud rate
speedcounter >>= 2;
return(speedcounter);
}
}
V.
In system design, it is as possible as to use the peripheral
integrated in DSP. This can improve the ratio of performance
and cost. The McBSP of TMS320C6000 series DSP provide
flexibility to connect to different kinds of interface. The
methods provided here are already used in our embedded
computer systems. The practical using shows that McBSP
which is configured as different interface can work reliably and
effectively.
CONFIGURING MCBSP AS SPI
SPI is a common four-line serial protocol interface,
including MISO (Master Input /Slave Output), MOSI (Master
Output /Slave Input), CLK (Shift CLK) and SS (Slave Select).
It has two working modes---master and slave. The data
synchronization clock of McBSP has Stop and Control choice.
So McBSP is compatible with SPT protocol. McBSP supports
two kinds of SPI transmission format and can be set CLKSTP
bit of SPCR register to decide whether SPI_CLK starts at high
or low level.
CONCLUSION
REFERENCES
[1]
[2]
[3]
F. H. Li, F. Wang, P. K. He, Theory and application of TMS320C6000
series DSPs, 2nd Ed. Beijing: Publishing House of Electronics
Industry,2003. (in Chinese)
Z.X. Lu, H.W. Chen, Y.C. Tai, “Implement of communication between
DSP and PC using McBSP,”Micro-computer, pp. 6-8, May, 2006.(in
Chinese)
Texas Instruments Incorporated. Application Report SPRA633B, 2004.
Download