Teletext Experimenter’s Board – Tutorial 6 – RISC OS

I realised recently that RISC OS is unashamedly my “comfort” operating system. And I’m not ashamed to put “comfort” and “operating system” together in the same sentence, either! If my day-job is all about fighting with Windows and Linux, then RISC OS is like taking a day off, and sitting on the sofa in my wife’s fluffy slippers, eating biscuits and binging Better Off Ted.

All Acorn computers after the 8-bit era have included an I2C bus (it’s used for the internal clock and CMOS settings, for example) and when RISC OS was ported to the Raspberry-Pi, they hooked-up the operating-system calls for the I2C to the Pi’s bus, too. So the great news for us is that the code required to access I2C on RISC OS is exactly the same, whether you’re running the latest build on a Raspberry-Pi, or an elderly A3000 you rescued from a skip outside a primary school.

We’ll talk about the hardware first, before moving on to software experiments.

Hardware Wiring

If you’re running RISC OS on a Pi, then the wiring is identical to how I described it in the previous tutorial (using Raspbian). So that just leaves me to talk about “legacy” Acorn hardware.

For RISC OS machines made by Acorn (and the Iyonix made by Castle) the I2C bus is made available on the expansion-card connector (Acorn called their expansion cards “Podules”).

This connector is a DIN41612C, and is still readily available (I seem to have a big box of them from when I was considering using them for my DIY-6502 project some years ago).

People who want to make a “proper” job of connecting their Acorn computer to their Experimenter’s Board might want to design and order a proper PCB to mount the connector on, and make the four pins required a bit more accessible. I leave that as an exercise for the reader … but let me know if that’d be useful to you, because I can probably quickly design one and get some PCBs ordered if there’s sufficient interest.

However … I just wanted to get something working quickly for the purposes of this tutorial, so I straightened-out the pins I needed, soldered some DuPont wires to them, and then clipped-off all the other pins. Like this:

Then connecting the Experimenter’s Board to my A3000 (the expansion connector is on the back) looks like this:

Controlling I2C in RISC OS

Access to the I2C bus is handled by the operating system, and can be accessed by the “IIC_Control” SWI. This is great, because it means we can do it in BASIC.

Usage in BASIC is something like this:

SYS "IIC_Control",<id>,<address of buffer>,<number of bytes in buffer>

It’s important to note that <id> uses the LOWEST bit to signify read or right (it should be set for reading, clear for writing) so the 7-bit ID of the device needs multiplying by two. So in my examples, I do this:

device%=&11
dev_write%=device%<<1
dev_read%=(device%<<1)+1

Then use dev_write% or dev_read%, depending on whether you are writing-to or reading from the device. It just makes the code a bit easier to read.

<address of buffer> and <number of bytes in buffer> are … well, exactly what you’d expect. The usual method is to pre-allocate a block of RAM as a general-purpose buffer (use DIM). Poke the data into it that you want to send, then pass the address to the SYS command along with the number of bytes you want to send. Like this:

DIM buffer% 2048:REM Allocates a 2K buffer
buffer%?0=9
buffer%?1=0
buffer%?2=0
SYS "IIC_Control",dev_write%,buffer%,3:REM sends three bytes

I’ve written two example BASIC programs to demonstrate, which do largely the same thing as my previous tutorials.

The first program (click here to download, 3KB) blanks the screen and runs a loop displaying the current time on the top line … then it reads the line back again, and prints it on screen. So this demonstrates writing-to and reading-from the Teletext Experimenter’s Board. It has far too many comments in – I hope you find them helpful!

The second program (click here to download, 4KB) is a primitive BASIC equivalent of the “Decoding” tutorial I previously wrote for the Arduino. Using it you can select a three-digit page, hold it, toggle the zoom modes, or download the page and print the data on-screen.

Click here to visit the Teletext Experimenter’s Board main project page.