muharis93
Posts: 3
Joined: Fri Jun 19, 2015 11:41 pm

I cannot understand Pi programming.

Sat Jun 20, 2015 12:05 am

First of all I am new in this field basically I am an electronic engineer and have some experience in MCU programming like PIC , AVR etc. In these device registers play a key role in getting a job done and there is on OS. This whole Linux thing is confusing me.

I want to know is there a way for directly accessing raspberry pi registers in C?link defining a direction of GPIO using data direction register or initializing URAT form URAT control register?

Is there any datasheet for PI like the ones that come with MCU?

How would you people recommend me to start with Pi keeping in mind my background?

Thankx

User avatar
Paeryn
Posts: 3074
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 1:59 am

The datasheet and various other information on the RPi can be found in this thread http://www.raspberrypi.org/forums/viewt ... 72&t=72260. It's more bare metal than linux but there is information on the hardware registers and how to use them.

Accessing the registers directly from linux is just a case of using mmap() to map the register space into your process. Although be careful as linux itself and/or other processes may already be using them. Usually there will be device drivers which you use to request access to different resources so that linux can either share them with you if it can (through an API rather than direct register manipulation), or make sure that only one process has access until it is finished with it (again this access could be via an API which does the register manipulations for you, or it might be just a locking mechanism to prevent anyone else directly altering the registers whilst you are) .
Last edited by Paeryn on Sat Jun 20, 2015 2:33 pm, edited 1 time in total.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

User avatar
mntmst
Posts: 57
Joined: Thu Sep 27, 2012 11:26 pm
Location: Fairview, Oregon

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 4:06 am

If you want to program low-level in a fashion similar to your typical uC in Linux you have to understand device drivers and there's no easy way to do it because you need a lot of information at first.

I would start here: http://lwn.net/Kernel/LDD3/

User avatar
joan
Posts: 15084
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 7:42 am

What are you trying to do? You don't need to involve yourself with the low-level details of registers.

muharis93
Posts: 3
Joined: Fri Jun 19, 2015 11:41 pm

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 12:14 pm

Thanks for your replies.

Currently I am just learning Pi. I want to use GPIO, PWM, SPI, URAT, and ADC for interfacing of different sensors or stuff.
Now a lot of help is available online on these topics but I don't understand as I am more used to play with register with out any OS.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 12:23 pm

The Pi has to run an OS, if you want something like that you probably want an Arduino.

I don't know what to tell you. Try to learn a high level language that will be really useful on the Pi.
There are 10 types of people: those who understand binary and those who don't.

muharis93
Posts: 3
Joined: Fri Jun 19, 2015 11:41 pm

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 12:33 pm

Is there any resource available online that explains the steps involved (not just give away the code) in using GPIO and other peripheral.

Thanks :roll: .

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 12:42 pm

muharis93 wrote:Is there any resource available online that explains the steps involved (not just give away the code) in using GPIO and other peripheral.

Thanks :roll: .
The easiest way to access GPIO is through libraries, namely RPi.GPIO for Python, pigpio for C and others. The full list is availible here:
http://elinux.org/RPi_Low-level_periphe ... e_examples
There are 10 types of people: those who understand binary and those who don't.

ghans
Posts: 7883
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: I cannot understand Pi programming.

Sat Jun 20, 2015 2:08 pm

You can "program" the Pi like an MCU if you really wish , but you will get horrible USB support and also reduced Internet performance or no connectivity at all.
Check the bare-metal subforum for assembler tips and tricks.

Of course , learning to use Linux and some high-level language is worthwhile and would give you access to lots of readily available
libraries , tools and drivers (!!). It is the way i definitely recommend unless you are highly allergic to such kinds of abstractions ;)

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

colinh
Posts: 95
Joined: Tue Dec 03, 2013 11:59 pm
Location: Munich

Re: I cannot understand Pi programming.

Sat Aug 08, 2015 1:15 am

kusti8 wrote:The Pi has to run an OS, if you want something like that you probably want an Arduino.
Err, of course the Pi doesn't need an OS! As ghans mentioned, there's an entire Bare Metal (meaning no OS) forum dedicated to it.

Indeed, I would say that if you're coming from microcontrolers, and want to fiddle with the hardware, not only is bare metal easier than trying to battle against the OS, but assembly code makes things even clearer than using C.

There are plenty of examples / tutorials about how to get started with bare metal / assembly code.

If you can't find them try googling the last line, after replacing "There are plenty of" with "Raspberry Pi / ARM" :)

User avatar
rpdom
Posts: 17703
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I cannot understand Pi programming.

Sat Aug 08, 2015 5:47 am

Bare metal in Assembler on the Pi is fun :-)

There's a load of details on the registers that control the GPIOs and other peripherals in the Peripheral Specification document and the other documentation here https://www.raspberrypi.org/documentati ... /README.md

Return to “Teaching and learning resources”