FRDM-MCXN947 i2c set to FLEXCOMM9 at P2_4 and P2_3 but fail to function

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

FRDM-MCXN947 i2c set to FLEXCOMM9 at P2_4 and P2_3 but fail to function

Jump to solution
9,852 Views
CarlLee
Contributor III

Dear all,

  I have downloaded the demo "frdmmcxn947_lpi2c_interrupt_b2b_transfer_master" and it is function well that is using FLEXCOMM2 P4.0 and P4.1 as SDA and SCL pins.

  I am going to set the i2c function to FLEXCOMM9 P2.4 and P2.3 by modifying the code in the demo code "frdmmcxn947_lpi2c_interrupt_b2b_transfer_master" as follows.

1) modify the code in "lpi2c_interrupt_b2b_transfer_master.c"

  from

/* attach FRO 12M to FLEXCOMM2 */

CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1u);

CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);

 

  to

/* attach FRO 12M to FLEXCOMM9 */

CLOCK_SetClkDiv(kCLOCK_DivFlexcom9Clk, 1u);

CLOCK_AttachClk(kFRO12M_to_FLEXCOMM9);

 

2) modify the code in "lpi2c_interrupt_b2b_transfer_master.c"

from

#define EXAMPLE_I2C_MASTER_BASE (LPI2C2_BASE)

to

#define EXAMPLE_I2C_MASTER_BASE (LPI2C9_BASE)

 

3) modify the code in "pin_mux.c"

void LPI2C2_InitPins(void)

{

/* Enables the clock for PORT2: Enables clock */

CLOCK_EnableClock(kCLOCK_Port2);

 

const port_pin_config_t port2_4_pinP1_config = {/* Internal pull-up resistor is enabled */

kPORT_PullUp,

/* Low internal pull resistor value is selected. */

kPORT_LowPullResistor,

/* Fast slew rate is configured */

kPORT_FastSlewRate,

/* Passive input filter is disabled */

kPORT_PassiveFilterDisable,

/* Open drain output is enabled */

kPORT_OpenDrainEnable,

/* Low drive strength is configured */

kPORT_LowDriveStrength,

/* Pin is configured as FC2_P0 */

kPORT_MuxAlt2,

/* Digital input enabled */

kPORT_InputBufferEnable,

/* Digital input is not inverted */

kPORT_InputNormal,

/* Pin Control Register fields [15:0] are not locked */

kPORT_UnlockRegister};

 

/* PORT2_4 (pin P1) is configured as FC2_P0 */

PORT_SetPinConfig(PORT2, 4U, &port2_4_pinP1_config);

 

const port_pin_config_t port2_3_pinP2_config = {/* Internal pull-up resistor is enabled */

kPORT_PullUp,

/* Low internal pull resistor value is selected. */

kPORT_LowPullResistor,

/* Fast slew rate is configured */

kPORT_FastSlewRate,

/* Passive input filter is disabled */

kPORT_PassiveFilterDisable,

/* Open drain output is enabled */

kPORT_OpenDrainEnable,

/* Low drive strength is configured */

kPORT_LowDriveStrength,

/* Pin is configured as FC2_P1 */

kPORT_MuxAlt2,

/* Digital input enabled */

kPORT_InputBufferEnable,

/* Digital input is not inverted */

kPORT_InputNormal,

/* Pin Control Register fields [15:0] are not locked */

kPORT_UnlockRegister};

 

/* PORT2_3 (pin P2) is configured as FC2_P1 */

PORT_SetPinConfig(PORT2, 3U, &port2_3_pinP2_config);

}

 

 

But the i2c cannot function.

Are there anything I am missing?

 

Please comment.

 

Thanks

Carl

 

 

Labels (1)
0 Kudos
Reply
1 Solution
9,618 Views
Alex_Wang
NXP Employee
NXP Employee

Hi, @CarlLee 

You're missing something, and you also need to change the macro definition clock rate. As follows:

#define LPI2C_MASTER_CLOCK_FREQUENCY CLOCK_GetLPFlexCommClkFreq(9u)

Clock selection is as follows:

Alex_Wang_0-1710984763149.jpeg

Hope this helps you.

Best regards, Alex

 

View solution in original post

0 Kudos
Reply
7 Replies
9,619 Views
Alex_Wang
NXP Employee
NXP Employee

Hi, @CarlLee 

You're missing something, and you also need to change the macro definition clock rate. As follows:

#define LPI2C_MASTER_CLOCK_FREQUENCY CLOCK_GetLPFlexCommClkFreq(9u)

Clock selection is as follows:

Alex_Wang_0-1710984763149.jpeg

Hope this helps you.

Best regards, Alex

 

0 Kudos
Reply
9,573 Views
CarlLee
Contributor III

Dear @Alex_Wang  and @Alice_Yang,

Thanks for your help!

The solution is work properly. 

I will add the i2c code to the face detection demo.

Previously I have successfully added i2c devices to the MCX_N9XX-BRK board with face detection.

This time, I need to transport the code to this new FRDM-MCXN947 board.

Regards,

Carl

 

9,813 Views
CarlLee
Contributor III

Is there anyone who can give me some advice?

0 Kudos
Reply
9,781 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @CarlLee 

What about the signal when using logic analyzer measure? 

How about using Config tool to config Flexcomm9, then refer to the code?

 

BR

Alice

0 Kudos
Reply
9,774 Views
CarlLee
Contributor III

Dear Alice, @Alice_Yang

I test the i2c at pins P2.4 and P2.3 as follow.

1)  I start a new project by import SDK example "frdmmcxn947_lpi2c_interrupt_b2b_transfer_master".

2)  I test the i2c function with another FRDM-MCXN947 which act as a i2c slave and function properly.

3)  I am going to change the i2c master SDA and SCL pins to P2.4 and P2.3 respectively.

4)  I use the Config tool to config Flexcomm9 pins SDA and SCL pins as P2.4 and P2.3 respectively.

5)  I also activate the clock of Flexcomm9 in the Config tool.

6)  I remark the line "LPI2C2_InitPins();" in the file "pin_mux.c"

7)  I modify the line in red color "#define EXAMPLE_I2C_MASTER_BASE(LPI2C9_BASE)"

in the file "lpi2c_interrupt_b2b_transfer_master.c"

8 )  I remark two more lines in the file "lpi2c_interrupt_b2b_transfer_master.c" as below.

CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1u);

CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);

 

9) I build and download the code.

 

10) I attach the oscilloscope display below. The yellow line is SDA and the blue one is SCL.

 

The i2c is still not function.

Please advice.

Thanks,

Regards,

Carl

 

0 Kudos
Reply
9,726 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @CarlLee 

I haven't find the issue from your steps description. 

Take a photo about hardware connection. Check whether connect the right pins.

If still can not work, please send your project to me, I help to check on my side. thanks.

 

BR

Alice

0 Kudos
Reply
9,685 Views
CarlLee
Contributor III

Dear @Alice_Yang,

  After checking the code and the connection carefully, the i2c is fail to function.

  The connection and the code are attached here.

  Please advice,

  Thanks,

Regards,

Carl

0 Kudos
Reply