SAM4SD32C GPIO Register

Discussion in 'Embedded Systems and Microcontrollers' started by embedded_, Aug 31, 2015.

  1. embedded_

    Thread Starter New Member

    Aug 31, 2015
    1
    0
    Hi,

    I'm new to the atmel ARM series MCU's and I am trying to create a simple program so that when I press the user button,
    the led on de board lights up.
    (I am using the SAM4s Xplained pro development board)

    I want to do this without the ASF functions, but with the GPIO registers like
    PIO_OSR, PIO_ODSR, PIO_PDSR etc.

    I'm having trouble reading the button.
    (so the condition inside the if statement is not correct) --> if((PIO_PDSR_P24) == 1){}
    Anyone knows how this statement should be formulated to read out the button via the PDSR register?

    Code (Text):
    1. /*
    2. * SAM4S_Xplained_Pro_firstProject.c
    3. *
    4. * Created: 30-8-2015 20:37:29
    5. *  Author: embedded_
    6. */
    7.  
    8. /*
    9.     User switch = PC24
    10.     User led = PC23
    11. */
    12.  
    13. #include "sam.h"
    14.  
    15. /**
    16. * \brief Application entry point.
    17. *
    18. * \return Unused (ANSI-C compatibility).
    19. */
    20. int main(void)
    21. {
    22.     /* Initialize the SAM system */
    23.     SystemInit();
    24.    
    25.     PIOC->PIO_PER = (PIO_PER_P24 | PIO_PER_P23); //PIO enable
    26.     PIOC->PIO_ODR = PIO_ODR_P24; //Input
    27.     PIOC->PIO_PUER = PIO_PUER_P24; //pull-up resistor button
    28.     PIOC->PIO_OER = PIO_OER_P23; //Output
    29.    
    30.     while (1)
    31.     {
    32.         if((PIO_PDSR_P24) == 1)
    33.         {
    34.             PIOC->PIO_SODR = PIO_SODR_P23;
    35.         }
    36.         else
    37.         {
    38.             PIOC->PIO_CODR = PIO_CODR_P23;
    39.         }
    40.     }
    41. }
     
Loading...