Quantcast
Channel: Renesas Synergy Platform
Viewing all articles
Browse latest Browse all 23645

Forum Post: RE: S7G2: Workaround to enhance number of external IRQs?

$
0
0
Hi Ralph, In addition to the KEY Input Function, if you need yet more pins, you could look at using the Port Group Function of the ELC and a spare GPT timer if you have one. The inputs of Ports 1, 2, 3 & 4 can be configured to detect a rising, falling, both edges and this event can be passed onto the ELC.  (see chapter 20.2.5 PFS register definition) Unfortunately the ELC can not generate an interrupt itself directly, it can only pass this event onto another peripheral. What I have done is to pass this event onto a GPT timer.  This GPT timer is configured to Up Count on an ELC event, and I configure the Overflow period as 1. Therefore, any event occurs on any of the Ports 1,2,3,4, this increments the GPT counter and an overflow occurs generating an interrupt. In the GPT overflow interrupt I can then go and read the pin states to see which pin generated the interrupt. Here is some very basic example code: I am detecting edges on P1_7 & P1_6 and I toggle the LEDs on P8_7, P8_8, P8_9, P8_10 to show the level status of the 2 lines. You will have to add a GPT timer to your code and configure it for periodic mode, raw count period of 1, enable the overflow interrupt and define a call back. volatile uint8_t event_flag = 0; volatile ioport_level_t temp; void hal_entry(void) {    /* TODO: add your own code here */    g_timer13.p_api- open(g_timer13.p_ctrl, g_timer13.p_cfg);    /* No SPI to enable ELC counting on GPT, so access the registers directly */    /* Using GPT13, which is R_GPTB5 in register definition file */    R_GPTB5- GTUPSR_b.USELCA = 1;   // 1: Enable counter count up on ELCA event input.    R_GPTB5- GTSSR_b.SSELCA = 1;    // 1: Enable counter start on ELCA event input.    g_ioport.p_api- pinCfg(IOPORT_PORT_01_PIN_06, 0x00002000);  // configure P1_6 to detect falling edge    g_ioport.p_api- pinCfg(IOPORT_PORT_01_PIN_07, 0x00002000);  // configure P1_7 to detect falling edge    /* Set the link so that the GPT and IOPORT event are linked */    g_elc.p_api- linkSet(ELC_PERIPHERAL_GPT_A, ELC_EVENT_IOPORT_EVENT_1);      g_elc.p_api- enable();    g_timer13.p_api- start(g_timer13.p_ctrl);    while(1)    {        while( event_flag == 0 );    // flag is set in the GPT overflow call back function below        R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);  // wait for any noise glitches on the pins to stop        event_flag = 0;  // clear the flag for next time        g_ioport.p_api- pinRead(IOPORT_PORT_01_PIN_06, &temp);                if( IOPORT_LEVEL_HIGH == temp )        {            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_HIGH);  // IOPORT_PORT_08_PIN_07            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_08, IOPORT_LEVEL_LOW);  // IOPORT_PORT_08_PIN_07        }        else        {            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_LOW);  // IOPORT_PORT_08_PIN_07            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_08, IOPORT_LEVEL_HIGH);  // IOPORT_PORT_08_PIN_07        }        g_ioport.p_api- pinRead(IOPORT_PORT_01_PIN_07, &temp);        if( IOPORT_LEVEL_HIGH == temp )        {            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_09, IOPORT_LEVEL_HIGH);  // IOPORT_PORT_08_PIN_09            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_10, IOPORT_LEVEL_LOW);  // IOPORT_PORT_08_PIN_09        }        else        {            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_09, IOPORT_LEVEL_LOW);  // IOPORT_PORT_08_PIN_09            g_ioport.p_api- pinWrite(IOPORT_PORT_08_PIN_10, IOPORT_LEVEL_HIGH);  // IOPORT_PORT_08_PIN_10        }    } } void cb_timer(timer_callback_args_t * p_args) {    SSP_PARAMETER_NOT_USED(p_args);    event_flag = 1; } I hope this is of interest Richard

Viewing all articles
Browse latest Browse all 23645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>