MPC5748G_I2C module

cancel
Showing results for 
Search instead for 
Did you mean: 

MPC5748G_I2C module

1,308 Views
huqiang
Contributor IV

When I initial the I2C module, I run the program step by step, observe the I2C registers.

     I notice that the "I2C_2.IBCR.B.MSSL" bit is always 0 and "I2C_2.IBDR.R" is also always 0.

     When I run the code "I2C_2.IBCR.B.MSSL = 1;", why will bit "I2C_2.IBSR.B.IBIF" and "I2C_2.IBSR.B.IBAL" turn to 1? instead of bit ""I2C_2.IBCR.B.MSSL" turn to 1?

     Is it that I cannnot select master mode, so I cannot set the "I2C_2.IBDR.R"?

 

 

void I2C_2_Init(void)

{

    // I2C Bus Frequency Divider Register (I2C_IBFD)

    I2C_2.IBFD.B.IBC = 0x20; // Division ratio to obtain SCL frequency from Platform clock/2.

 

 

    // I2C Bus Control Register (I2C_IBCR)

    I2C_2.IBCR.B.MDIS = 0; // Enable I2C module

 

 

    I2C_2.IBCR.B.IBIE = 1; // Interrupts from the I2C Bus module are enabled

    I2C_2.IBCR.B.TXRX = 1; // Transmit Mode

 

 

    // Start I2C master mode transmit

    I2C_2.IBCR.B.MSSL = 1; // Master Mode - When this bit is changed from 0 to 1, a START signal is generated on the bus and the master mode is selected

 

 

    I2C_2.IBSR.B.IBIF = 0; // I-Bus Interrupt Flag

    I2C_2.IBDR.R = 0x55; // Sent out 0x55

 

 

    // Observe changes in IBSR[TCF]

//    while (I2C_0.IBSR.B.TCF == 0);

 

 

    //Wait until IBSR[IBIF] = 1.

    while(I2C_2.IBSR.B.IBIF == 0);

 

 

    I2C_2.IBCR.B.MSSL = 0;       // Generate stop signal;

}

Original Attachment has been moved to: I2C_Z4_1.zip

Labels (1)
Tags (2)
4 Replies

760 Views
petervlna
NXP Employee
NXP Employee

Hi,

Seems to me that you can use only I2C_0 as master.

Peter

0 Kudos

760 Views
huqiang
Contributor IV

Thank you. I've tried to use I2C_0 as master, it worked successfully.

Can I use other I2C_x as master? How to code?

0 Kudos

760 Views
PetrS
NXP TechSupport
NXP TechSupport

All I2C modules can work as master. You have to configure pads properly.

Both pins, SDA and SCL, must be configured to enable output buffer, select open-drain function, enable input buffer, select intenal pull ups if there are no external one.

This config can be used:

SIUL2.MSCR[73].R = 0x23880002;  //PE[9] - I2C_2 SCL

SIUL2.IMCR[781-512].R = 1;

SIUL2.MSCR[72].R = 0x23880004;  //PE[8] - I2C_2 SDA

SIUL2.IMCR[782-512].R = 1;

BR, Petr

760 Views
huqiang
Contributor IV

Petr,

Thanks a lot.

Do you have some I2C module examples of transfering data?

BR, Qiang

0 Kudos