I2c Board

What have you built or do you want to design to go with your replica 1

I2c Board

Postby renejm » Mar Fri 09, 2012 1:43 am

I have been working on an I2c interface board for the Replica 1. From that you should be able to control almost anything. The addressing can be set to any unused location (I use 0xb000). I am using the Relica1 in a Computer Engineering class and having my students build an EEPROM and I2c board for it.

It would probably be easier to use the Arduino as it has the I2c stuff built in and coding the protocol in Assembly (BASIC is too slow) is tedious. I have included thre SLOW BASIC code. Have a version in Assembly and in FigFORTH, will not post that code here (as it is an assignment in my class) but if you want my assembly code or FORTH for a clock using the board, send me a message. Also I will send the gEDA schematic that I can not attach.

Jim

2012-03-08 - uploaded a new copy of the schematic, the gEDA schematic file, and an Integer BASIC program that bit bangs the device at 0xb00

REM V4_I2C.TXT
REM CONTROL I2C BOARD
REM J.M.RENEAU - YOU ARE FREE TO USE THIS CODE AS LONG AS YOU LEAVE MY NAME AND THE HISTORY IN IT
REM http://WWW.RENEJM.NET
REM
REM FOR VERSION 3 OF THE REPLICA-I2C BOARD
REM
REM SET D TO THE DEVICE NUMBER
REM A TO THE DEVICE ADDRESS
REM B CONTAINS THE DATA BYTE TO WRITE OR READ
REM B0 ARRAY OF BYTE DATA (UP TO 256)
REM N NUMBR OF BYTES TO READ OR WRITE WITH ARRAY OPERATION
REM K NACK BIT (1 IF FAIL, 0 IF OK)
REM D9 - DEBUG FLAG (SET TO 1 OR 0)
REM A9 - ADDRESS OF THE BOARD 0XB000
REM
REM DO NOT USE VARIABLES D0, D1, I0, I1, I2, I3, D9, B9, T9, T8
REM D0 - ^SCL OUT, D1 - ^SDA OUT,
REM I0 - ^SCL IN, I1 - ^SDA IN,
REM I2 - ^INT0 IN, I3 - ^INT1 IN,
REM
REM GOSUBS
REM 1000 - INITIALIZE I2C
REM 3000 - WRITE A REGISTER (NON ADDRESSED BYTE)
REM 3100 - WRITE AN ADDRESSED BYTE
REM 3200 - WRITE ARRAY (N BYTES)
REM 4000 - READ A REGISTER (NON ADDRESSED BYTE)
REM 4100 - READ A BYTE FROM AN ADDRESS
REM 4200 - READ ARRAY (N BYTES)
REM
REM E000R - START BASIC FROM WOZMON
REM E2B3R - WARM START AFTER RESET
REM
REM MODIFICATION HISTORY
REM DATE...... PROGRAMMER... DESCRIPTION
REM 2011-10-26 J.M.RENEAU WAS WORKING MOSTLY
REM 2011-11-11 J.M.RENEAU RESURRECTED V1 BOARD
REM 2011-11-12 J.M.RENEAU CLEANED UP V1 AS NEW V3
REM 2011-11-12 J.M.RENEAU AT END OF ALL SUBS MAKE SURE SCL
REM HIGN AND SDA HIGH AFTER READS (ACK)
REM 2011-11-29 J.M.RENEAU CHANGED FOR V4 BOARD (NON INVERTING)
REM 2011-11-30 J.M.RENEAU CHANGED ADDRESS FOR ADDRESSING AT ...000
REM 2011-12-06 J.M.RENEAU REMOVED CHANGE OF 2011-11-12 TO MAKE
REM LIKE KBS PROGRAM
REM 2011-12-11 J.M.RENEAU ADDED ARRAY OPERATIONS 3200 & 4200
REM FULLY WORKING WITH V4 BOARD
REM 2011-12-14 J.M.RENEAU FIXED CLOCK SETTING GOSUB 200
REM AND ADDED DIGITAL CLOCK AT 800


LOMEM=2048
HIMEM=16384
SCR

10 A9=-20480
20 D9=0
30 GOSUB 1000
98 GOSUB 200
99 GOTO 800

100 REM *** READ CLOCK ON 0XD0
105 D=13*16
140 A=0
150 GOSUB 4100
160 PRINT D;".";A;" > ";B/16;B MOD 16
165 REM D = 4*16
166 REM GOSUB 3000
170 GOTO 100
199 END

