K64 Using Pin as GPIO after setup for I2C

Showing results for 
Search instead for 
Did you mean: 

K64 Using Pin as GPIO after setup for I2C

Contributor III


I am having a problem changing the PIN mux at run time after the PIN was already configured.

I currently have a PIN setup iin I2C mux configuration. This pin is used for the SDA signal for I2C.

I need to switch this pin over to GPIO mode to control it. I don't have any other option because the I2C chip I am working with has a very special wake sequence with a very specific timing. 

I have tried setting up the PIN in GPIO mode after configuring but I get a hard fault after trying to write to the PCOR register. Please see the code snippet below with comments. Please let me know how to do this.

I am using the mcuXpresso 2.4 SDK driver. See the code snippet below. 

Additional information

  1. The I2C peripheral is setup in DMA mode with interrupts.
  2. I do not call I2C_MasterDeinit() or destroy of the I2C EDMA handles
    1. I am hoping i do not need to do this as all I want to do is switch the PIN mux over to GPIO and control the line temporary for a few micro seconds.

/*Reconfigure this pin as GPIO pin*/
PORT_SetPinMux(i2c0_sda_pin.port, i2c0_sda_pin.pin, kPORT_MuxAsGpio); 

/*This configuration is not required but I do it anyway to make sure all the registers are setup*/
port_pin_config_t pin_mux1_adv_config0 =
        .pullSelect           = kPORT_PullUp,
        .slewRate             = kPORT_FastSlewRate,
        .passiveFilterEnable  = kPORT_PassiveFilterEnable, /*Filter Tau = 100ns */
        .openDrainEnable      = kPORT_OpenDrainDisable,
        .driveStrength        = kPORT_HighDriveStrength,
        .mux                  = kPORT_MuxAsGpio,
        .lockRegister         = kPORT_UnlockRegister

PORT_SetPinConfig(i2c0_sda_pin.port, i2c0_sda_pin.pin, &pin_mux1_adv_config0);

const gpio_pin_config_t gpio_output_default_low =
        .pinDirection   = kGPIO_DigitalOutput,
        .outputLogic    = 0u

/*The code hard faults here when this function calls GPIO_WritePinOutput() 
which write to the PCOR register*/
GPIO_PinInit(i2c0_sda_pin.bank, i2c0_sda_pin.pin, &gpio_output_default_low);
Labels (1)
Tags (3)
0 Kudos
1 Reply

NXP TechSupport
NXP TechSupport

I try to reconfigure the SDA pin as GPIO output 0, the hard faults did not happen.(i2c_edma_b2b_transfer_master example ...\SDK_2.4.0_FRDM-K64F\boards\frdmk64f\driver_examples\i2c\edma_b2b_transfer\master\iar)

reConfigure SDA as GPIO.png

Please check if the base address which pass into GPIO_WritePinOutput() was correct or not.


Best Regards,



Note: If this post answers your question, please click the Correct Answer button. Thank you!

0 Kudos