Basics in Basic
In this chapter we can see how to configure SIF in Basic to get connection. You can also see some easy terminal program to send characters over serial line and receive this.
In this example we will use SIF with Base address at 131 and all IO ports will be related to this address.
This will be basic setting for 115200 bauds, 8 bits, 1 stop bit, no parity and HW handstake
1. First of all we have to choose UART by CONFIG register. This setting will select UART1, disable INT and delete all flag registers
OUT Base+28, 0
2. Now we can start with setting of UART, this will enable int flag from UART to SIF CPLD
OUT Base+4, 1
3. Next setting is eable FIFO registers, delete old content and set levels
OUT Base+8, 71
4. After FIFO we will data bits, parity, stop bits and also by bit 7 we enable baud rate generator registers
OUT Base+12, 131
5. In this step we adjust baud rate generator by this formula:
divisor = 460800 / bauds
4 = 460800 / 115200
than
OUT Base, 4 LSB
OUT Base+4,0 MSB
6. By enter 191 to Line control register we will have access to EFR
OUT Base+12, 191
7. In EFR register we will enable HW flow control mode
OUT Base+8, 192
8. By writing right values to LCR we finished configuration
OUT Base+12, 3
After this setting your SIF is configured for comunication and all data sent to Base IO port will be transmited to
RS232. Received data will be read by reading Base IO port.
Follow is example of some easy terminal with configuration
10 LET b$="": LET base=131 20 PRINT "SIF Configuration" 30 PRINT "UARTx "; 40 INPUT uart 50 PRINT uart 60 PRINT "Speed: "; 70 INPUT baud 80 PRINT baud 90 PRINT "Data bits: "; 100 INPUT bits 110 PRINT bits 120 PRINT "Stop bits: "; 130 INPUT stopb 140 PRINT stopb 150 PRINT "parity(0-N, 1-O, 2-E)"; 160 INPUT parita 170 PRINT parita 180 PRINT "irda (1/0) "; 185 IF uart=1 THEN LET ir=0: GO TO 195 190 INPUT ir 195 PRINT ir 200 PRINT "HW flow cont.(1/0)"; 210 IF ir=1 THEN LET tk=0: GO TO 230 220 INPUT tk 230 PRINT tk 240 PRINT "Echo (2/1/0) "; 245 PRINT "0 - None, 1 - only ZX, 2 - Both "; 250 INPUT echo 260 PRINT echo 270 GO SUB 660 290 CLS 300 PRINT "SIF test program" 310 PRINT "1. Terminal" 320 PRINT "8. Read SIF ports" 340 PRINT "9. Port setting" 350 PRINT "0. Exit" 360 PRINT AT 13,0;"Actual setings:" 370 PRINT "UART: ";uart 380 PRINT "Speed: ";baud 390 PRINT "Bits: ";bits 400 PRINT "Stop bits: ";stopb 410 PRINT "Parity:1=O,2=E: ";parita 420 PRINT "Flow Cont.(1/0) ";tk 430 PRINT "Echo (2/1/0) ";echo 440 INPUT v 460 IF v=1 THEN CLS : GO TO 510 470 IF v=9 THEN CLS : GO TO 20 480 IF v=0 THEN STOP 490 IF v=8 THEN CLS : GO TO 960 500 GO TO 290 510 CLS : PRINT AT 20,0;"End SS+X": PRINT AT 0,0; 520 LET a$=INKEY$ 530 IF a$="" THEN GO TO 600 540 IF b$=a$ THEN LET b$="": GO TO 520 550 IF a$ ="£" THEN GO TO 290 560 IF echo<>0 THEN PRINT INVERSE 1;a$; 570 OUT base,CODE a$ 580 LET b$ = a$ 590 PAUSE 30 600 LET stav =IN(base+20) 605 if (stav/2<>INT (stav/2)) THEN GO TO 620 610 GO TO 520 620 LET a=IN base 622 IF a=16 THEN PRINT: GO TO 520 624 IF a=10 THEN PRINT " ": GO TO 520 626 IF a<32 THEN GO TO 520 630 IF echo=2 THEN OUT base,a 640 PRINT INVERSE 0;CHR$ (a); 650 GO TO 520 660 LET lcr= 0 670 IF uart=1 THEN OUT base+28,0 680 IF uart=2 THEN OUT base+28,2 690 IF parita=1 THEN LET lcr=lcr+8 700 IF parita=2 THEN LET lcr=lcr+12 710 IF bits=6 THEN LET lcr=lcr+1 720 IF bits=7 THEN LET lcr=lcr+2 730 IF bits=8 THEN LET lcr=lcr+3 740 OUT base+12,lcr 750 LET fcr =BIN 00011111 760 OUT base+8,fcr 770 LET mcr =BIN 00000000 780 IF ir=1 THEN LET mcr=BIN 01001000 790 OUT base+16,mcr 800 LET lcr=lcr+128 810 OUT base+12,lcr 820 LET div=460800/baud 830 LET bmsb=INT (div/256) 840 LET blsb = div-(bmsb*256) 850 OUT base,blsb 860 OUT base+4,bmsb 870 LET lcr=lcr-128 880 OUT base+12,191 890 IF tk=0 THEN LET efr= 0 900 IF tk=1 THEN LET efr=BIN 11000000 910 OUT base+8,efr 920 OUT base+12,lcr 930 LET ier =BIN 00000001 940 OUT base+4,ier 950 RETURN
Followed program after run ask for setting and set you UART.
After this you can from menu select Terminal, connect PC with SIF by Cross cable.
On PC you can run some Hyperterminal or similar software with setting of corresponding speed, data bits, handstake a nd what you write to your Spectrum should appear on PC hyperterminal.
With this easy terminal you can also make connection to Embeded ConnectOne module! But this will be in some next part.