How do I configure GPIO (PTBx) as an output?

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

How do I configure GPIO (PTBx) as an output?

951 Views
mihir_rajput
Contributor III

Hello. I am using MM9Z1_638D1 for a project.

How should I correctly configure a GPIO (PTB3) as an output and drive it?

Current implementation:

B_GPIO_CTL = (B_GPIO_CTL_PE3M_MASK | B_GPIO_CTL_DIR3M_MASK); // enable mask
B_GPIO_CTL |= (B_GPIO_CTL_PE3_MASK | B_GPIO_CTL_DIR3_MASK); // enable

B_GPIO_PUC_PUE3 = 1; // pull up enable
B_GPIO_OUT3 = 1; // turning on

B_GPIO_OUT3 = 0; // turning off

Is my understanding correct?

Am I missing something?

I don't see any voltage on that pin.

0 Kudos
3 Replies

814 Views
Q_man
NXP Employee
NXP Employee

Hi Mihir,

the MM9Z1_638 device has registers with masked bits, which allow to set or clear individual bits without the need for a read-modify-write process.
The masked bits correlate to the same "bit name", e.g. B_GPIO_CTL_DIR3(M)_MASK.

For example see the following code examples:

B_GPIO_CTL = (B_GPIO_CTL_DIR3M_MASK | B_GPIO_CTL_DIR3_MASK);   // set PTB3 as OUTPUT

B_GPIO_CTL = (B_GPIO_CTL_DIR3M_MASK |              0      );   // set PTB3 as INPUT

Corrected implementation:

B_GPIO_CTL = (B_GPIO_CTL_PE3M_MASK | B_GPIO_CTL_PE3_MASK );    // enable PTB3 GPIO function
B_GPIO_CTL = (B_GPIO_CTL_DIR3M_MASK| B_GPIO_CTL_DIR3_MASK);   // set PTB3 as OUTPUT

B_GPIO_PUC_PUE3 = 1; // pull up enable
B_GPIO_OUT3 = 1; // turning on

B_GPIO_OUT3 = 0; // turning off

Rgds

W.

0 Kudos

814 Views
mihir_rajput
Contributor III

Is this the right way to drive the pin?

B_GPIO_OUT3 = 1; // turning on

B_GPIO_OUT3 = 0; // turning off

The datasheet talks about PTBX3 as output buffer control.

0 Kudos

814 Views
Q_man
NXP Employee
NXP Employee

Yes, correct!

0 Kudos