200 REM *** INITIALIZE CLOCK
210 PRINT "SET CLOCK (Y) ";
215 INPUT A$
220 IF A$ # "Y" THEN RETURN
230 PRINT "HOUR";
232 INPUT B
234 B = B/10 * 16 + B MOD 10
236 B0(3) = B
240 PRINT "MINUTE";
242 INPUT B
244 B = B/10 * 16 + B MOD 10
246 B0(2) = B
250 B0(1) = 0
260 D=13*16
270 A = 0
280 N = 3
290 GOSUB 3200
299 RETURN

300 REM *** TEST EPROM AT 0XA0
310 D=10*16
320 FOR A=0 TO 9
330 B= RND (256)
340 GOSUB 3100
350 PRINT B;" > ";D;".";A
360 NEXT A
370 FOR A=0 TO 9
380 GOSUB 4100
390 PRINT D;".";A;" = ";B
395 NEXT A
399 END

400 REM *** TEST RAM AT 0XA0 WITH ARRAY
401 FOR N=1 TO 8
402 B0(N)= RND (256)
403 PRINT N;" > ";B0(N)
404 NEXT N
410 D=10*16
411 A=0
412 N=8
413 GOSUB 3200
420 GOSUB 4200
431 FOR N=1 TO 8
432 PRINT N;" > ";B0(N)
433 NEXT N
499 END

500 REM *** READ CLOCK 0XD0 WITH ARRAY
510 D=13*16
511 A=0
512 N=8
520 GOSUB 4200
531 FOR N=8 TO 1 STEP -1
532 PRINT B0(N)/16;B0(N) MOD 16;" ";
533 NEXT N
540 PRINT
549 GOTO 500

700 REM *** READ 0X42 AND DISPLAY
710 D=4*16+2
720 GOSUB 4000
730 PRINT B
799 GOTO 700

800 REM ** CLOCKYWOCKY
805 D=13*16
810 A=0
815 N=3
820 GOSUB 4200
823 B = B0(1)
825 B0(9) = B MOD 16 + 48
830 B0(8) = B /16 + 48
835 B0(7) = 58
838 B = B0(2)
840 B0(6) = B MOD 16 + 48
845 B0(5) = B /16 + 48
850 B0(4) = 58
853 B = B0(3)
855 B0(3) = B MOD 16 + 48
860 B0(2) = B /16 + 48
865 B0(1) = 4*16+6
870 D = 5*16
875 A = 254
880 N = 9
885 GOSUB 3200
890 PRINT ".";
899 GOTO 800

900 REM ** WRITE OUT 0-255 TO 0X40
910 FOR T=0 TO 255
920 D=4*16
930 B=T
940 GOSUB 3000
980 NEXT T
990 END

1000 REM ** INITIALIZE
1001 IF D9 THEN PRINT "1000 INIT"
1010 DIM B0(256)
1020 REM SET D0 AND D1 EQUAL TO 2 (NOT 0 OR 1)
1030 D0=2
1040 D1=2
1050 GOSUB 1700
1060 GOSUB 1800
1099 RETURN

1100 REM ** WRITE BITS
1110 POKE A9,D0+(D1*2)
1198 IF D9 THEN PRINT ">C";(D0);" D";(D1)
1199 RETURN

1200 REM ** READ DATA BIT (RAISE AND LOWER SCL)
1210 GOSUB 1400
1220 GOSUB 1500
1230 GOSUB 1300
1240 I1= PEEK (A9)
1260 GOSUB 1400
1270 I0=I1 MOD 2
1280 I1=(I1/2) MOD 2
1298 IF D9 THEN PRINT "<-----C";(I0);" D";(I1)
1299 RETURN

1300 REM ** SCL HIGH
1310 IF D0=1 THEN RETURN
1320 D0=1
1330 GOSUB 1100
1399 RETURN

1400 REM ** SCL LOW
1410 IF D0=0 THEN RETURN
1420 D0=0
1430 GOSUB 1100
1499 RETURN

1500 REM ** SDA HIGH
1510 IF D1=1 THEN RETURN
1520 D1=1
1530 GOSUB 1100
1599 RETURN

1600 REM ** SDA LOW
1610 IF D1=0 THEN RETURN
1620 D1=0
1630 GOSUB 1100
1699 RETURN

