pi crtl de
Posts: 1
Joined: Thu Jan 30, 2014 8:26 pm
Location: Germany, Lower Saxony

GPIO Read with BASIC

Mon Feb 10, 2014 1:52 pm

Hello,
since a time I play around with the GPIO module for BBC BASIC at the pi. As I'am going to read some/all “input GPIO's“ same time, and store the result for later computing: What's the correct syntax? I have tried some of the ...exp32 calls, but get constant failure messages. Read single GPIO works fine. Thanks in advance!

User avatar
Burngate
Posts: 6560
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore

Re: GPIO Read with BASIC

Mon Feb 10, 2014 5:26 pm

Not sure what you mean by "...exp32 calls" - maybe because I'm 'doin' my own thing' rather than using other peoples' software!

However, I believe this should get you what you want, using a very short bit of assembler

Code: Select all

SYS "OS_Memory",13,&20200000,&100 TO ,,,IO_Base%

DIM code% 100
P%=code%
[OPT 2
    SWI "OS_EnterOS"
    LDR R0,[R0,#&34]
    SWI "OS_LeaveOS"
    MOV PC,R14
]

A%=IO_Base%
result%=USR(code%)
result% is all the first 32 GPIOs in order, in one 32-bit word.
Using AND and OR appropriately you should be able to dig out of it the GPIOs you want

Beware - I haven't actually used precisely this in anger, although it's the bare bones of what does work in the middle of what I've been writing
Last edited by Burngate on Mon Feb 17, 2014 10:29 am, edited 1 time in total.

fladda
Posts: 24
Joined: Fri Jan 04, 2013 1:46 pm

Re: GPIO Read with BASIC

Sun Feb 16, 2014 8:58 pm

I just copied this programme across to the ARMBE (!Edit) Basic Editor on the RC11 RPi. Seems to do something - well it prints a 32-bit number as expected. No I/O connected on my RPi so I've no easy way of knowing if the values are correct.

However, just for those not familiar with BBC Basic.

The line "A% = IO_Base" contains a 'typo', the '%' character is missing.

Should be "A% = IO_Base%",

The '%' character means that the variable 'IO_BASE' is used as a 32-bit integer variable.

Ralph

User avatar
Burngate
Posts: 6560
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore

Re: GPIO Read with BASIC

Mon Feb 17, 2014 10:30 am

fladda wrote:The line "A% = IO_Base" contains a 'typo', the '%' character is missing.
Should be "A% = IO_Base%",
The '%' character means that the variable 'IO_BASE' is used as a 32-bit integer variable.
:oops: Sorry! :oops:
I've put it in now

fladda
Posts: 24
Joined: Fri Jan 04, 2013 1:46 pm

Re: GPIO Read with BASIC

Tue Feb 18, 2014 2:09 pm

This small programme gives an excellent example of just how easily and quickly you can get down to almost 'bare metal' programming on the RPi, using RISC OS with its built-in BBC BASIC :-)

Ralph

Return to “RISCOS”