MCUXpresso

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

MCUXpresso

1,095 Views
juliancox
Contributor V

I am using a FRDM-KL26Z128 eval board to develop a new product which I have built on a separate PCB. (mainly I2C, SPI and GPIO). To test my add-on hardware I am using a demo application - eCompass. I am using the PIN tool to configure the pins -  2 for the UART (no change and no problem) and 2 for the I2C. The original app uses I2C0 on pins 20 and 21 and I want to use pins 35 and 36. The pins 20 and 21 do not appear on the Routing Details table if I select BOARD_Init_Pins, but they are the only entries on Routing Details table when I select BOARD_I2C_ConfigurePins.

Looking at pin_mux.c  function BOARD_I2C_ConfigurePins(void) showed that pins 20 and 21 were configured for I2C0 with about 6 lines of code for each pin, but there was no entry for Pins 35 and 36, although I selected them on the pin list and then deleted pins 20 and 21 from the pin list. Now pins 35 and 36 appear in the Routing Ddetails list for both BOARD_Init_Pins and BOARD_I2C_ConfigurePins. They also now appear in functionBOARD_I2C_ConfigurePins(void) but with only one line of code

You will probably realise that my experience with MCUXpresso is somewhat limited and I would like to know why there are differences between the old  and new I2C0 configurations (apart from the pin allocations)

0 Kudos
Reply
5 Replies

1,065 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

This is the pin assignment of KL16 with 64 pin LQFP

xiangjun_rong_0-1712456607272.png

This is the pin mux register

xiangjun_rong_1-1712456933134.png

 

This is the procedure to configure pins:

1)enable PORTB gated clock

SIM->SCGC5|=1<<10|1<<9;

2)configure the Pin35 and Pin36 as I2C0 pins as ALT2

PORTB_0:

PORTB->PCR[0]&=~(7<<8);

PORTB->PCR[0]|=(2<<8);

 

PORTB_1:

PORTB->PCR[1]&=~(7<<8);

PORTB->PCR[1]|=(2<<8);

 

Then the PTB0/PTB1 will function as I2C0 pins.

I do not see your code, pls check above description.

Hope it can help you

BR

XiangJun Rong

 

0 Kudos
Reply

1,037 Views
juliancox
Contributor V

