Reading a Port as a set of parallel bits

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

Reading a Port as a set of parallel bits

跳至解决方案
600 次查看
davepfaltzgraff
Senior Contributor I

In KSDK1, I was able to read a port as a set or parallel bits using the GPIO_HAL_ReadPortInput(FP_BASE) function.

 

It appears that in KSDK2, this has been removed and I can only find routines to read individual bits on the port using the GPIO_ReadPinInput(FP_BASE, PIN_NO) routine.

 

How can I read the set if bits in KSDK2?

标签 (1)
0 项奖励
1 解答
373 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, David,

This is the api function GPIO_ReadPinInput() body:

static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)

{

    return (((base->PDIR) >> pin) & 0x01U);

}

You see that the function only read the specified bit instead of all the bits in PDIR register.

If you want to read all the PDIR register, you can define a function yourself.

for example

static inline uint32_t GPIO_ReadInput(GPIO_Type *base)

{

    return (base->PDIR);

}

Hope it can help you.

BR

XiangJun Rong

在原帖中查看解决方案

0 项奖励
2 回复数
373 次查看
davepfaltzgraff
Senior Contributor I

Hi XiangJun Rong,

That's what I had thought, but when I tried it, I didn't get the results I expected. My problem was some code brought in from an old project that was driving the pins low when I expected them to be inputs. Now that I have eliminated that code, the system is now operating as expected.

Thanks,

Dave

0 项奖励
374 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, David,

This is the api function GPIO_ReadPinInput() body:

static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)

{

    return (((base->PDIR) >> pin) & 0x01U);

}

You see that the function only read the specified bit instead of all the bits in PDIR register.

If you want to read all the PDIR register, you can define a function yourself.

for example

static inline uint32_t GPIO_ReadInput(GPIO_Type *base)

{

    return (base->PDIR);

}

Hope it can help you.

BR

XiangJun Rong

0 项奖励