Changing Pin mode from output to input at runtime in R5F102AAASP using E2Studio

Hi iam using R5F102AAASP and would like to configure P22 as input or output during runtime, the initial state of the pin will be set to output during boot, iam using E2Studio with GCC

  • By default all ports are input after RESET. Port direction is changed in the port mode register PM2 at address 0xFFF22.

  • RNTalekar,

    Have you been successful switching your port directions?

    Mike Clements
    RenesasRulz Moderator
  • In reply to Mike Clements:

    I tried changing the PORT P1 from Output to Input, by changing PM1. But the input value P1 is always the 0x00.
    I tried adding delay before reading also. not working.
    I tried setting pull up PU1 while setting as input port and disable pull up while setting as output port. not working again.
    I use e2studio and code generator.

    Please help here.
  • In reply to Elango:

    Elango,

    Can you show us the code you are using to initialize your port and set the port direction?
    Can you also include the code that is attempting to read from your port?

    This will allow members of our community to attempt to answer your question.

    Mike Clements
    RenesasRulz Moderator
  • In reply to Mike Clements:

    Here is the code. 

    Intention is to display different number in 7-Segment display(connected to port P1) if key is (connected to pin P12). (so P12 is used as input and also output)

    I created a 1 ms timer and in that service routine,  I am checking the input state of the pin P12 and changing the 7-segment delay output delay value. 

    Port P1 is also used to drive the 7-segment display.

     


    void ConfigureAsDisplay(void)
    {
    P1 = _00_Pn0_OUTPUT_0 | _00_Pn1_OUTPUT_0 | _00_Pn2_OUTPUT_0 | _00_Pn3_OUTPUT_0 | _00_Pn4_OUTPUT_0 |
    _00_Pn5_OUTPUT_0 | _00_Pn6_OUTPUT_0 | _00_Pn7_OUTPUT_0;
    P14 = _00_Pn7_OUTPUT_0;
    PMC14 = _00_PMCn7_DI_ON | _7F_PMC14_DEFAULT;
    PM1 = _00_PMn0_MODE_OUTPUT | _00_PMn1_MODE_OUTPUT | _00_PMn2_MODE_OUTPUT | _00_PMn3_MODE_OUTPUT |
    _00_PMn4_MODE_OUTPUT | _00_PMn5_MODE_OUTPUT | _00_PMn6_MODE_OUTPUT | _00_PMn7_MODE_OUTPUT;
    PM14 = _00_PMn7_MODE_OUTPUT | _7F_PM14_DEFAULT;
    }


    void ConfigureAsKeyPad(void)
    {
    P1 = _00_Pn0_OUTPUT_0 | _00_Pn1_OUTPUT_0 | _00_Pn3_OUTPUT_0 | _00_Pn4_OUTPUT_0;
    P14 = _00_Pn7_OUTPUT_0;
    PU1 = _04_PUn2_PULLUP_ON | _20_PUn5_PULLUP_ON | _40_PUn6_PULLUP_ON | _80_PUn7_PULLUP_ON;
    PIM1 = _20_PIMn5_TTL_ON | _40_PIMn6_TTL_ON | _80_PIMn7_TTL_ON;
    PMC14 = _00_PMCn7_DI_ON | _7F_PMC14_DEFAULT;
    PM1 = _00_PMn0_MODE_OUTPUT | _00_PMn1_MODE_OUTPUT | _04_PMn2_MODE_INPUT | _00_PMn3_MODE_OUTPUT |
    _00_PMn4_MODE_OUTPUT | _20_PMn5_MODE_INPUT | _40_PMn6_MODE_INPUT | _80_PMn7_MODE_INPUT;
    PM14 = _00_PMn7_MODE_OUTPUT | _7F_PM14_DEFAULT;
    }

    unsigned char code=0x3F;
    //1 ms interval timer
    static void __near r_tau0_channel0_interrupt(void)
    {
    /* Start user code. Do not edit comment generated here */
    ConfigureAsKeyPad();
    NOP();
    if(!P1_bit.no2)
       code=0xFF;
    else
    code=0x3F;
    ConfigureAsDisplay();
    P1=code;
    /* End user code. Do not edit comment generated here */
    }

  • In reply to Mike Clements:

    If I enable TTL input buffer on other ports (eg. P16), the input and output switching works. Read value is actual value on the pin (I connected a simple push switch to GND). There are ports without TTL input buffer. Those ports does not work as input. It returns last output value at that pin.