1700 REM ** I2C START
1710 IF D9 THEN PRINT "1700 START"
1720 GOSUB 1400
1730 GOSUB 1500
1740 GOSUB 1300
1750 GOSUB 1600
1760 GOSUB 1400
1799 RETURN

1800 REM ** I2C STOP
1810 IF D9 THEN PRINT "1800 STOP"
1820 GOSUB 1400
1830 GOSUB 1600
1840 GOSUB 1300
1850 GOSUB 1500
1860 GOSUB 1400
1899 RETURN

1900 REM ** OUTPUT BYTE
1901 IF D9 THEN PRINT "1900 OUT ",B9
1902 K9=B9
1903 GOSUB 1400
1905 FOR T9=1 TO 8
1910 IF B9>=128 THEN GOSUB 1500
1920 IF B9<128 THEN GOSUB 1600
1925 B9=(B9*2) MOD 256
1930 GOSUB 1300
1935 GOSUB 1400
1940 NEXT T9
1950 REM # CLOCK IN THE ACK BIT
1960 GOSUB 1200
1970 K=I1
1980 IF NOT K THEN GOTO 1999
1990 PRINT "1900 OUT NACK",K9
1991 END
1999 RETURN

2000 REM ** FETCHES 8 BITS, MOST SIGN BIT FIRST
2001 IF D9 THEN PRINT "2000 IN"
2005 B9=0
2020 FOR T9=1 TO 8
2030 B9=B9*2
2035 GOSUB 1200
2040 B9=B9+I1
2050 NEXT T9
2060 IF K THEN GOSUB 1500
2070 IF NOT K THEN GOSUB 1600
2080 GOSUB 1300
2090 GOSUB 1400
2099 RETURN

3000 REM ** OUTPUT B AS D.REGISTER
3010 GOSUB 1700
3020 B9=D
3030 GOSUB 1900
3040 B9=B
3050 GOSUB 1900
3060 GOSUB 1800
3099 RETURN

3100 REM ** OUTPUT B TO D.A
3110 GOSUB 1700
3120 B9=D
3130 GOSUB 1900
3140 B9=A
3150 GOSUB 1900
3160 B9=B
3170 GOSUB 1900
3180 GOSUB 1800
3199 RETURN

3200 REM ** OUTPUT ARRAY B0 TO D.A TO D.A+N-1
3210 GOSUB 1700
3220 B9=D
3230 GOSUB 1900
3240 B9=A
3250 GOSUB 1900
3255 FOR T8=1 TO N
3260 B9=B0(T8)
3270 GOSUB 1900
3280 NEXT T8
3290 GOSUB 1800
3299 RETURN

4000 REM ** GET B FROM D.REGISTER
4010 GOSUB 1700
4020 B9=D+1
4030 GOSUB 1900
4040 K=0
4050 GOSUB 2000
4060 B=B9
4070 GOSUB 1800
4099 RETURN

4100 REM ** GET B FROM D.A
4110 GOSUB 1700
4120 B9=D
4125 GOSUB 1900
4130 B9=A
4135 GOSUB 1900
4145 GOSUB 1700: REM # REPEATED START
4150 B9=D+1
4155 GOSUB 1900
4160 K=1
4170 GOSUB 2000
4180 GOSUB 1800
4190 B=B9
4199 RETURN

4200 REM ** GET ARRAY B0 FROM D.A TO D.A+N-1
4210 GOSUB 1700
4220 B9=D
4225 GOSUB 1900
4230 B9=A
4235 GOSUB 1900
4245 GOSUB 1700: REM # REPEATED START
4250 B9=D+1
4255 GOSUB 1900
4257 FOR T8=1 TO N
4260 K=0
4265 IF T8=N THEN K=1
4270 GOSUB 2000
4280 B0(T8)=B9
4285 NEXT T8
4290 GOSUB 1800
4299 RETURN
Attachments
r1_io2i2c_v4.jpg
v4 of the board
r1_io2i2c_v4.jpg (75.18 KiB) Viewed 4472 times
r1_io2i2c_v5_sm.png
Schematic
r1_io2i2c_v5_sm.png (178.78 KiB) Viewed 4472 times
renejm
 
Posts: 4
Joined: Dec Mon 26, 2011 12:29 am

Return to Creation Room

Who is online

Users browsing this forum: No registered users and 4 guests

cron