Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Flashing an LED with AT91SAM7S256
PostPosted: Wed Sep 23, 2009 3:52 pm 
Offline

Joined: Tue Sep 15, 2009 4:24 pm
Posts: 2
After decades of using the PIC, I have taken the leap of faith to the ARM..

I am using the IAR toolchain and all I want to do is flash an LED. I have 'borrowed' the following code that compiles OK, but when I single step through it, once the registers have been set the PDSR does not change. Stupid question, but how can I tell if my port pin is toggling...

I am also having nightmares with the SAM-ICE JTAG, but I will put that in another post.

Please let me know where I am going wrong - thanks

Here is the code:

Code:

#include <AT91SAM7S256.h>

#define LED            (1<<0)   // PA0
#define INPUT_PIN      (1<<1)   // PA1
#define INT_PIN        (1<<2)   // PA2

static void initialize( void);
void delay_us( int time);
void delay_ms( int time);

int main(void)
{
  int delay = 100;
  volatile long input;
  initialize();

  volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;

  while(1)
  {
    input = pPIOA->PIO_PDSR;          //for debugging.  Watch input variable to check if inputs working.

    if(( pPIOA->PIO_PDSR & INPUT_PIN) == INPUT_PIN)
      delay = 1000;
    else
      delay = 100;

    pPIOA->PIO_CODR = LED;
    delay_ms(delay);
    pPIOA->PIO_SODR = LED;
    delay_ms(delay);
  }
}

static void initialize(void)
{
  //Turn on the peripheral clock.  Without this on, inputs do not actually register in the PDSR register
  volatile AT91PS_PMC   pPMC = AT91C_BASE_PMC;         // pointer to PMC data structure
  pPMC->PMC_PCER = (1<<AT91C_ID_PIOA);            // enable Timer0 peripheral clock

  volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
  pPIOA->PIO_PER = (LED | INPUT_PIN);         // Set PIO to control LED and button.
  // Initialize Input
  pPIOA->PIO_ODR = INPUT_PIN ;                // Disable outputs for INPUT pins. (not needed as all pins default input on reset)
  pPIOA->PIO_PPUER = INPUT_PIN;               //Pullup Enable (not needed as all pullups are enabled on reset)

  // Initialize Output
  pPIOA->PIO_OER = LED;                      // Enable output for LED.
  pPIOA->PIO_SODR = LED;                     // Turn LED off.
  pPIOA->PIO_PPUDR = LED;                    //Pullup disable
}

void delay_us(int delay)
{
  while(delay--)
  {
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
      __asm ("NOP");
  }
}

void delay_ms(int delay)
{
  char i;
  while(delay--)
  {
    for(i=0; i<4; i++)
    {
      delay_us(250);
    }
  }
}


Top
 Profile  
 
 Post subject: Re: Flashing an LED with AT91SAM7S256
PostPosted: Wed Sep 23, 2009 8:41 pm 
Offline

Joined: Thu Dec 02, 2004 2:28 pm
Posts: 454
hello,
i would recommend the following procedure:
1) take one of the examples included in ewarm
2) build the whole project
3) use the debugger for programming the flash or laod the code into ram and debug the code
4) try to understand what the exmaples does (reading the datasheet of the at91sam7s helps a lot too).
5) use the example as a framework and add your code
6) take a look into the other examples to understand how to use the different peripherals
7) take a look at the following link. you will find there of even more examples, all prepared for ewarm
http://www.atmel.com/dyn/products/tools ... ol_id=4343

hope this helps (also with your sam-ice problem)

regards
gerhard


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: