[En-Nut-Discussion] Blinking LED on Ethernut 3
Marti Raudsepp
marti at voicecom.ee
Mon Jun 4 12:56:34 CEST 2007
Ste wrote:
> I would know which are the modifications to bring to the example "Blinking
> LED" available on the Ethernut web page in the section Nut/OS LED TUTORIAL
> (and here attached) so that runs also on Ethernut 3.
I don't know which pins or controllers the LEDs are attached to on the
Ethernet 3 board, but this is how I can blink LEDs on my AT91
development board.
I myself am using the header included with the AT91 development kit.
This defines a huge number of register addresses. You can get it from
http://www.keil.com/dd/docs/arm/atmel/sam7x/at91sam7x256.h
#include <at91sam7x256.h>
Alternatively you may use the definitions from <arch/arm/at91_pio.h> --
which have to be redefined to volatile pointers to actually use them in
C code:
#include <arch/arm/at91_pio.h>
typedef volatile unsigned int AT91_REG;
#define AT91C_PIOB_PER ((AT91_REG*)PIOB_PER)
#define AT91C_PIOB_OER ((AT91_REG*)PIOB_OER)
#define AT91C_PIOB_SODR ((AT91_REG*)PIOB_SODR)
#define AT91C_PIOB_CODR ((AT91_REG*)PIOB_CODR)
Four LEDs on my development board are bound to 19th...22nd pins of the
parallel I/O controller B; the pin bits are defined as follows:
#define LED1 (1<<19) // PB19
#define LED2 (1<<20) // PB20
#define LED3 (1<<21) // PB21
#define LED4 (1<<22) // PB22
#define LED_MASK (LED1|LED2|LED3|LED4)
The parallel controller (and most others) are operated through writing
respective bit masks to certain register addresses.
Initialization of LED pins:
// Enable specified pins on Parallel I/O controller B (PIOB)
// (PER = PIO Enable Register)
*AT91_PIOB_PER = LED_MASK;
// Enable output on specified pins (OER = Output Enable Register)
*AT91_PIOB_OER = LED_MASK;
// Set (turn off) all LEDs (SODR = Set Output Data Register)
*AT91_PIOB_SODR = LED_MASK;
Controlling the LEDs:
// Turn on LEDs 1 and 3 (CODR = Clear Output Data Register)
*AT91_PIOB_CODR = LED1|LED3;
// Turn off LEDs 1 and 2 (we've seen SODR before)
*AT91_PIOB_SODR = LED1|LED2;
This should be fairly straightforward to adapt to the blinking LED
example if you can figure out the PIO pins on your board.
Regards,
Marti Raudsepp
Voicecom OÜ
More information about the En-Nut-Discussion
mailing list