Initialize GPIO

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Initialize GPIO

跳至解决方案
2,570 次查看
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

标签 (1)
标记 (4)
0 项奖励
回复
1 解答
1,414 次查看
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 项奖励
回复
1 回复
1,415 次查看
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 项奖励
回复