AnsweredAssumed Answered

K64 Using Pin as GPIO after setup for I2C

Question asked by unknowncoder on Jun 29, 2018
Latest reply on Jul 3, 2018 by Robin_Shen


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,, 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,, &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(,, &gpio_output_default_low);