strebor27
Posts: 6
Joined: Sat Sep 28, 2013 4:43 pm

baking pi: external led

Sat Sep 28, 2013 5:07 pm

I have completed the baking pi tutorials and started on my own projects. At the moment I am just trying to switch a led on via GPIO PIN 24 (18).

this is very simple but I am obviously doing something wrong. is either my code or circuit incorrect? I first used the baking pi lesson 01 code and had my external led attached to pin 16. the pi's OK light came on but not my external led. I thought maybe 16 was not for external peripherals so I changed to pin 18.

.section .init
.globl _start
_start:

ldr r0,=0x20200000

mov r1,#1
lsl r1,#24
str r1,[r0,#4]

mov r1,#1
lsl r1,#18
str r1,[r0,#40]

loop$:
b loop$
Attachments
schematic.png
my circuit
schematic.png (2.48 KiB) Viewed 1712 times

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

Re: baking pi: external led

Sat Sep 28, 2013 5:54 pm

Which pin of P1 are you using?

GPIO 18 is connected to Pin 12 of P1.

strebor27
Posts: 6
Joined: Sat Sep 28, 2013 4:43 pm

Re: baking pi: external led

Sat Sep 28, 2013 7:18 pm

p1 header: 18

GPIO 24

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

Re: baking pi: external led

Sat Sep 28, 2013 8:29 pm

strebor27 wrote:p1 header: 18

GPIO 24
Ok, but your code is using GPIO 18. P1-12.

To use GPIO 24 it would have to be something like

Code: Select all

.section .init
.globl _start
_start:

ldr r0,=0x20200000

mov r1,#1
lsl r1,#12
str r1,[r0,#8]

mov r1,#1
lsl r1,#24
str r1,[r0,#40]

loop$:
b loop$
(caveat: I haven't tested this, but I believe it to be correct)

strebor27
Posts: 6
Joined: Sat Sep 28, 2013 4:43 pm

Re: baking pi: external led

Sat Sep 28, 2013 10:37 pm

ok thanks your right I was getting confused with the GPIO pins. I agree, your code looks right, I ran it but it still did not light the LED.

found this table, I understand that I have to turn the pin on at location 0x2020 0008 then clear the pin at 0x2020 0028 but what if I was to set pin 24 at address 0x2020 001c?
Attachments
GPIOregisters.jpg
GPIOregisters.jpg (63.45 KiB) Viewed 1642 times

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

Re: baking pi: external led

Sun Sep 29, 2013 11:50 am

Aha, yes.

The OK/ACT LED on GPIO 16 is connected between 3.3v and the GPIO, so it turns on when the GPIO is set to 0 (cleared), and off when the GPIO is set to 1 (set).

I assume your external LED is linked via a resistor between the GPIO pin and 0V. Therefore you will need to set the GPIO to 1 to make the LED turn on. [edit] I just re-checked your diagram, and this is correct.

So you are correct in saying that you need to write a 1 to bit 18 of 0x2020 001c. :-)

Just change the "str r1,[r0,#40]" to "str r1,[r0,#28]".

strebor27
Posts: 6
Joined: Sat Sep 28, 2013 4:43 pm

Re: baking pi: external led

Sun Sep 29, 2013 8:36 pm

yep thats it, got it working :D .

cheers for your help

Do you know how many amps is in the output of the gpio pins?. trying to figure out what type of transistor I will need to drive a small dc motor.

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

Re: baking pi: external led

Sun Sep 29, 2013 9:07 pm

I can't remember exactly, but the GPIO pins are only able to handle a few mA, maybe as much as 16mA but I would try to take as little current as possible from them. Somewhere like 2 mA should be enough to drive a mosfet transistor that will run a motor. Other people have driven motors from the GPIO pins, so a search should find some details of the circuits required.

strebor27
Posts: 6
Joined: Sat Sep 28, 2013 4:43 pm

Re: baking pi: external led

Thu Oct 03, 2013 10:58 pm

hey any idea how I would go about setting the pin drive strength. I read that the default is 8mA. each pin is 3 bits so instead of setting the pin to 001 would you change its strength with a different value like 011?

Return to “Bare metal, Assembly language”