I2C

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

I2C

1,156 Views
dineshram
Contributor I

Hi,

I am using MPC5748G Controller "Core 2" for Capacitive Touch Display (Adafruit 2.8"). I am using I2C Protocol for Touch Sense. In this post I have attached the I2C init() and readReg() function. The Problem is the Display is hanging after some time i.e., randomly.

I need suggestions on wheather the function written is ok or needs some changes to solve hanging problem.

 

Thanks

 

void initI2C_1(void)
{
I2C_1.IBFD.B.IBC = 0x20; /* Division ratio to obtain SCL frequency from Platform clock/2. */

I2C_1.IBCR.B.MDIS = 0; /* I2C module is enabled */
I2C_1.IBCR.B.IBIE = 0; /* Interrupt disabled */
// I2C_1.IBCR.B.TXRX = 1; /* Transmit Data */
}

 

 

uint8_t I2C_readReg(uint8_t addr) { /* Master receive function */

SIUL2.GPDO[PJ0].B.PDO_4n = 0; /* Initialize low */

I2C_1.IBCR.B.TXRX = 1; /* Transmit Data */
I2C_1.IBCR.B.MSSL = 1; /* Master mode */
I2C_1.IBSR.B.IBIF = 0;
I2C_1.IBDR.R = 0x70;
while(I2C_1.IBSR.B.TCF != 1); /* Data transfer in progress */
while(I2C_1.IBSR.B.IBIF != 1); /* Data transfer in progress */
(void)I2C_1.IBSR.R;
while(I2C_1.IBSR.B.RXAK != 0); /* Address Received ACK */
SIUL2.GPDO[PJ0].B.PDO_4n = 1;

I2C_1.IBSR.B.IBIF = 0;
I2C_1.IBDR.R = addr;
while(I2C_1.IBSR.B.TCF != 1); /* Data transfer in progress */
while(I2C_1.IBSR.B.IBIF != 1); /* Data transfer in progress */
(void)I2C_1.IBSR.R;
while(I2C_1.IBSR.B.RXAK != 0); /* Address Received ACK */

delay(1000);

I2C_1.IBCR.B.RSTA = 1;

I2C_1.IBSR.B.IBIF = 0;
I2C_1.IBDR.R = 0x71;
while(I2C_1.IBSR.B.TCF != 1); /* Data transfer in progress */
while(I2C_1.IBSR.B.IBIF != 1); /* Data transfer in progress */
(void)I2C_1.IBSR.R;
while(I2C_1.IBSR.B.RXAK != 0); /* Address Received ACK */

delay(1000);

I2C_1.IBSR.B.IBIF = 0;
I2C_1.IBCR.B.TXRX = 0;

data = I2C_1.IBDR.R;
while(I2C_1.IBSR.B.TCF != 1); /* Data transfer in progress */
while(I2C_1.IBSR.B.IBIF != 1); /* Data transfer in progress */
(void)I2C_1.IBSR.R;
I2C_1.IBSR.B.IBIF = 0;
delay(5000);

return I2C_1.IBDR.R;


}

0 Kudos
Reply
1 Reply

1,153 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

please follow Figure 44-13. Recommended I2C interrupt service routine flowchart of the RM for your code.
For clearing status bits do not use bit access, rather use register access, moreover flag is cleared by writing 1 to it.
Maybe you can try to use simple driver posted at https://community.nxp.com/t5/MPC5xxx-Knowledge-Base/MPC5xxx-I2C-communication-driver/ta-p/1121925
There are few examples posted that uses this driver, see https://community.nxp.com/t5/MPC5xxx-Knowledge-Base/MPC5-software-example-list/ta-p/1102445, for example https://community.nxp.com/t5/MPC5xxx-Knowledge-Base/Example-MPC5748G-PCF8885-Touch-sensing-demo-GHS6...

BR, Petr

0 Kudos
Reply