Home

pc to dsp link using rs-232 over

image

Contents

1. break comm2_get 1 break ti Port Input character from port window 55 9 76 24 gotoxy 3 1 insline cprintf 2 x r n ch d l l SA 1 1 l F if k 1 if ch 0 strncat r2string kp1 3 if ch 1 strncat r2string kil 3 if ch 2 strncat r2string kp2 3 if ch 3 strncat r2string ki2 3 if ch 4 strncat r2string kp3 3 if ch 5 strncat r2string ki3 3 if ch 6 strncat r2string x6 2 if ch 7 strncat r2string x7 2 if ch 8 strncat r2string x8 2 if ch 9 strncat r2string x9 2 if ch 10 strncat r2string x10 3 if ch 11 strncat r2string vdcr if ch 12 strncat r2string idr 3 if ch 13 strncat r2string iqr 3 if ch 14 strncat r2string ddr 3 if ch 15 strncat r2string dqr 3 else itoa ch cha 16 if k 2 strncat r2string VH 4 if k 3 strncat r2string VL 4 strncat r2string cha 2 k if k 4 k 1 window 55 9 76 24 gotoxy 1 1 insline cprintf P 2 C s r n strset r2string r2string break Dy r2string O removes hendl res removes hendl B 163 res 4 r r 1 1 l Get Key Function int getkey void int key if kbhit return 1 return key getch
2. Function analize analizes inputed command int analize char string define KPI 6b7031 define KIl 6b6931 define KP2 6b7032 define KI2 6b6932 define KP3 6b7033 define KI3 6b6933 define X6 7836 define X7 WS define X8 7838 define X9 7839 define X10 783130 define VDCR 76646372 define IDR 696472 define IQR 697172 define DDR 646472 define DOR 647172 char str int com if strlen string gt 8 cprintf ERROR Invalid return 1 strcpy str string com 1 if strcmp str KP1 0 if strcmp str KI1 0 if strcmp str KP2 0 if strcmp str KI2 0 if strcmp str KP3 0 if strcmp str KI3 0 if strcmp str X6 0 if stremp str X7 0 if strcmp str X8 0 if strcmp str X9 0 if stremp str X10 0 key key getch strlen string command n r com 0x00 com 0x01 com 0x02 com 0x03 com 0x04 com 0x05 com 0x06 com 0x07 com 0x08 com 0x09 com 0x0a B 164 lt 4 256 strcmp strcmp str strcmp str SEE str Str strcmp strcmp Ph FH FH FH Fh H H H H H h com 1 return com Check function int check char string define A 61 define B 62 define C 63 define D 64 define E 65 define F 66 define O 30 char str int i 0 chw 1
3. reseting of buffer COMM port parameters state of int mask reg forbide all keep old vector vector change allowed interrupts outportb IMR mask_reg installed2 1 installation flag return 0 port installed comml_setup void comml_setup int speed int parity int bits int stopbit unsigned char param int divisor outportb comml_port LCR 0x80 set DLAB set speed divisor int 115200L speed outportb comml_port DLL divisor amp Ox00ff outportb comml_port DLH divisor gt gt 8 amp Ox00ff reset DLAB mask interrupts param 0 param unsigned char parity bits stopbit outportb comml_port LCR param a Ox3f outportb comml_port IER 0 reset leftover values param inportb comml_port LSR interrupt for send transmit of charc RDR THR clean interrupts outport comml_port IER 3 type of interrupt inportb comml_port IIDR reset IIDR inportb comml_port RDR reset RDR comm2_setup void comm2_setup int speed int parity int bits int stopbit unsigned char param int divisor outportb comm2_port LCR 0x80 set DLAB set speed divisor int 115200L speed outportb comm2_port DLL divisor amp Ox00ff outportb comm2_port DLH divisor gt gt 8 amp Ox00ff reset D
4. define DL 0 least sig byte baud rate divisor define DLH 1 most sig when line ctl bit7 1 define IER d interrupt enable register define IIDR 2 interrupt idnetification register bit 0 gt more than one interrupt bit 1 2 gt interrupt type 00 gt change in MSR 01 gt THR is empty 10 gt Data is received 11 gt Error in receive or error ZS define LCR 3 line control register define LSR 5 line status register define IN_BUFSIZE 8192 input buffer size define OUT_BUFSIZE 256 output buffer size functions int comml_install int port int comm2_install int port void comml_setup int speed int parity int bits int stopbit void comm2_setup int speed int parity int bits int stopbit int comml_open int port int speed int parity int bits int stopbit int comm2_open int port int speed int parity int bits int stopbit int comml_remove void int comm2_remove void int comml_get void int comm2_get void void com void com void com void com ml pu m2_pu ml pu m2_pu global var ine ch t AE Ch ts char str ts char str iables void interrupt oldvectorl interrupt handler static unsigned char rcvbuffl IN_BUFSIZ receiving buffer Gl u B 166 static unsigned char sndbuff1 OUT_BUFSIZE
5. transm buff static unsigned int rcvbuffsl 0 beg of rec buff static unsigned int rcvbuffel 0 end of rec buf static unsigned int sndbuffsi 0 beg of tran buf static unsigned int sndbuffel 0 end of tran buf static unsigned int comml_int 0 interrupt vector static unsigned int comml_port 0 port base address static unsigned int comml_mask 0 int mask static unsigned int installedl 0 flag installation static unsigned int outputl_busy 0 output indicator void interrupt oldvector2 interrupt handler static unsigned char rcvbuff2 IN_BUFSIZE receiving buffer static unsigned char sndbuff2 OUT_BUFSIZE transm buff static unsigned int rcvbuffs2 0 beg of rec buff static unsigned int rcvbuffe2 0 end of rec buf static unsigned int sndbuffs2 0 beg of tran buf static unsigned int sndbuffe2 0 end of tran buf static unsigned int comm2_int 0 interrupt vector static unsigned int comm2_port 0 port base address static unsigned int comm2_mask 0 int mask static unsigned int installed2 0 flag installation static unsigned int output2_busy 0 output indicator comml_interrupt void interrupt comml_interrupt void unsigned char state disable while state inportb comml_port IIDR amp 1 switch state case 2 output if sndbuffsl sn
6. char num cprint f ERROR 0 com Ox0c com 0x0b com 0x0d com 0x0e com 0x0f Invalid convertes number from ascii hex to int stropy str string for i 0 i lt 10 i itoa i 30 num 10 if strcmp str num 0 chw i if strcmp str O 0 chw 0x00 if strcmp str A 0 chw 0x0a if strcmp str B 0 chw 0x0b if strcmp str C 0 chw 0x0c if strcmp str D 0 chw 0x0d if strcmp str E 0 chw 0x0e if strcmp str F 0 chw 0x0f if chw 1 cprintf ERROR Invalid value n r return chw File com c include lt dos h gt interrupt parameters B 165 command n r define define define define define define define define define define define define define define define IMR ICR EOI 0x21 mask interuppt register 0x20 end of int reg 0x20 end of int data Comm Port Parameters COM1_PORT Ox03f8 base address of port 1 COM2 PORT Ox02f8 base address of port 2 COM3 PORT 0x03e8 COM4_PORT 0x02e8 COM1_INT Ox0c COM2_INT 0x0b COM3_INT Ox0c COM4_INT 0x0b COM1_MASK 0x10 INT mask for IMR IRQ4 COM2_MASK 0x08 Int mask for IMR IRQ3 COM3_MASK 0x10 COM4_MASK 0x08 8250 register ofset define THR 0 transmit hold register define RDR 0 input data register
7. amp v2 valuel v3 lt lt 4 Ox0f amp v4 insline cprintf P 1 C x VH x valuel comml_put kom comml_put valueh B 160 comml_put valuel else strcpy string emptystring strset string break case 32 COM2 kom analize com vl check valuel v2 check value2 r v3 check value3 v4 check value4 1 if kom 1 amp amp vl 1 amp amp v2 1 s v3 1 amp amp v4 1 valueh vl lt lt 4 0x0f amp v2 Oxf0 valuel v3 lt lt 4 Ox0f amp v4 Oxf0 cprintf P 1 C x VH x VL x n kom valueh valuel comm2_put kom comm2_put valueh comm2_put valuel else strcpy string emptystring strset string break default cprintf ERROR Invalid port n r break i 1 gotoxy 1 1 insline insline insline strcpy string emptystring strset string break case ALTX exit quit 1 clrscr strcpy string emptystring strset string window 1 1 80 25 textbackground BLACK for i 0 i lt 25 i cprintf r n break case ALTC clear screen elrser X strcpy string emptystring strset string i 1 break case ALTH strcpy rlstring emptystring B 161 switch strset rlstring J 1 break case ALTD strcpy r2string strset r2string k 1 bre
8. amp parity are user can be used to electrically interface 5 VDC to the RS 232 line voltage levels The operation of the transmitter setup routine is completely independent on the the receiver setup routine operation Although both tx and rx use the same timer as a master clock source the xmitted bits need not be in sync with the received bits The default state of the reciever is OFF so the turn_rx_on subroutine must be used to enable RX Calling Argument for autobaud load the baud constant dm baud_period Proc_frequency 3 Baudrate 1 Useful Subroutines init_uart Must be called after system reset get_char_axl Waits for RX input and returns with it in axl out_char_axl Waits for last TX output and transmits axl Must be called to enable th Can be used to ignore input RX data turn_rx_on turn_rx_ofrf Useful Flag DM flag_rx_ready If this DM location is all the UART is ready to rx new word data from receipt of RX data ones it indicates that TE it Lisi Zero then data is being received Can be used for xon xoff flow control Author Fares Eidi 21 May 90 Analog Devices Inc modified Christoph D Cavigioli 17 Dec 90 modified Steven Cox 20 Dec 91 extensive rewrit modified Steven Cox 31 Dec 91 Reset flag_rx_stop_yet to 1 Comments modified Steven Cox 11 Feb 92 Added support for autobaud modified Philip Holdgate 02 Apr 92 modified for Apps N
9. is to be sent this time around dm timer_tx_ctr ar if no bit is to be sent if ne jump receiver then decrement ctr and return sri dm internal_tx_buffer shift out LSB of internal_tx_buffer sr lshift srl by 1 hi into SRI Test the sign of this bit dm internal tx buffer sri set or reset FLAG OUT accordingly ar pass sr0 this effectively clocks out the if ge reset flag out word being xmitted one bit at a time if It set flag out LSB out first at FLAG OUT ay0 3 reset timer ctr to 3 i e next bit dm timer_tx_ctr ay0 will be sent after 3 timer interrupts ayO0 dm bits_left_in_tx number of bits left to be xmitted ar ay0 1 is now decremented by one dm bits left in tx ar indicating that one is now xmitted B 177 if gt jump receiver if no more bits left then ready ax0 1 flag is set to true indicating dm flag_tx_ready ax0 a new word can now be xmitted Receiver Section receiver ax0 dm flag_rx_off Test if receiver is turned on ar pass ax0 if ne rti ax0 dm flag rx stop yet Test if finished with stop bit of ar pass ax0 last word or not if finished then if ne jump rx test busy continue with check for receive ayO dm timer rx ctr decrement timer ctr and test to see ar ay0 1 if stop bit period has been reached dm timer_rx_ctr ar if not return and wait if ne rti ax0 1 if stop bit is reached then reset dm flag_rx_sto
10. 0x08 0x08 ze char string char string Exit Clear Screen amp Send Buffer Clear COMI Receiver Buffer Clear COM2 Receiver Buffer Parity Bit Carrier signal Space Back Space Enter get key from keyboard analizes given command converts number from ascii hex to int B 158 void main void int portl 1 int speedl 9600 int parityl NPARITY int datal BIT8 int stopil STOPI int port2 2 int speed2 9600 int parity2 NPARITY int data2 BIT8 int stop2 STOPI int quit 0 quit the program int ch character from keyboard or port int chp int i 1 j 1 k 1 char stringtemp 25 char string rlstring r2string char emptystring int len lenl len2 char chal2 char port com char valuel value2 value3 value4 value5 int kom vl v2 v3 v4 valueh valuel intro switch comml_install port1 hendler instalation case 1 printf Port d is already open n port1 return case 2 printf Port d can not be opened n portl return default break comml_setup speedl parityl datal stopll parametars switch comm2_install port2 hendler instalation case l printf Port d is already open n port2 return case 2 printf Port d can not be opened n port2 return default break c
11. 2101 EZ LAB Board and an interface board with an RS 232 line driver chip connected to the FlagIn and FlagOut pins on the J2 Sport Connector you must supply the incoming signals to the line driver chip As an alternative a 21020 EZ LAB Board could be used since it already has all of the necessary hardware ADSP 21xx and RS 232 line driver chip however in this case the interrupt vector table would have to be modified for ADSP 2111 requirements and connected to a terminal such as an IBM PC running PROCOMM again you supply the input data via PROCOMM in this case Author Philip Holdgate Analog Devices 03 Apr 1992 Modified Brian Baker Analog Devices 27 Apr 1992 KERRIE RUKE KK RRR ERR E IER ER EA KR RRR RRA KA RAR BER KAS KR RRR IER KR module AUTOEcho UART initialize baudrate etc UART enable the rx section of the uart UART disable the rx section of the uart UART output a character UART wait amp get input character UART timer interrupt routine for RX and TX external init_uart external turn_rx_on external turn_rx_off external out_char_axl external get_char_axl external process_a_bit a a a aaa external baud period UART load with period from autobaud Interrupt Vector Table JUMP START RTI NOP NOP Reset Vector RTI NOP NOP NOP IRQ2 Interrupt
12. sndbuff2 sndbuffs2 amp 1 0 sndbuffs2 sndbuffe2 0 comm2_port RDR if already insalled reseting of buffer parameters Changing interrupt vectors mask_reg inportb IMR outportb IMR Oxff oldvectorl getvect setvect comml_int comml_int comml_interrupt comml_mask IMR mask_reg mask_reg mask_reg amp outportb Oxff installedl 1 state of int mask reg forbide all keep old vector vector change allowed interrupts installation flag return 0 comm2 install nstall int comm2_i int port unsigned char mask_reg if installed2 1 return 1 rcvbuf fs2 rcvbuffe2 sndbuffs2 sndbuffe2 0 pointers switch case l comm2_port COM1_PORT comm2_int COM1_INT comm2_mask COM1_MASK port break case 2 comm2_port COM2_PORT comm2_int COM2_INT comm2_mask COM2_MASK break case 3 comm2_port COM3_PORT comm2_int COM3_INT comm2_mask COM3_MASK break case 4 comm2_port COM4_PORT comm2_int COM4_INT comm2_mask COM4_MASK break default return 2 end switch Changing interrupt vectors mask_reg inportb IMR EK outportb IMR Oxff oldvector2 getvect comm2_int setvect comm2_int comm2 interrupt mask reg mask reg amp comm2 mask Oxff B 169 port installed if already insalled
13. ART is busy dm flag_tx_ready ax0 rts get an input character output axl B 179 modifies ax0 get_char_axl ax0 dm flag_rx_no_word ar pass ax0 if ne jump get_char_axl if no rx word input then wait axl dm user_rx_buffer get received ascii character ax0 1 dm flag rx no word ax0 word was read rts output a character input axl modifies ax0 srl sr0 ar out_char_axl ax0 dm flag tx ready ar pass ax0 if eq jump out char axi if tx word out still pending then wait dm user tx buffer axi call invoke UART transmit send it out rts nable the RX section modifies ax0 turn rx on ax0 0 dm flag_rx_off ax0 rts disable the RX section modifies ax0 turn_rx_off ax0 1 dm flag rx off ax0 LESS endmod File AECHO1 DSP FZRKAKKAKKAKAKKAKAKAKKKAKAKAKAKAKAXAKKAKAKKKAAKAKAKAKKAAKKAKKKAKAKAKAKK dek EK ADSP 2101 EZLAB UART Example AUTOECHO DSP This program utilizes the UART code listed in Appendix 1 and provided on the disk UART DSP to provide a simple example of how to use the UART monitor This program reads a character in and writes echos it back out The program also utilizes the Autobaud capability described and listed in Appendix B and modified slightly for this example the modified code is also provided on the disk AUTOECHO DSP B 180 he only hardware required is an ADSP
14. Appendix B HIGHER LEVEL COMMUNICATION EXAMPLE PC TO DSP LINK USING RS 232 OVER OPTICAL FIBER B 1 SYSTEM DESCRIPTION PC Interface Board The PC interface board Figure B 1 is used to convert the electrical RS 232 signals from the PC into the optical signals which will be transmitted over the optical fiber The board has two communication port connectors It is capable to separately drive two pairs of transmitting and receiving diodes The PC outputs the voltage levels of 11V Signals are converted into the TTL CMOS signals using High Speed CMOS RS 232 Driver Receiver ADM242 Logical 1 is translated from 11V to 5V and logical 0 from 11V to OV After inversion these signals drive the HFBR 1521 transmitter Inversion is needed to reverse the effect of the B 150 common emitter circuit inside of the transmitting diode Block diagram of this system is shown on Figure B 2 4 lu mou L Ju F Tx Alu DE ME ri H o D N ADM242 q riz Rx E N itt L lu 130 l H L L EE EE LI Tx emeng H lu I 74LSO4N 4 bDS75451 d L CZ OO A EZE LAT Rx Intrface Board Figure B 2 Block di
15. Devices code B 3 Since the code didn t work properly some modifications had to be made Chapter B 3 This code is written in the ADSP 2100 Family Assembler It uses the FLAG_IN and the FLAG_OUT pins of the DSP microprocessor as receiving and transmitting pins The operation of the transmitter setup routine is completely independent of the receiver setup routine operation Both Tx and Rx use the same timer interrupt as a master clock source Parameters such as the number of bits per word baud rate length of stop bit and parity are user programmable B 155 Table B 1 Commands supported in PC Communicator Command Hex Value Description MC NON ANE KO lee See kees B 156 The communication baud rate depends on the value PERIOD stored into TCOUNT and TPERIOD memory mapped control registers Table B 2 The internal timer is set to run at three times the baud rate A microprocessor executes the PROCESS_A_BIT routine on every timer interrupt This routine checks if there is a bit to be sent or received and if that is true it initiates the appropriate action Bits need to be transmitted and or received only once every three interrupts Signal transmission utilizes the FLAG_OUT pin Depending on the information the pin is set to high or low When receiving the routine checks the status of the FLAG_IN pin Because of synchronization problems the reception is more critical than transmission The algorithm of this
16. ED SPFIL TLE TAERA Received xxxx r n window 4 9 25 24 textcolor WHITE textbackground RED for i 0 i lt 28 i cprintf window 55 9 76 24 textcolor WHITE B 173 Center r n r n r n r n r n r n textbackground RED for i 0 i lt 24 i cprint r n return 0 void sentout int ch window 9 10 22 21 cprintf probal r n cprintf proba2 r n cprintf proba3 r n cprintf proba4 r n cprintf proba5 r n cprintf proba6 r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n cprintf probal r n B 3 DSP FILES File UARTI DSP 2 5 EZ 2 2 5 2 2 2 2 2 5 2 2 2 2 2 2 2 2 2 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 202 ADSP 2101 Family Software UART UART DSP This uses FLAG_IN FLAG_OUT and the TIMER of ADSP 2101 to interface to an RS 232 asynchronous serial device such as a VT100 terminal ex ADSP 2101 FLAG OUT gt AD233 gt RS 232 RX ADSP 2101 FLAG_IN lt AD233 lt RS 232 TX TIMER maintains baudrate Parameters bits word baudrate programmable An RS 232 line driver chip such as the AD233 stopbits
17. LAB mask interrupts param 0 param unsigned char parity bits stopbit outportb comm2_port LCR param amp Ox3f outportb comm2_port IER 0 reset leftover values param inportb comm2_port LSR B 170 interrupt for send transmit of charc RDR THR clean interrupts outport comm2_port IER 3 type of interrupt inportb comm2_port IIDR reset IIDR inportb comm2_port RDR reset RDR comml_remove int comml_remove void if installedl 1 return 1 comm_interrupt hasn t been installed setvect comml_int oldvectorl returning old vector values installedi 0 return 0 comm2_remove int comm2_remove void if installed2 1 return 1 comm2_interrupt hasn t been installed setvect comm2_int oldvector2 returning old vector values installed2 0 return 0 commi_get int comml_get void int com_char if rcvbuffsl rcvbuffel return 1 com char int rcvbuffl rcvbuffs1 rcvbuffsl IN_BUFSIZE return com_char comm2_get int comm2_get void int com_char if rcvbuffs2 rcvbuffe2 return 1 com_char int rcvbuff2 rcvbuffs2 rcvbuffs2 IN_BUFSIZE return com_char B 171 comml_put void comml_put int ch if outputl_busy 1 outportb comml_port THR ch outputl_busy 1 window 4 9 25 24 gotoxy 3 1 insline epr
18. RTI NOP NOP NOP SPORTO Transmit Interrupt RTI NOP NOP NOP SPORTO Receive Interrupt RTI NOP NOP NOP SPORT1 Transmit Interrupt RTI NOP NOP NOP SPORT1 Receive Interrupt JUMP PROCESS_A BIT RTI NOP NOP Timer Interrupt Initialization Routine START DM Baud_Period AR UART Autobaud CALL Init_UART Initialize UART CNTR 15000 Wait approximately one DO XLOOP UNTIL CE character to insure last one XLOOP NOP made it through CNTR 15000 DO YLOOP UNTIL CE YLOOP NOP CALL Turn_RX_On Enable UART Receive ain System Loop DO MLOOP UNTIL FOREVER CALL Get_Char_AX1 Read in character B 181 CALL Out_Char_AX1 and Echo it back out LOOP NOP ENDMOD B 182 REFERENCES B 1 Aleksandar Radovanovic PC Modemske Komunikacije Beograd Tehnicka knjiga 1991 B 2 ADSP 2100 Family User s Manual Analog Devices 1995 B 3 Cavigioli C D Holdgate P and Backer B UART Example Analog Devices http www analog com April 1992 B 183
19. agram of the type of used signals DSP Interface Board DSP Interface board Figure B 3 is very similar to the PC interface board described previously The difference is that in this case there is no need to convert signals to RS B 151 232 voltage level because the DSP works with 0 5V voltages Signals FLAG_IN FLAG_OUT GND and VCC are taken directly from ADSP 2101 pins 74LS04N BRWN ra Figure B 3 DSP Interface Board Communication Software Communication Protocol We based the communication data format on the RS 232 standard This is a standard for asynchronous serial communication Signals are transmitted mostly over fiber so the RS 232 distance restrictions do not apply in this case This standard defines that if no data are to be sent the line is in MARK state 11V Transmission starts with a START bit i e SPACE state 11V Following the START bit data bits are sent logical ones have negative and logical zeroes positive voltage levels The next is the PARITY bit followed by the STOP bit The STOP bit can have duration of 1 1 5 or 2 bits The RS 232 standard does not define the number of data bits Usually there are 5 7 or 8 bits Data bit are sent in reverse order B 152 The PC side of the system follows this standard The format used here is one START bit 8 data bits and one STOP bit At the PC Interface Board signals are converted from the RS 232 level to the TTL CMOS level and then to optic
20. ak default add letter to the gotoxy i L putch ch itoa ch strncat string break ch comml_get case 1 break default insline cha 16 cha 2 Port Input emptystring Di character from port window 55 9 76 24 gotoxy 3 1 cprintf 1 x r n ch if j 1 if ch 0 strncat ristring kpl 3 if ch 1 strncat ristring kil 3 if ch 2 strncat ristring kp2 3 if ch 3 strncat rlstring ki2 3 if ch 4 strncat rlstring kp3 3 if ch 5 strncat rlstring ki3 3 if ch 6 strncat rlstring x6 2 if ch 7 strncat ristring x7 2 if ch 8 strncat ristring x8 2 if ch 9 strncat ristring x9 2 if ch 10 strncat ristring x10 3 if ch 11 strncat ristring vdcr 4 if ch 12 strncat ristring idr 3 if ch 13 strncat ristring iqr 3 if ch 14 strncat ristring ddr 3 if ch 15 strncat ristring dqr 3 else itoa ch cha 16 if j 2 strncat ristring VH 4 if j 3 strncat ristring VL 4 strncat ristring cha 2 j if j 4 j 1 cprintf P 1 C s r n window 55 9 76 24 gotoxy 1 1 insline len strlen rlstring strcpy rlstring B 162 ristring emptystring string switch ch case defaul comml_remove comm2_remove strset rlstring ristring
21. al signals Data is then transmitted over fiber and after reception converted back to TTL CMOS at the DSP side An example of sending a hexadecimal character 41 binary 01000001 is shown in Figure BA Start 1 0 0 0 0 0 l 0 Stop Figure B 4 RS 232 Standard for sending hexadecimal character 41 An RS 232 connector can have 9 Figure B 5 a or 25 pins Figure B 5 b For PC DSP communication only three are used receive pin 2 on 9 pin socket or pin 3 on 25 pin transmit pin 3 or pin 2 and ground pin 5 or 7 The ground is only connected to the PC interface board and TX and Rx signals are transmitted over fiber This makes the DSP and PC electrically isolated a b Figure B 5 RS 232 Connectors a 9 pin b 25 pin B 153 PC Software PC communication software can be based on the polling method or interrupt B 1 If polling is used the program periodically checks the state of the serial port It is easier to write software in this manner but the limitation is that communication speed can not be reliable above 1200bps This is the reason our software PC DSP Communicator listed in Chapter B 2 is written in C and uses the interrupt method During this project several versions of this program have been written In the first version only ASCII characters could be sent and received The second version allowed hexadecimal input and output The latest version is customized for the PEBB system The PC DSP Communicator
22. dbuffel outputl_busy 0 else outportb comml_port THR sndbuffl sndbuffsl outputl_busy 1 if sndbuffsl break case 4 input rcvbuffl rcvbuffel inportb comml_port RDR rcvbuffel IN_BUFSIZE break default break outportb ICR EOI enable sndbuffel sndbuffsl sndbuffel 0 comm2_interrupt void interrupt comm2_interrupt void unsigned char state B 167 disable while state switch state case 2 output if sndbuffs2 sndbuffe2 else outportb comm2_port THR output2_busy 1 if sndbuffs2 break case 4 input revbuff2 rcvbuffe2 inportb rcvbuffe2 IN_BUFSIZE break default break inportb sndbuffe2 outportb ICR EOI enable Wi comml_install int comml_install int port unsigned char mask_reg if installedl 1 return 1 rcvbuffsil rcvbuffel sndbuffsi sndbuffel 0 pointers switch case l comml_port COM1_PORT comml_int COM1_INT comml_mask COM1_MASK port COMM port break case 2 comml_port COM2_PORT comml_int COM2_INT comml_mask COM2_MASK break case 3 comml_port COM3_PORT comml_int COM3_INT comml_mask COM3_MASK break case 4 comml_port COM4_PORT comml_int COMA4_INT comml_mask COM4_MASK break default return 2 end switch B 168 comm2_port IIDR output2_busy
23. has the ability to send and receive data simultaneously from and to ports COMI and COM2 Communication speed baud rate length of stop bit and parity are user programmable and do not have to be the same for both ports The PC has to have a mouse driver installed The command string has this format e lidraa0O The PC interprets this as Send to port COMI command 0x03 data 0x23 and Ox4a so the three bytes will be sent using COMI in this order 0x03 0x23 and Ox4a The Figure B 6 shows the line signals in this case Shown are the waveforms the signal transmitted by the PC TX PC the same signal received at the DSP side RX DSP the same signal echoed by DSP TX DSP after a processing delay and that signal received by PC RX PC Communication speed is 9600bauds one byte of data with one START and one STOP bit lasts 1 024ms B 154 Analyzer Haveform MACHINE 1 Acq Control Cancel Accumulate TX PE PC Center MN C Jos Screen SE ESE cS Pee ta O EE to x UTRA to 0 F300 US ESE O20 ms cS 260 Pee EE O24 ms UTRA O24 ms Figure B 6 Command string idr aa 00 A command string has to be written in this exact order otherwise typed in commands are rejected This is done for safety purposes For now there are only 16 commands They are listed in table BI Received bytes are interpreted as they are received three at the time DSP Software The DSP software used for communication purposes is based on an Analog
24. intf 1 0x r n ch else while sndbuffel gt OUT_BUFSIZE sndbuf f1 comm2_put sndbuffel ch void comm2_put int ch if output2 busy 1 outportb comm2_port THR ch output2_busy 1 window 4 9 25 24 gotoxy 3 1 insline eprintf 2 0x r n ch else while sndbuffe2 gt OUT_BUFSIZE sndbuff2 comml_puts void comml_puts sndbuffe2 ch char str int ch whil ch str comml_put ch comm2_puts void comm2_puts char str int eh whil ch str comm2_put ch B 172 File intro c include lt conio h gt int intro void int intro void int 1 celrscr window 22 2 80 7 textcolor WHITE textbackground BLUE highvideo cprintf Cprintf lowvideo cprintf cprint cprint PC DSP Communicator h Virginia Power Electronics Virginia Tech m Fh t gt window 32 13 51 21 highvideo textcolor WHITE 1 LIGHTBLU textbackground E cprintf r n cprintf MENU r n cprintf r n cprintf ALT C Clr Send r n cprintf ALT H Clr COMI r n cprintf ALT D Clr COM2 r n cprintf ALT X Exit hk cprintf r n window 4 8 26 10 textcolor WHITE textbackground RED Cprinti Sent xxxx r n window 55 8 76 10 textcolor WHITE textbackground R
25. omm2_setup speed2 parity2 data2 stop2 parametars B 159 window 4 switch ch case case case case many parameters n r 1 amp amp v3 l amp amp IESSE Oxf0 VL x n r kom v4 1 valueh 9 25 24 getkey Keyboard Input 1 no key is pressed break SPACE space separator gotoxy i L strncat string 1 printf break DEL backspace gotoxy i 1 putchar ch strncpy stringtemp string len strlen string 2 strncpy string stringtemp string len 0 break CR strlen string len Enter cprfintft n port strtok string com strtok NULL cprintf C s n r com valuel strtok N ee E cprintf VL1 s n r value2 strtok N ek my cprintf VL2 s n r value3 strtok N EA cprintf VL3 value4 strtok N cprintf VL4 s n r vi MJ value5 strtok N if UL valuel value2 UL Q value3 UL value4 WI d cprintf ERROR UL Ir es 0 Ss n r strlen valu n r Too cprintf P s n r port switch atoi port case 31 COMI kom analize vl check valuel v2 check val v3 check value3 v4 check val if kom 1 strlen value5 0 valueh vl lt lt 4 amp amp v2 amp amp 0x0f
26. ote cleaned up modified Ivana Milosavljevic 06 Avg 97 cleaned from cleaning up KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK RRR RAR RE module UART The Constants below must be changed to modify uart parameters const tx num of bits 10 start bits tx data bits stop bits const rx_num_of_bits 8 rx data bits start stop bits not counted const RX BIT ADD Ox0100 1 rx num of bits const TX BIT ADD Oxfe00 Oxffff lt lt tx data bits 1 These constants can be used if autobaud is not needed B 175 const PERIOD 74 not tested 13 amp 57600 PERIOD Proc_frequency 3 Baudrate 1 const PERIOD 112 not tested 13 amp 38400 PERIOD Proc_frequency 3 Baudrate 1 const PERIOD 347 13 amp 19200 PERIOD Proc_frequency 3 Baudrate 1 const PERIOD 456 13 amp 14400 PERIOD Proc_frequency 3 Baudrate 1 const PERIOD 688 9600 const PERIOD 2740 2400 Definitions of memory mapped control registers const SCALE Ox3ffb const TCOUNT Ox3ffc const PERIOD Ox3ffd const System_Control_Reg Ox3fff entry init_uart UART initialize baudrate etc entry out_char_axl UART output a character entry get_char_axl UART wait amp get input character entry turn_rx_on UART enable the rx
27. p_yet ax0 to wait for next word dm flag_rx_ready ax0 ax0 dm internal_rx_buffer copy internal rx buffer dm user rx buffer ax0 to the user rx buffer ax0 0 indicated that a word is ready in dm flag rx no word ax0 the user rx buffer rti rx_test_busy ax0 dm flag_rx_ready test rx flag if rcvr is not busy ar pass ax0 receiving bits then test for start If it if eq jump rx_busy is busy then clk in one bit at a time if flag_in jump rx_exit Test for start bit and return if none ax0 0 dm flag_rx_ready ax0 otherwise indicate rcvr is now busy dm internal_rx_buffer ax0 clear out rcv register ax0 4 timer runs 3x baud rate so rcvr dm timer_rx_ctr ax0 will only rev on every 3rd interrupt initially this ctr is set to 4 This will skip the start bit and will allow us to check FLAG_IN at the center of the received data bit a aaa ax0 rx num of bits dm bits left in rx ax0 EX exit rel rx_busy ayO0 dm timer_rx_ctr decrement timer ctr and test to see B 178 rcv pad_ ar ay0 1 if bit is to be rcvd this time around dm timer_rx_ctr ar if not return else receive a bit if ne rti Shift in rx bit ax0 3 reset the timer ctr to 3 indicating dm timer_rx_ctr ax0 next bit is 3 timer interrupts later ayO RX BIT ADD ar dm internal rs buffer if not flag in jump pad zero Test RX in
28. program is such that the reception delay is less than one third of a bit duration plus the delay through hardware With the baudrate set to 9600 the start bit is received in the worst case in 30us after the beginning of its transmission The next time FLAG_IN is checked is after four timer interrupts which allows the checking of FLAG_IN at the center of the received bit it makes reception more reliable Signals outputted by the DSP are very clean and the DSP provides a good time resolution This makes this communication very reliable in tested conditions Some problems may occur in noisier environments in which case the parity check should be used Table B 2 Appropriate PERIOD values for different communication speeds Baudrate PERIOD 2400 2740 9600 688 14400 450 19200 347 B 157 B 2 PC FILES PC Communicator File main c include include include include include include define define define define define define define define define define define define define define define define FUNCTI int getke int anali int check lt stdio h gt lt stdlib h gt lt string h gt lt conio h gt lt dos h gt lt graphics h gt ALTX 301 ALTC 302 ALTH 291 ALTD 288 NPARITY EPARITY OPARITY BIT7 0x02 BIT8 0x03 STOP1 0x00 STOP2 0x04 CARRIER DWORD Ox11 SPACE Ox20 DEL 0x08 CR Ox0d ONS y void 0x00 0x18
29. put bit and ar ar ay0 add in a 1 if hi zero sr lshift ar by 1 lo Shift down to ready for next bit dm internal_rx_buffer sr0 ayO0 dm bits_left_in_rx if there are more bits left to be rcvd ar ay0 1 then keep UART in rcv mode dm bits left in rx ar and return if gt rti if there are no more bits then That was the last bit ax0 3 set timer to wait for middle of the adm timer rx ctr axo0 stop bit ax0 0 flag indicated that uart is waiting dm flag_rx_stop_yet ax0 for the stop bit to arrive E invoke_UART_transmit subroutine This is the first step in the transmit process The user has now loaded user_tx_buffer with the ascii code and has also invoked this routine invoke_UART_transmit ax0 3 initialize the timer decimator ctr dm timer_tx_ctr ax0 this divide by three ctr is needed since timer runs 3x baud rate ax0 tx_num_of_bits this constant is defined by the dm bits_left_in_tx ax0 user and represents total number of bits including stop and parity ctr is initialized here indicating none of the bits have been xmitted sril 0 SrO TX BIT ADD upper bits are hi to end txmit with hi ar dm user tx buffer transmit register is copied into sr sr or lshift ar by 1 lo the internal tx reg amp left justified ro dm internal_tx_buffer sr0 before it gets xmitted ax0 0 indicate that the U
30. section entry turn_rx_off UART disable the rx section entry process_a_bit UART timer interrupt routine for RX and TX global flag_rx_ready global baud_period Var flag_tx_ready flag indicating UART is ready for new tx word Var flag_rx_ready flag indicating UART is ready to rx new word Var flag_rx_stop_yet flag tells that a rx stop bit is not pending var flag rx no word indicates a word is not in the user rx buffer var flag rx off indicates a that the receiver is turned off var timer tx ctr divide by 3 ctr timer is running amp 3x baudrate var timer rx ctr divide by 3 ctr timer is running amp 3x baudrate var user tx buffer UART tx reg loaded by user before UART xmit var user rx buffer UART rx reg read by user after word is rcvd Var internal_tx_buffer formatted for serial word adds start amp stop bits user tx buffer is copied here before xmission var internal_rx_buffer Var bits_left_in_tx number of bits left in tx buffer not cika out Var bits left in rx number of bits left to be rcvd not clkd in var baud_period loaded by autobaud routine init_uart ax0 0 dm TSCALE ax0 ax0 PERIOD decrement TCOU ftdm baud period from Initializing subrou tine NT every instruction cycle autobaud or use constant ax0 PERIOD B 176 and comment in the appropriate constant dm TCOUNT ax0 dm TPERIOD ax0 interrup
31. ts generated at 3x baudrate ax0 0x0800 CHANGED BEFORE 0 dm System Control Reg ax0 no bmwait pmwait states SPORTI FI FO ax0 1 dm flag tx ready ax0 set the flags showing that UART is not busy dm flag ra ready ax0 dm flag rx stop yet ax0 dm flag rx no word ax0 dm flag rx off ax0 rx section off set flag out UART tx output is initialized to high ifc 0x003f clear all pending interrupts nop wait for ifc latency imask b 000001 enable TIMER interrupt handling ena timer start timer now rts Process_a_bit TIMER interrupt routine This routine is the heart of the UART It is called every timer interrupt i e 3x baudrate This routine will xmit one bit at a time by setting clearing the FLAG_OUT pin of the ADSP 2101 This routine will then test if the uart is already receiving If not it will test flagin rx for a start bit and place the uart in receive mode if true If already in receive mode it will shift in one bit at a time by reading the FLAG_IN pin Since the internal timer is running at 3x baudrate bits need only be transmitted received onc every 3 timer interrupts process_a_bit ena sec_reg Switch to the background dreg set ax0 dm flag_tx_ready if not in transmit go right to receive ar pass ax0 if ne jump receiver Transmitter Section ayO0 dm timer_tx_ctr test timer ctr to see if a bit ar ay0 1

Download Pdf Manuals

image

Related Search

Related Contents

Piano della sicurezza  Samsung NA-CY30 User Manual  Cisco Systems 880 Series Network Router User Manual  MÉCÉNAT - Forum National des Associations & Fondations  ESI WebEOC 7.0 User Manual  BRAVIA KDL55W905ABAEP  GE EWS2 Installation Guide  User Manual - Support Technique AURES    V. Caradec , L. Le Douarin – Les grands-parents, leurs petits  

Copyright © All rights reserved.
Failed to retrieve file