Hello I'm using the Kinetis KL43Z MCU and have 2 question
1. How do I setup a GPIO input and out put function (could you please provide a sample along with explanation)
2. Can you please give me a list of the GPIO names used on this MCU
Any help is greatly appreciated
Kind regards Jack Monaghan
Hi Jack Monaghan,
Answer your 2 questions:
1.How do I setup a GPIO input and out put function
If you want to control GPIO, you should use these register: SIM_SCGC5, PORTx_PCRn, GPIO register.
SIM_SCGC5 is used to open port clock.
PORTx_PCRn is used to configure the pin as GPIO function, and whether have interrupt , pullup or pulldown,ect.
GPIO, is used to control the pin as output or input, and get the pin input data or set the port output data.
An example to set PTA5 as output high
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // enable pta port clock
PORTA_PCR5 = PORT_PCR_MUX(01); //pta5 as gapio
GPIOA_PDDR = 1<<5;// pta5 output
GPIOA_PDOR= 1<<5;// pta5 output higg
Input is the same, just congfigure PORTA_PCR5 use interrupt or not, pullup,etc. then clear GPIOA_PDOR bit5 to set pta5 as input.
If you want to use the interrupt, you should enable the global interrupt and the PORTA interrupt.
Actually, we have the sample code for the KL43, please download the code from this link:
http://cache.freescale.com/files/32bit/software/FRDM-KL43Z-SC-BAREMETAL.exe
2:Can you please give me a list of the GPIO names used on this MCU
You can find the pin name from the reference manual, chapter 10.1 KL43 Signal Multiplexing and Pin Assignments
Wish it helps you!
If you still have question, please contact me!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Ok so I've made a diagram of how the program/(part of the circuit) will be set out so you can get a much clearer picture on what i need to do sorry for the confusion with the "2 buttons" before.
so if you press the button but haven't pulled out the pull out it will play a noise on loop and when you press it
again it will turn off. But if you have taken the pullout out it puts it into an "ACTIVE" mode so as soon as you press
the button it will start playing and won't stop until the batteries die no matter how many times you try to turn it off.
define: GPIO, noise function, speaker function,
1. A low speed voltage is put through both the GPIO outputs.
2. Both the GPIO inputs keep sampling for any input.
3.Outcomes
A. The "contact" gets an input and the button does as well it will jump to the part of the code where it will just play the noise on loop
until the batteries die.
B, Their is an input in the button function but not the "contact" functions it will start playing the code that just plays the noise on loop until the button is pressed again to turn it off
Hi
I don't see the advantage of connecting one pole of the button/contact to a GPIO output - they can probably be connected to 0V and the inputs can connect an internal pull-up and monitor for a '0' to detect when the button is pressed or the contact is closed.
In your case you just need to configure these two pins as outputs driving 0V (or '1' and invert the input detection).
The rest of the logic (and what happens when the inputs are detected) is general software and so has nothing to do with the Kinetis GPIOs themselves.
Regards
Mark
Kinetis: µTasker Kinetis support
KL43: µTasker FRDM-KL43Z support / µTasker TWR-KL43Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
Hi Jack
1. See the following for macros to configure and control GPIOs in the uTasker project - the macro source code shows the actual control that they do.
2. Below is a screen shot of the uTasker simulator running the FRDM-KL43Z board. Attached is the simulation (simply unzip and execute uTaskerFRDM-KL43Z - no installation necessary) - if you hover the mouse over each port you can see its pin number, its GPIO and peripheral functions as well as the present function that it has (whether input or output and logical state) - if an interrupt is configured on a port changing its input state by clicking with the mouse will also cause interrupt to be generated.
Otherwise you can find a complete list of pins in the KL43 user manual in the section about pin multiplexing.
If you would like to accelerate your learing and have much more fun in the process simply use the uTasker project and the KL43 simulator and you can step through the code that controls such things and test you own code - and see the results in the simuator without needing to use a debuger or guess what is happening in the chip.
All tools and code are free for non-commerical work.
Regards
Mark
Kinetis: µTasker Kinetis support
KL43: µTasker FRDM-KL43Z support / µTasker TWR-KL43Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
Could you please help me make 2 functions for 2 buttons?
Jack
You will need to better specifiy what you require but the following shows how I would configure two inputs to monitor two buttons. One is moitored by polling and one is configured to generate an interrupt when pressed (assuming they are '0' when pressed).
#define BUTTON1 PORTB_BIT0 // button inputs to use #define BUTTON2 PORTC_BIT3 void fnConfigureButtons(void) { INTERRUPT_SETUP interrupt_setup; // interrupt configuration parameters interrupt_setup.int_handler = fnButton1_pressed; // handling function interrupt_setup.int_priority = 3; // port interrupt priority interrupt_setup.int_port = PORTB; // the port used interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON); // interrupt on rising edges interrupt_setup.int_port_bits = (BUTTON1); // the inputs connected fnConfigureInterrupt((void *)&interrupt_setup); // configure interrupt on button 1 _CONFIG_PORT_INPUT(C, (BUTTON2), PORT_PS_UP_ENABLE); // configure button 2 input } void fnPollButton2(void) { if (_READ_PORT_MASK(C, BUTTON2) == 0) { fnDebugMsg("Button 2 is pressed\r\n"); } else { fnDebugMsg("Button 2 is NOT pressed\r\n"); } } // Interrupt handler when button 1 pressed // static void fnButton1_pressed(void) { fnInterruptMessage(OWN_TASK, BUTTON_EVENT); // example of generating an event }
Regards
Mark
Kinetis: µTasker Kinetis support
KL43: µTasker FRDM-KL43Z support / µTasker TWR-KL43Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market