Initialize GPIO

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

Initialize GPIO

Jump to solution
1,833 Views
blakehodder
Contributor III

I am new to freescale and am trying to initialize GPIO pins without using MQX. I am trying to initialize the data direction of the ports with the following:

 

MCF_GPIO_DDRTI_DDRTI0,MCF_GPIO_DDRTI = 0;

 

this does not seem to work. Could someone point me in the right direction as to how to accomplish this. I am use to using PICs and the TRIS register.

 

Thanks,

 

Blake

Labels (1)
0 Kudos
1 Solution
677 Views
TomE
Specialist II

First your code has to be "legal C". You're using preprocessor macros, so the first thing you should do is to find the header files they're defined in and find out what you've actually written.

I don't have your project or development system (or know which CPU you're using, as you didn't say), but Googling for "MCF_GPIO_DDRTI_DDRTI0" finds:

mcf52259 initialization code View source code: mcf52259_gpio.h - VerySource

That contains:

#define MCF_GPIO_DDRTI                       (*(vuint8 *)(0x4010001C))

/* Bit definitions and macros for MCF_GPIO_DDRTI */

#define MCF_GPIO_DDRTI_DDRTI0                (0x1)


So your code is turning into:

    (*(vuint8 *)(0x4010001C)), 1 = 0;

You should also read the Reference Manual for your chip and look for the definitions of those registers.

The way it works is that "MCF_GPIO_DDRTI" is defined as a pointer to the control register. This can be read and written simply as a normal variable as "MCF_GPIO_DDRTI = x" or "x = MCF_GPIO_DDRTI". The individual bit positions in the registers are defined as constants - 1, 2, 4, 6, 16, 32, 64 and 128. And so on.

If you want to set all the pins on Port PTI to inputs with the first one only being an output, then:

    MCF_GPIO_DDRTI = MCF_GPIO_DDRTI_DDRTI0;

That simply writes the value "1" into that 8-bit port.

If you want to change the first pin only to an output, leaving any previous settings of the other pins alone:

    MCF_GPIO_DDRTI |= MCF_GPIO_DDRTI_DDRTI0;

Likewise to change one pin to an input:

    MCF_GPIO_DDRTI &= ~MCF_GPIO_DDRTI_DDRTI0;

There should be no need to try and start from scratch with this. You should look for a standalone project for your micro that you can download that performs full initialialization of the part. You can then start from working code and change it to suit your requirements. I'd suggest starting at Freescale's MCF52259 page, clicking on "Software and Tools" and downloading some of the software packages, specifically "Snippets, Boot Code, Headers, Monitors, etc. (2) ".

Tom

View solution in original post

0 Kudos
1 Reply
678 Views
TomE
Specialist II

First your code has to be "legal C". You're using preprocessor macros, so the first thing you should do is to find the header files they're defined in and find out what you've actually written.

I don't have your project or development system (or know which CPU you're using, as you didn't say), but Googling for "MCF_GPIO_DDRTI_DDRTI0" finds:

mcf52259 initialization code View source code: mcf52259_gpio.h - VerySource

That contains:

#define MCF_GPIO_DDRTI                       (*(vuint8 *)(0x4010001C))

/* Bit definitions and macros for MCF_GPIO_DDRTI */

#define MCF_GPIO_DDRTI_DDRTI0                (0x1)


So your code is turning into:

    (*(vuint8 *)(0x4010001C)), 1 = 0;

You should also read the Reference Manual for your chip and look for the definitions of those registers.

The way it works is that "MCF_GPIO_DDRTI" is defined as a pointer to the control register. This can be read and written simply as a normal variable as "MCF_GPIO_DDRTI = x" or "x = MCF_GPIO_DDRTI". The individual bit positions in the registers are defined as constants - 1, 2, 4, 6, 16, 32, 64 and 128. And so on.

If you want to set all the pins on Port PTI to inputs with the first one only being an output, then:

    MCF_GPIO_DDRTI = MCF_GPIO_DDRTI_DDRTI0;

That simply writes the value "1" into that 8-bit port.

If you want to change the first pin only to an output, leaving any previous settings of the other pins alone:

    MCF_GPIO_DDRTI |= MCF_GPIO_DDRTI_DDRTI0;

Likewise to change one pin to an input:

    MCF_GPIO_DDRTI &= ~MCF_GPIO_DDRTI_DDRTI0;

There should be no need to try and start from scratch with this. You should look for a standalone project for your micro that you can download that performs full initialialization of the part. You can then start from working code and change it to suit your requirements. I'd suggest starting at Freescale's MCF52259 page, clicking on "Software and Tools" and downloading some of the software packages, specifically "Snippets, Boot Code, Headers, Monitors, etc. (2) ".

Tom

0 Kudos