Since my first post I changed the I2C pins to 53 and 54 (it makes connection to my hardware a little easier. when I tested it there was no activity neither pin. When I allocated the new pins they appeared in the BOARD_I2C_ConfigurePins table, but after I "updated the code" they also appeared in the  BOARD_InitPins table. Below is a copy of pin_mux.c taken from the code windowing the "Pins" perspective.

/***********************************************************************************************************************
* This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
* will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
**********************************************************************************************************************/

/* clang-format off */
/*
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Pins v15.0
processor: MKL26Z128xxx4
package_id: MKL26Z128VLH4
mcu_data: ksdk2_0
processor_version: 13.0.1
board: FRDM-KL26Z
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
/* clang-format on */

#include "fsl_common.h"
#include "fsl_port.h"
#include "pin_mux.h"

/* FUNCTION ************************************************************************************************************
*
* Function Name : BOARD_InitBootPins
* Description : Calls initialization functions.
*
* END ****************************************************************************************************************/
void BOARD_InitBootPins(void)
{
BOARD_InitPins();
}

/* clang-format off */
/*
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
BOARD_InitPins:
- options: {callFromInitBoot: 'true', coreID: core0, enableClock: 'true'}
- pin_list:
- {pin_num: '23', peripheral: UART0, signal: RX, pin_signal: TSI0_CH2/PTA1/UART0_RX/TPM2_CH0}
- {pin_num: '24', peripheral: UART0, signal: TX, pin_signal: TSI0_CH3/PTA2/UART0_TX/TPM2_CH1, direction: OUTPUT}
- {pin_num: '53', peripheral: I2C0, signal: SCL, pin_signal: CMP0_IN2/PTC8/I2C0_SCL/TPM0_CH4/I2S0_MCLK}
- {pin_num: '54', peripheral: I2C0, signal: SDA, pin_signal: CMP0_IN3/PTC9/I2C0_SDA/TPM0_CH5/I2S0_RX_BCLK}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
/* clang-format on */

/* FUNCTION ************************************************************************************************************
*
* Function Name : BOARD_InitPins
* Description : Configures pin routing and optionally pin electrical features.
*
* END ****************************************************************************************************************/
void BOARD_InitPins(void)
{
/* Port A Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortA);
/* Port C Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);

/* PORTA1 (pin 23) is configured as UART0_RX */
PORT_SetPinMux(BOARD_INITPINS_DEBUG_UART_RX_PORT, BOARD_INITPINS_DEBUG_UART_RX_PIN, kPORT_MuxAlt2);

/* PORTA2 (pin 24) is configured as UART0_TX */
PORT_SetPinMux(BOARD_INITPINS_DEBUG_UART_TX_PORT, BOARD_INITPINS_DEBUG_UART_TX_PIN, kPORT_MuxAlt2);

/* PORTC8 (pin 53) is configured as I2C0_SCL */
PORT_SetPinMux(PORTC, 8U, kPORT_MuxAlt2);

/* PORTC9 (pin 54) is configured as I2C0_SDA */
PORT_SetPinMux(PORTC, 9U, kPORT_MuxAlt2);

SIM->SOPT5 = ((SIM->SOPT5 &
/* Mask bits to zero which are setting */
(~(SIM_SOPT5_UART0TXSRC_MASK | SIM_SOPT5_UART0RXSRC_MASK)))

/* UART0 Transmit Data Source Select: UART0_TX pin. */
| SIM_SOPT5_UART0TXSRC(SOPT5_UART0TXSRC_UART_TX)

/* UART0 Receive Data Source Select: UART_RX pin. */
| SIM_SOPT5_UART0RXSRC(SOPT5_UART0RXSRC_UART_RX));
}

/* clang-format off */
/*
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
BOARD_I2C_ConfigurePins:
- options: {coreID: core0, enableClock: 'true'}
- pin_list:
- {pin_num: '53', peripheral: I2C0, signal: SCL, pin_signal: CMP0_IN2/PTC8/I2C0_SCL/TPM0_CH4/I2S0_MCLK}
- {pin_num: '54', peripheral: I2C0, signal: SDA, pin_signal: CMP0_IN3/PTC9/I2C0_SDA/TPM0_CH5/I2S0_RX_BCLK}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
/* clang-format on */

/* FUNCTION ************************************************************************************************************
*
* Function Name : BOARD_I2C_ConfigurePins
* Description : Configures pin routing and optionally pin electrical features.
*
* END ****************************************************************************************************************/
void BOARD_I2C_ConfigurePins(void)
{
/* Port C Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);

/* PORTC8 (pin 53) is configured as I2C0_SCL */
PORT_SetPinMux(PORTC, 8U, kPORT_MuxAlt2);

/* PORTC9 (pin 54) is configured as I2C0_SDA */
PORT_SetPinMux(PORTC, 9U, kPORT_MuxAlt2);
}
/***********************************************************************************************************************
* EOF

I have also attached the pin_mux.c file from the Project/Board folder. It did not reflect ant of the changes that I had made in the "pins" config tool so I edited it to reflect the changed pin allocation. Why are there two Pin_mux.c files (the two pin_mux.h files are also different).

Referring to the pin configuration code you gave me - Where do I put them and will they conflict with (either of) Pin_mux.c?

This problem is really getting me down.

0 Kudos
Reply

1,016 Views
juliancox
Contributor V

please allow me to clarify two points:

1. I have the two pull-ups and the master will send out an address. If the address does not match any slave device it will not receive an ACK and the activity will terminate. However, there is no activity on the I2C output pins, but there should be AT LEAST 8 clock pulses and 8 address pulses (assuming that no slave responds).

2. When I look at pin_mux.c using the "Pins" config tool it shows: -

void BOARD_I2C_ConfigurePins(void)

{

/* Port C Clock Gate Control: Clock enabled */

CLOCK_EnableClock(kCLOCK_PortC);

 

/* PORTC8 (pin 53) is configured as I2C0_SCL */

PORT_SetPinMux(PORTC, 8U, kPORT_MuxAlt2);

 

/* PORTC9 (pin 54) is configured as I2C0_SDA */

PORT_SetPinMux(PORTC, 9U, kPORT_MuxAlt2);

}

