Getting started with Atmel SAM4S-EK2

LED 1

Let's begin with a small project that turns on a LED on the board.

  • To start a new project, click File > New > Project... or press Clrl + Shift + N.

  • Select GCC C ASF Board Project and name the project as ledtest.

  • In the Board Selection window, use Select By Board option and select SAM4S-EK2 and press OK.

In the right-hand side, you'll find the Solution Explorer window. Open the src folder, and double-click main.c. This is where we will be doing most of the programming.

In the Solution Explorer, open

src > boards > sam4s_ek2 > sam4s_ek2.h

This header file lists several definition related to the board operating frequency and board description. Lets try to find an LED pin in this header file.

  • Type LED in the search box.
  • We can see the pin definition for the blue and green LED.
  • Let's use the blue pin. Copy LED0_GPIO.

Let us now go to main.c file and try to find a gpio function that will turn the LED pin on and off.

  • By typing gpio, a number of suggestion pop-up. Select gpio_set_pin_low. This function takes a gpio pin as an argument. So paste LED0_GPIO as the argument.

      gpio_set_pin_low(LED0_GPIO);
    
  • Give an infinite loop such as

    while(true) {}
    

To compile and build the project, go to Build > Compile and Build > Build Solution. If there is no error, Build succeeded message will appear in your output windows. Output file will be created in your project folder as a binary package.

To flash the board

  • Connect the micro-usb cable from the board to pc.
  • To Erase old project, move your slide switch in the board to the left position and hold reset for a second and then move the switch to the right position and once again hold a reset button for a second.
  • Then open SAM-BA icon in the desktop and ensure that the board is correct. Click connect.
  • In the Flash tab, browse your binary file by clicking the button on the left of Send File.
  • Click Send File and then Execute.
  • Sometimes you will need to press the reset button on the board.

Now the blue led turn on.

Click here for project code

For more information about GPIO