title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">title="">
摘 要: 介紹了一種基于DSP+UART實(shí)現(xiàn)串行通信的方法,并運(yùn)用在圖文輸入系統(tǒng)中。實(shí)驗(yàn)表明,該方法能夠可靠地實(shí)現(xiàn)TMS320C6713與圖文輸入系統(tǒng)之間的通信。
關(guān)鍵詞: 數(shù)字信號(hào)處理器;異步串行通信;TL16C752B
異步串口由于采用RS-232電平,傳輸距離長(zhǎng)、連線簡(jiǎn)單,因而得到了廣泛應(yīng)用。圖文聲并現(xiàn)的多媒體電話機(jī)的輸入部分是圖文輸入系統(tǒng),該系統(tǒng)使用TI公司的TMS320C6713 DSP, DSP中有同步高速串口,但沒有異步串口,無法與低速設(shè)備進(jìn)行通信。因此如果DSP能通過RS-232/485串口與其他外部設(shè)備進(jìn)行通信,將會(huì)為圖文輸入系統(tǒng)提供極大的方便。圖文輸入系統(tǒng)采用手寫板作為輸入設(shè)備,方便人們?cè)陔娫捊涣髦械氖褂?。手寫板通過電磁感應(yīng)產(chǎn)生電信號(hào),并通過RS-232接口輸出。但是,TI公司生產(chǎn)的TMS320C6000系列的數(shù)字信號(hào)處理器不具有異步串口,故實(shí)現(xiàn)異步通信功能的設(shè)計(jì)方法一般有2種:一種基于軟件編程來實(shí)現(xiàn),通過編程將DSP的多通道緩沖串行接口(McBSP)改為異步通信串口;另一種基于硬件來實(shí)現(xiàn)。采用硬件方法來實(shí)現(xiàn)不占用多通道緩沖串行接口,而且可以根據(jù)外部設(shè)備的需要靈活地設(shè)置波特率。 因此,本文采用TI公司的專用異步串行芯片TL16C752B來實(shí)現(xiàn)串行通信。
1 TMS320C6713 DSP和手寫板簡(jiǎn)介
TMS320C6713是高性能的32位浮點(diǎn)DSP,適用于專業(yè)音頻信號(hào)處理,其主頻高達(dá)300 MHz,處理速度高達(dá)2400 MIPS/1800 MFLOPS。采用改進(jìn)哈佛結(jié)構(gòu)、片上共有264 K×8位存儲(chǔ)器,其中4 K×8位一級(jí)程序緩存、4 K×8位一級(jí)級(jí)數(shù)據(jù)緩存、256 K×8位二級(jí)緩存,并且具有豐富的片上外設(shè)資源,其中就包括2個(gè)同步串口McBSP。此外,TMS320C6713還有32位的EMIP總線、有4個(gè)空間,每個(gè)空間均可與SDRAM、SBSRAM和異步外設(shè)實(shí)現(xiàn)無縫接口[1]。本文將異步外設(shè)TL16C752B映射在EMIP的CE1空間,所以DSP在訪問TL16C752B上的寄存器時(shí)只需要將基地址加上偏移量就可以了。
手寫板可分為2大類:手觸式與電磁感應(yīng)式。手觸板是利用筆觸及到基板時(shí),基板上的電容及電阻發(fā)生作用的變化來起作用。因此,所謂“筆”,可以是任何會(huì)改變電阻或電容的任何物件,例如手指或塑料棒。由于筆必須接觸到基板才能起作用,因此,當(dāng)筆提起后,將不會(huì)產(chǎn)生作用,用起來比較不自然。制造時(shí),由于電阻值與電容值很難做到均勻與精確,所以手觸板有一些先天上的限制。電磁感應(yīng)筆的工作原理:電磁感應(yīng)筆會(huì)放出電磁波,由基板感應(yīng)到后,計(jì)算出筆的位置,由于電磁波能隔空傳導(dǎo),所以筆即使不接觸到基板,基板也能感應(yīng)到。本系統(tǒng)選用電磁感應(yīng)式手寫板,采用接口為RS-232。
2 TL16C752B的組成及結(jié)構(gòu)特點(diǎn)
TL16C752B采用8位異步并行存儲(chǔ)器接口(D7~D0),可與TMS320C6713的外部存儲(chǔ)器接口(EMIF)直接相連,具有2個(gè)異步串行轉(zhuǎn)換通道(UART-A和UART-B),當(dāng)使用48 MHz的輸入時(shí)鐘時(shí),波特率最高可以達(dá)到3 Mb/s。每個(gè)通道包含18個(gè)寄存器,通過地址線A2~A0對(duì)寄存器進(jìn)行尋址,并且分別具有64 B的發(fā)送FIFO和64 B的接收FIFO。UART-A和UART-B分別由片選信號(hào)/CSA和/CSB選通。TL16C752B還提供2個(gè)中斷請(qǐng)求信號(hào)INTA和INTB,分別用于通道A和B申請(qǐng)C6713的中斷。其功能模塊圖如圖1所示。
TL16C752B的各個(gè)寄存器的映射地址[2]如表1所示,其中黑體部分的寄存器為二次尋址的寄存器。
TL16C752B有2種工作流控制模式: 硬件流控制和軟件流控制。使用前者通過請(qǐng)求發(fā)送引腳RTS和允許發(fā)送引腳CTS的硬件連接可自動(dòng)控制串行數(shù)據(jù)流,從而提高系統(tǒng)的有效性;后者則通過使用可編程的Xon/ Xoff 字符來自動(dòng)控制數(shù)據(jù)傳輸。本文采用硬件流控制的方式進(jìn)行電路連接。
3 硬件接口電路
C6713也采用雙電源供電方式,即內(nèi)核是1.8 V,接口是3.3 V,因此TL16C752B可以直接與DSP相連,簡(jiǎn)化了電路。但由于手寫板采用RS-232電平,在RS-232C標(biāo)準(zhǔn)中的電壓相對(duì)地是對(duì)稱的,邏輯“0”的電平為+3 V~+15 V;邏輯“1”的電平為-3 V~-15 V。實(shí)際應(yīng)用中通常由±12 V電源供電,所以與TTL、CMOS接口需電平轉(zhuǎn)換。本系統(tǒng)采用MAX3160來完成電平轉(zhuǎn)換的工作。
TL16C752B的數(shù)據(jù)線D7~D0直接與TMS320C6713的ED7~ED0數(shù)據(jù)線相連,實(shí)現(xiàn)數(shù)據(jù)的傳輸。TL16C752B的片內(nèi)寄存器選擇線A2~A0與TMS320C713的地址線EA4~EA2相連。當(dāng)TL16C752B的片選信號(hào)/CSA、/CSB為有效電平時(shí),分別選中A、B通道。通道A映射為DSP的地址空間為0x80000000到0x80000007, 通道B映射為DSP的地址空間為0xC0000000到0xC0000007。DSP 采用中斷方式接收從手寫板輸入的數(shù)據(jù),通道A、B分別占用DSP的外部中斷6和外部中斷7,如圖2所示。
4 DSP軟件編程
在對(duì)TLC752B訪問之前要對(duì)其進(jìn)行初始化,TL16C752B的初始化程序主要包括以下幾部分:
(1)波特率的設(shè)定。TL16C752B包含一個(gè)可編程的波特率寄存器分為高位寄存器(DLH)和低位寄存器(DLL),用來存儲(chǔ)分頻系數(shù)的高8位和低8位,它可以在輸入時(shí)鐘的基礎(chǔ)上進(jìn)行分頻(最大分頻系數(shù)為216-1),分頻系數(shù)的計(jì)算公式如下:
分頻系數(shù)=輸入時(shí)鐘頻率/(比例系數(shù)×16×期望得到的波特率)
注:當(dāng)MCR寄存器中的bit7為0時(shí),比例系數(shù)為1;當(dāng)MCR寄存器中的bit7為1時(shí),若比例系數(shù)為4。
因此,在輸入時(shí)鐘頻率為30.72 MHz時(shí),若想要獲得9.6 kb/s的波特率就需要分別向DLH和DLL寫入0x00和0xC8。
(2)增強(qiáng)功能的使能及設(shè)置EFR 的相關(guān)位。
(3)對(duì)接收FIFO和發(fā)送FIFO 的設(shè)定, 通過設(shè)置MCR、TCR和TLR這3個(gè)寄存器來實(shí)現(xiàn)。
(4) 傳輸數(shù)據(jù)格式設(shè)定, 包括數(shù)據(jù)位長(zhǎng)度(5位、6位、7位或8位)、停止位長(zhǎng)度(1位、1.5位或2位)、DMA 傳輸模式1或0、奇偶校驗(yàn)、是否使用強(qiáng)制校驗(yàn)?zāi)J?、暫??刂莆坏取1疚脑O(shè)定數(shù)據(jù)長(zhǎng)度為8位,1個(gè)停止位,無奇偶校驗(yàn)位,DMA0模式。
(5)設(shè)置FIFO 控制以及中斷控制寄存器。
TL16C752B 初始化程序如下,程序采用C語言編寫,具有可移植性:
#define baudrate_9k6 0x00c8
#define UartWordLen 0x0003 //數(shù)據(jù)長(zhǎng)度為8
#define UartStopBits 0x0000 //1個(gè)停止位
#define UartParity 0 //奇偶校驗(yàn)位
#define RHR 0x0000<<1
#define IER 0x0001<<1
#define FCR 0x0002<<1
#define LCR 0x0003<<1
#define MCR 0x0004<<1
#define LSR 0x0005<<1
#define MSR 0x0006<<1
#define DLL 0x0000<<1
#define DLH 0x0001<<1
#define EFR 0x0002<<1
Uint8 baudratel,baudrateh,uartdata;
UARTA_Handle = UART_open(UART_ A); //打開UART A通道
/* 設(shè)置波特率. */
UART_rset(UARTA_Handle, LCR,0x80);
BaudRate = baudrate_9k6; //將波特率設(shè)置為9.6 kb/s
baudratel = (UartBaud & 0x00ff);
UART_rset(UARTA_Handle, DLL,baudratel); /*將波特率的低8位字節(jié)賦給DLL寄存器*/
baudrateh = (UartBaud & 0xff00) >> 8;
UART_rset(UARTA_Handle, DLH,baudrateh); /*將波特率的高8位字節(jié)賦給DLH寄存器*/
UART_rset(UARTA_Handle, LCR,0x00);
/* Set word length. */
uartdata = UartWordLen + UartStopBits + UartParity;
UART_rset(UARTA_Handle, LCR,uartdata); //設(shè)置傳輸格式
/* Set FIFO 寄存器. */
UART_rset(UARTA_Handle, FCR,0x02); //復(fù)位FCR寄存器
UART_rset(UARTA_Handle, FCR,0x07); //設(shè)置FCR寄存器
UART_rset(UARTA_Handle, MCR,0x08); //使能UART中斷
/*設(shè)置接收保持寄存器中斷RHR. */
UART_rset(channel, IER, 0x01); //設(shè)置FIFO 接收中斷
UART_rset(channel, MCR,0x49);
通過擴(kuò)展串口完成TMS320C6713與圖文輸入系統(tǒng)串行通信硬件接口比較簡(jiǎn)單、數(shù)據(jù)傳送距離遠(yuǎn)、使用經(jīng)濟(jì)。該電路及其軟件經(jīng)與圖文輸入系統(tǒng)的通信實(shí)驗(yàn)證明, 在波特率為9 600 kb/s時(shí), 能夠可靠地實(shí)現(xiàn)兩者之間的通信。
參考文獻(xiàn)
[1] Texas Instruments. TMS320C6713, TMS320C6713B Floating-point digital signal processors.2004.
[2] Texas Instruments. TL16C752B 3. 3 - V Dual UART with 64 B FIFO.2000.