1 Reply Latest reply on Apr 13, 2011 11:38 AM by MR_41

    Modifying Drive Mode From C Code

      Is it possible to change the drive mode of a certain PIN at runtime for C Code.


      In my application I have defined P3[7] as "Pull Up" in the IDE, I want to change it to "Pull Down" at runtime.


      My best guess how to do this is code like this  ...

      PRT3DM1 |= 0x80 PRT3DM0 |= 0x80

      In other examples I've seen stuff about 'disconnect from global bus', would I need to do this as well?

        • 1. Re: Modifying Drive Mode From C Code

          Yes. You are correct.

          To make P3[7] pull up, you would use the following code.

          PRT3DM0 |= 0x80;
          PRT3DM1 |= 0x80;
          PRT3DM2 &= ~0x80;

          To make it pull down:

          PRT3DM0 &= ~0x80;
          PRT3DM1 &= ~0x80;
          PRT3DM2 &= ~0x80;

          The write to PRT3DM2 is redundant if you do not change to any other drive mode that may set the DM2 bit.

          Regarding the connecting to Global bus, if the pin has to connect to a digital block through the Global In or Global Out nets, the the bit in the PRTxGS register has to be set.  If you are controlling the pin through the PRTxDR register, then the pin has to be disconnected from the global bus by clearing the PRTxGS bit.

          Best Regards,
          The PSoC Hacker