How to tristate an output pin on KL03

cancel
Showing results for 
Search instead for 
Did you mean: 

How to tristate an output pin on KL03

593 Views
yz0
Contributor I

I am a bit confused by the manual when it is describing the GPIO behavior with regard to input/output buffers. 

I am reading from the KL03 Sub-Family Reference Manual Chapter 12 (PORT Control and Interrupts). Section 12.7.1 has the following sentence: "A pin can be floating due to an input pin that is not connected or an output pin that has tristated (output buffer is disabled)".

The problem with the statement above is that KL03 does not appear to have a register in the PORT module that would enable or disable an output buffer. Would someone help me understand what was meant by the statement above and how can I set the output pin to Z / High Impedance / Tristate?

Here is how I set everything up right now:

//Enable PORTB clock

SIM->SCGC5 |= SIM_SCGC5_PORTB(1);

//Initialize PB0 as GPIO

PORTB->PCR[0] = (PORTB->PCR[0] & ~PORT_PCR_MUX_MASK) | PORT_PCR_MUX(1);

//Set PB0 as output direction

GPIOB->PDDR |= (1U << 0U);

//Set PB0 to level HIGH

GPIOB->PDOR |= (1U << 0U);

//Need help setting PB0 to high impedance state

0 Kudos
1 Reply

344 Views
mjbcswitzerland
Specialist V

Hi

The reference is general and some peripheral functions (such as FlexTimers, SPI, I2S) can tri-state outputs as part of their normal operation. The reference is not specific to GPIO output mode, where there is no control to tri-state a "GPIO output" itself. To tri-state a GPIO configure pin you need to sets its direct to input and remove any pull-up/down resistors.

In the uTasker project your code sequence is done with:

_CONFIG_DRIVE_PORT_OUTPUT_VALUE(B, (PORTB_BIT0), (PORTB_BIT0), (PORT_SRE_SLOW | PORT_DSE_HIGH)); // configure clock gating, set output and characteristics and drive to '1'

_FLOAT_PORT(B, PORTB_BIT0); // set to floating input

Port macro overview: http://www.utasker.com/forum/index.php?topic=1875.0

Macros also use bit-banding or bit-manipulation engine for maximum efficiency.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
Kinetis KL02/KL03/KL05:
- http://www.utasker.com/kinetis/FRDM-KL02Z.html
- http://www.utasker.com/kinetis/FRDM-KL03Z.html
- http://www.utasker.com/kinetis/FRDM-KL05Z.html

For less questions and faster, cheaper developments: try uTasker for Kinetis (also free open source on Git Hub)

0 Kudos