but when I open pin_mux.c from the project explorer window I get a different result:

void BOARD_I2C_ConfigurePins(void) {

CLOCK_EnableClock(kCLOCK_PortE); /* Port E Clock Gate Control: Clock enabled */

 

const port_pin_config_t portc8_pin53_config = {

     kPORT_PullUp, /* Internal pull-up resistor is enabled */

     kPORT_SlowSlewRate, /* Slow slew rate is configured */

     kPORT_PassiveFilterDisable, /* Passive filter is disabled */

     kPORT_LowDriveStrength, /* Low drive strength is configured */

     kPORT_MuxAlt2, /* Pin is configured as I2C0_SCL */

};

PORT_SetPinConfig(PORTE, PIN24_IDX, &portc8_pin53_config); /* PORTE24 (pin 20) is configured as I2C0_SCL */

const port_pin_config_t portc9_pin54_config = {

      kPORT_PullUp, /* Internal pull-up resistor is enabled */

      kPORT_SlowSlewRate, /* Slow slew rate is configured */

      kPORT_PassiveFilterDisable, /* Passive filter is disabled */

      kPORT_LowDriveStrength, /* Low drive strength is configured */

      kPORT_MuxAlt2, /* Pin is configured as I2C0_SDA */

};

PORT_SetPinConfig(PORTE, PIN25_IDX, &portc9_pin54_config); /* PORTE25 (pin 21) is configured as I2C0_SDA */

}

In the first one the function is "PORT_SetPinMux("

and in the second one the function is "PORT_SetPinConfig("

Why are there two versions of the same file in the project, which one is correct and how do I get rid of the other one?

0 Kudos
Reply

1,012 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

In the debugger, after the pin_mux.c has been executed, pls check the

PORTC_PCR[8]/PORTC_PCR[9] registers and check the MUX bits if the bits are 2.

You can also use the code:

This is the procedure to configure pins:

1)enable PORTC gated clock

SIM->SCGC5|=1<<11;

2)configure the Pin35 and Pin36 as I2C0 pins as ALT2

PORTC_8:

PORTC->PCR[8]&=~(7<<8);

PORTC->PCR[8]|=(2<<8);

 

PORTC_9:

PORTC->PCR[9]&=~(7<<8);

PORTC->PCR[9]|=(2<<8);

 

xiangjun_rong_0-1712738809928.png

Hope it can help you

BR

XiangJun Rong

0 Kudos
Reply

1,022 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

From pin assignment, I suppose that the following code is okay to configure the PTC8/8 as I2C0 pins, after you configure PTC8/9 as I2C pins, they are open drain automatically.

 

From hardware perspective, I have checked the FRDM-KL26Z schematics, the PTC8/9 are connected to the pin14/16 of J1 without connected to the other IC, you should connect pull-up resistor on the two pins and connect them to an I2C slave device, because I2C slave device is required to give ACK signal when slave device has received matched address.

void BOARD_I2C_ConfigurePins(void)
{
/* Port C Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);

/* PORTC8 (pin 53) is configured as I2C0_SCL */
PORT_SetPinMux(PORTC, 8U, kPORT_MuxAlt2);

/* PORTC9 (pin 54) is configured as I2C0_SDA */
PORT_SetPinMux(PORTC, 9U, kPORT_MuxAlt2);
}

Hope it can help you

BR

XiangJun Rong

 

0 Kudos
Reply