REM >Example1 REM REM An example of using the Teletext Experimenter's Board on RISC OS, in BASIC. REM REM http://danceswithferrets.org/geekblog/?p=1250 REM REM Tested on a Raspberry-Pi running RISC OS 5.23. ON ERROR REPORT:PRINT " at line ";ERL:END REM SYS "OS_ReadSysInfo",14 TO numIICs% REM PRINT "There are ";numIICs%;" IIC Buses on this device." REM IF numIICs%<1 THEN REM PRINT "Couldn't find any I2C busses? What?" REM END REM ENDIF device%=&11 dev_write%=device%<<1 dev_read%=(device%<<1)+1 REM The IIC_Control commands like to be passed an address of a block of memory we can use REM for reading or writing the device. So we allocate a block of RAM (2K is plenty) and REM make it our "general I/O area" for the device DIM buff% 2048 REM We send data down the IIC channel by writing the bytes we want to send into the buffer first, REM then pass the IIC_Control command the address of the buffer, and the number of bytes we want to send. REM The bytes themselves ... correspond with how we did initialisation in the Arduino example. buff%?0=4:REM We want to write from register 4 buff%?1=7:REM Will put a 7 in register 4. buff%?2=&CC:REM Register 5 buff%?3=0:REM Register 6 buff%?4=0:REM Register 7 SYS "IIC_Control",dev_write%,buff%,5:REM Send the first five bytes of the buffer to our device. buff%?0=0:REM start at register 0 buff%?1=16:REM Register 0 buff%?2=&54:REM Register 1 SYS "IIC_Control",dev_write%,buff%,3 buff%?0=8 : REM Start at register 8 buff%?1=15 SYS "IIC_Control",dev_write%,buff%,2 REPEAT starttime%=0 SYS "OS_ReadMonotonicTime" TO starttime% buff%?0=9 : REM Start at register 9 (cursor position) buff%?1=0 buff%?2=0 REM Now we're on register 11. We just write bytes to go on screen. x%=3 text$=TIME$ FOR z%=1 TO LEN(text$) buff%?x%=ASC(MID$(text$,z%,1)) x%+=1 NEXT SYS "IIC_Control",dev_write%,buff%,x% REM Now lets try reading the first line of screen memory back again buff%?0=9 buff%?1=0 buff%?2=0 SYS "IIC_Control",dev_write%,buff%,3 REM Can I read data back again? SYS "IIC_Control",dev_read%,buff%,40 FOR z%=0 TO 39 c%=buff%?z% IF c%>31 AND c%<127 THEN PRINT CHR$(c%); ELSE PRINT "[";~c%;"]"; NEXT PRINT timenow%=starttime% REPEAT SYS "OS_ReadMonotonicTime" TO timenow% UNTIL (timenow%-starttime%)>=100 UNTIL 0