Example using 'Global Pin Control Low/High Register' in PORT module for Kinetis K60

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Example using 'Global Pin Control Low/High Register' in PORT module for Kinetis K60

3,282件の閲覧回数
belskyc
Contributor III

Hello,

 

Does anyone have any example code that uses the 'Global Pin Control Low/High Register' on the Kinetis K60 to configure the ports? 

 

Thanks,

~

0 件の賞賛
返信
4 返答(返信)

2,345件の閲覧回数
branislavdrengu
Contributor I

Do you have function example for PORTX_GPCLR ?

0 件の賞賛
返信

2,345件の閲覧回数
belskyc
Contributor III

For clarification, I'm looking for basic examples using the PORTx_GPCLR and PORTx_GPCHR registers in the Kinetis K60. 

 

Does anyone have applications using these registers?  If so, could you please send snipits of your code as examples? 

 

Thanks,

~

0 件の賞賛
返信

2,345件の閲覧回数
mjbcswitzerland
Specialist V

Hi

 

The following configures port A bits0, 3, 6, 22, 25 and 31 to GPIO functionality with enabled pull-up resistor, passive input filter:

 

 

PORTA_GPCLR = ((PORTA_BIT6 | PORTA_BIT3 | PORTA_BIT0) | (PORT_MUX_GPIO | PORT_PS_UP_ENABLE | PORT_PFE));PORTA_GPCHR = (((PORTA_BIT22 | PORTA_BIT25 | PORTA_BIT31) >> 16) | (PORT_MUX_GPIO | PORT_PS_UP_ENABLE | PORT_PFE));

 

 

This is however only a part of what may be needed to configure the complete port functionality and characterisics (eg. first power needs to be applied to the port).

 

The use of PORTx_GPCLR/PORTx_GPHR may save a few instructions but is not that generic since it requires grouping pins requiring identical settings into lower 16 and upper 16 bits.

 

More generally, the following can be used for complete initialision of GPIO input use (for example):

 

_CONFIG_PORT_INPUT(A, (PORTA_BIT22 | PORTA_BIT25 | PORTA_BIT31 | PORTA_BIT6 | PORTA_BIT3 | PORTA_BIT0), (PORT_PS_UP_ENABLE | PORT_PFE));

 

 

where:

 

#define _CONFIG_PORT_INPUT(ref, pins, chars)  SIM_SCGC5 |= SIM_SCGC5_PORT##ref; \
                                              fnConnectGPIO(PORT##ref, pins, chars); \
                                               GPIO##ref##_PDDR &= ~(pins);

and

 

// This routine is used to connect a number of port pins to their GPIO function with defined characteristics
//
extern void fnConnectGPIO(int iPortRef, unsigned long ulPortBits, unsigned long ulCharacteristics)
{
    unsigned long ulBit = 0x00000001;
    volatile unsigned long *ptrPCR = (volatile unsigned long *)(PORT0_BLOCK + (iPortRef * 0x1000));
    while (ulPortBits != 0) {
        if (ulPortBits & ulBit) {
            *ptrPCR = (PORT_MUX_GPIO | ulCharacteristics);               // set the GPIO characteristics for each port pin
            ulPortBits &= ~(ulBit);
        }
        ptrPCR++;
        ulBit <<= 1;
    }
}

 

Similar macros (with small changes) also allow generic output and peripheral type configuration.

 

Regards

 

Mark

 

 

 

0 件の賞賛
返信

2,345件の閲覧回数
branislavdrengu
Contributor I

That's wrong........ GPCLR can't do anything with pins 16-31. It is Global Pin Control LOW register and it can only SET or CLEAR 0-15 bit's of PORTX

0 件の賞賛
返信