1

I'm using an AT91SAM7 chip on the MakingThings board for some custom work. To better understand the peripheral driver, I'm trying to directly call/control an output pin (PA12) to turn on the status LED.

main()
{
    AT91C_BASE_PIOA->PIO_PER = AT91C_PIO_PA12; //Enable Pin PA12
    AT91C_BASE_PIOA->PIO_OER = AT91C_PIO_PA12; // Enable Pin PA12 as 'peripheral manager' controlled pin 
    AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA12; //Disable Pull Up resistors
    AT91C_BASE_PIOA->PIO_SODR =  AT91C_PIO_PA12; // Set pin state to 'high'
}

That code builds fine. When I burn the firmware and test it, that does not turn on the LED on pin A 12. The peripheral controller is a bit complex, so I'm concerned I'm doing something in a wrong order, or that I am missing some other register that must be set. Does anyone have feedback or info on why that might be wrong?

(I can run other code, do other examples, run USB data, etc. It's just the simple flicking on an LED that is weird).

Kevin Vermeer
  • 20,067
  • 8
  • 57
  • 102
Far McKon
  • 151
  • 1
  • 2
  • 3

2 Answers2

1

Have a look at this blinking LED sample code.

http://www.olimex.com/dev/soft/arm/SAM7/Blinking_LED.zip

How do you have the LED wired up?

Toby Jaffey
  • 28,836
  • 19
  • 98
  • 150
0

If its a hardware thing, there are a couple of different ways to make an LED light using a PIO pin..

If you happen to have the LED wired anode to +V, cathode toward the PIO pin (w/a suitable limiting resistor of course), it will be a LOW pin state that would light the LED.

If you have the anode of the LED toward the PIO pin, and the cathode toward ground, then a HIGH should light the LED, as you've coded.

A quick googling for ARM91SAM7 turned up an Atmel datasheet for the whole series, Atmel document is filenamed doc6175.pdf .

A rule of thumb for choosing the limiting resistor is to pick a value that will give anywhere from 5 to 20mA, when dropping a voltage about 1.25V less that your supply rail. However, looking at the datasheet, the spec says this chip can 'draw' only 8mA (section 6.6), which is just about enough to get light out of an LED, so choose your resistor accordingly, or use a buffering device if you need more LED current.

Figure 27-3 in that pdf shows all the PIO control register settings that set up the pin. Having spent about 15 minutes looking at that and your code, it looks like you've covered the necessaries. The only register you didn't alter was PIO_MDSR, but if I read the diagram right, that comes out of reset in a state compatible with what you are trying to do.

JustJeff
  • 19,233
  • 3
  • 51
  • 77