I wanted a easy start in the development with the evalutationboard. So i started to turn leds on , toggle them ....
But i can't find a simple way to toggle a onboard LED with sw1 or sw2 of of the board.
I set the systemclock
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK ;
set the sw1 as gpio
PORTA_PCR19 |= (PORT_PCR_MUX(1));
and set the resistors
PORTA_PCR19 |= PORT_PCR_PE_MASK;
If i press the button nothing happens and the GPIO_PDIR_PDI (19) don't have a high state
tmp=(GPIOA_PDIR & GPIO_PDIR_PDI(1<<19));
Hi Philipp
I didn't see an "error" with the code but I think that you may need to add a delay between configuring the input and reading it. Don't forget that PTA19 (SW1) on the TWR board has no external pull-up resistor and the pin defaults to a XTAL output at reset. If you change its function and add a pull-up it may take a short amount of time before the input charges to '1'; if your code immediately reads the input it may always read '0', whether the button is pressed or not.
In case you want a simple start with your board see the link below since it gives you everything you may need (including industrial quality USB and Ethernet) and allows you to simulate the board in (approx.) real-time to avoid HW complications.
To do what you want in this case, the code would be (it handles all details that beginners may get wrong but gives most powerful learning and analysis capabilities at the same time)
#define SWITCH_SW1 PORTA_BIT19
_CONFIG_PORT_INPUT(A, (SWITCH_SW1), PORT_PS_UP_ENABLE); // configure the input (including clocking and characteristics)
if (_READ_PORT_MASK(A, SWITCH_SW1) == 0) { // read the state of the input
// SW1 pressed
}
else {
// SW1 not pressed
}
Note that there is one thing in your code that may have caused failure:
PORTA_PCR19 |= (PORT_PCR_MUX(1)); // risky but works for this pin
This works since the default peripheral function is ALT 0 (XTAL) but may fail if it weren't.
PORTA_PCR19 = (PORT_PCR_MUX(1)); // no risk
Regards
Mark
Kinetis for Professionals: http://www.utasker.com/kinetis.html
K60F120: http://www.utasker.com/kinetis/TWR-K60F120M.html