Interrupt with external switch

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Interrupt with external switch

1,290 Views
javierhernande1
Contributor IV

Target: FRDM-K64F 

Firmware DAPLink rev0244

MCUXpresso IDE v10.1.1 [Build 606] [2018-01-02]

KSDK 2.3.0

Hello,

I'm trying to controlled a 7 Segment Led Display with a external switch (not on board switch) but this code not works. 

Please, What is the correct way to create the interrupt for PTC11?

Best regards

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_debug_console.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
#include "fsl_common.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/
//FRDM-K64F pintout-> https://os.mbed.com/platforms/FRDM-K64F/#board-pinout
#define SW_FQ_GPIO GPIOC /* Frequency switch :: PTC11 */
#define SW_FQ_GPIO_PORT PTC
#define SW_FQ_GPIO_PIN 11U
#define SW_FQ_IRQ 61U
#define SW_FQ_IRQ_HANDLER PORTC_IRQHandler
#define SW_PWR_GPIO_PORT PTC /* Power button :: PTC3 */ /*TO-DO*/
#define SW_PWR_GPIO_PIN 3U
/**
 * E10561-J
 * Common Anode 3,8
 *
 * A B C D E F G DP
 * 7 6 4 2 1 9 10 5
 *
 * A -- PTC7
 * B -- PTC0
 * C -- PTC4
 * D -- PTC2
 * E -- PTC1
 * F -- PTC9
 * G -- PTC10
 * DP - PTC5
 **/
#define LED_GPIO GPIOC
#define LED_A_GPIO_PORT PTC
#define LED_A_GPIO_PIN 7U
#define LED_A_GPIO_NAME "A"
#define LED_B_GPIO_PORT PTC
#define LED_B_GPIO_PIN 0U
#define LED_B_GPIO_NAME "B"
#define LED_C_GPIO_PORT PTC
#define LED_C_GPIO_PIN 4U
#define LED_C_GPIO_NAME "C"
#define LED_D_GPIO_PORT PTC
#define LED_D_GPIO_PIN 2U
#define LED_D_GPIO_NAME "D"
#define LED_E_GPIO_PORT PTC
#define LED_E_GPIO_PIN 1U
#define LED_E_GPIO_NAME "E"
#define LED_F_GPIO_PORT PTC
#define LED_F_GPIO_PIN 9U
#define LED_F_GPIO_NAME "F"
#define LED_G_GPIO_PORT PTC
#define LED_G_GPIO_PIN 10U
#define LED_G_GPIO_NAME "G"
#define LED_DP_GPIO_PORT PTC
#define LED_DP_GPIO_PIN 5U
#define LED_DP_GPIO_NAME "DP"
/*******************************************************************************
 * Prototypes
 ******************************************************************************/
/*******************************************************************************
 * Variables
 ******************************************************************************/
/* Whether the SW button is pressed */
volatile bool g_ButtonPress = false;
/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Interrupt service fuction of switch.
 *
 * This function toggles the LED
 */
void SW_FQ_IRQ_HANDLER(void)
{
 /* Clear external interrupt flag. */
 GPIO_PortClearInterruptFlags(SW_FQ_GPIO, 1U << SW_FQ_GPIO_PIN);
 /* Change state of button. */
 g_ButtonPress = true;
 /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
 exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
 __DSB();
#endif
}
/*
 * @brief Application entry point.
 */
int main(void) {
/* Define the init structure for the input frequency switch pin */
 gpio_pin_config_t sw_fq_config = {
 kGPIO_DigitalInput, 0,
 };
/* Define the init structure for the input power switch pin */
 gpio_pin_config_t sw_pwr_config = {
 kGPIO_DigitalInput, 0,
 };
/* Define the init structure for the output 7Segment Led Display pin */
 gpio_pin_config_t led_config = {
 kGPIO_DigitalOutput, 0,
 };
/* Init board hardware. */
 BOARD_InitBootPins();
 BOARD_InitBootClocks();
 BOARD_InitBootPeripherals();
 /* Init FSL debug console. */
 BOARD_InitDebugConsole();
/* Print a note to terminal. */
 PRINTF("\r\n OpenVTX Firmware\r\n");
 PRINTF("\r\n Press the Frequency switch to change the channel \r\n");
/* Init Frequency input switch GPIO */
 PORT_SetPinInterruptConfig(SW_FQ_GPIO_PORT, SW_FQ_GPIO_PIN, kPORT_InterruptFallingEdge);
 EnableIRQ(SW_FQ_IRQ);
 GPIO_PinInit(SW_FQ_GPIO, SW_FQ_GPIO_PIN, &sw_fq_config);
/* Init output 7 Segment Led Display */
 GPIO_PinInit(LED_GPIO, LED_A_GPIO_PIN, &led_config);
while(1)
 {
 if(g_ButtonPress)
 {
 /* Toggle A LED */
 GPIO_PortToggle(LED_GPIO, 1U << LED_A_GPIO_PIN);
 /* Reset state of button */
 g_ButtonPress = false;
 }
 }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

7 Segment Display datasheet

3 Replies

703 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Have you try to select PTC11 as GPIO function?

Please refer the image shown below:

PTC11 alt1.PNG

PTC11.PNG

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

703 Views
javierhernande1
Contributor IV

Sorry, I am a mess with C.

Now works. Thank you.

Best regards

Captura de pantalla de 2018-03-23 14-47-01.png

Captura de pantalla de 2018-03-23 14-43-04.png

0 Kudos

703 Views
mjbcswitzerland
Specialist V

Hi

See the following for details about port interrupt operation:
- Port interrupt: https://youtu.be/CubinvMuTwU
- Keypad and LCD: https://youtu.be/vGk-b40EgL0
- LCD: https://youtu.be/YJEzxSqVtss


Regards

Mark




Kinetis: http://www.utasker.com/kinetis.html
Kinetis K64:
- http://www.utasker.com/kinetis/FRDM-K64F.html
- http://www.utasker.com/kinetis/TWR-K64F120M.html
- http://www.utasker.com/kinetis/TEENSY_3.5.html
- http://www.utasker.com/kinetis/Hexiwear-K64F.html

Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : http://www.utasker.com/support.html