This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

direct referrence to GPIO pins

another newbie question.

I have a piece of code that I am porting from PICC. In PICC, you can make reference to specific pins ("#define sclk GPIO5" for example), and in your code, you can write to sclk to change the pin output on GPOI5. This makes porting code or changing pin layout so much easier as you can simple redefine sclk to a different pin to make the code work.

ARM seems to prefer to change its pin output through IOSET / IOCLR.

To make the existing PICC code work, I would prefer to be able to define certain pins logically, and change their states by referencing their logic names.

how do you do that in ARM? Thanks in advance.

Parents
  • we have discussed all along why it is not possible to do the PIC-styled direct port access in this thread. the reasons given range from "it is ARM's business model, stupid" to "it is not good for your health", :).

    here is a little piece of code that does direct port access on LPC210x chips and you can expand it to other ARM chips too.

    [code]
    #include <LPC210x.H>
    #include "myioconfig.h"

    //hardware configuration
    #define LEDPort IOPIN_bit
    #define LED P0_8 //LED connected to P0.8
    //end hardware configuration

    #define ON 1
    #define OFF 0
    #define LED_STATE LEDPort.LED
    //#define LED_ON IOSET_bit.LED = 1 //turn on the LED
    //#define LED_OFF IOCLR_bit.LED = 1 //turn off the LED
    #define LED_ON LEDPort.LED=ON
    #define LED_OFF LEDPort.LED=OFF

    void delay(unsigned long dly);
    void init_mcu(void);

    void delay(unsigned long dly) { for(; dly>0; dly--) ;
    }

    void init_mcu(void) { PINSEL0 = 0x0; //??????GPIO IODIR_bit.LED = 1; //set the led pin as output
    }

    int main(void)
    {

    init_mcu(); //initialize the mcu LED_OFF; //turn the led off

    while(1) { delay(100000); (LED_STATE)? (LED_OFF):(LED_ON); //toggle the led pin }
    } [/code]

    enjoy.

    it is basically done by redefining the GPIO registers in the header file.

Reply
  • we have discussed all along why it is not possible to do the PIC-styled direct port access in this thread. the reasons given range from "it is ARM's business model, stupid" to "it is not good for your health", :).

    here is a little piece of code that does direct port access on LPC210x chips and you can expand it to other ARM chips too.

    [code]
    #include <LPC210x.H>
    #include "myioconfig.h"

    //hardware configuration
    #define LEDPort IOPIN_bit
    #define LED P0_8 //LED connected to P0.8
    //end hardware configuration

    #define ON 1
    #define OFF 0
    #define LED_STATE LEDPort.LED
    //#define LED_ON IOSET_bit.LED = 1 //turn on the LED
    //#define LED_OFF IOCLR_bit.LED = 1 //turn off the LED
    #define LED_ON LEDPort.LED=ON
    #define LED_OFF LEDPort.LED=OFF

    void delay(unsigned long dly);
    void init_mcu(void);

    void delay(unsigned long dly) { for(; dly>0; dly--) ;
    }

    void init_mcu(void) { PINSEL0 = 0x0; //??????GPIO IODIR_bit.LED = 1; //set the led pin as output
    }

    int main(void)
    {

    init_mcu(); //initialize the mcu LED_OFF; //turn the led off

    while(1) { delay(100000); (LED_STATE)? (LED_OFF):(LED_ON); //toggle the led pin }
    } [/code]

    enjoy.

    it is basically done by redefining the GPIO registers in the header file.

Children