Hi,
I'm writing a sample code to initialize I2C communication on my LPC845 and PCF8574 of LCD HD44780.
At the moment, I would to write simple code with the only scope to see the signals of SDA and SCL in oscilloscope and to control that all is initialized correctly.
The I2C of LPC is converted with bi-directional 5V level shifter (I do this circuit with 2 IRFZ44n, N-MOS) as requested by PCF8574 --> (attachments)
I've initialized all the register that are wrote into the datasheet (as you can see from attachments) but I don't see anything on my oscilloscope screen.
What It could be the issue?, could you help me please? I would understand which errors are in the code.
Thanks,
Ivan
Solved! Go to Solution.
Hi Hang,
In these days I've tried multiple configurations, as you listed now, the N-MOS level translator and pull-ups connected to PIO0_10 and PIO0_11 are working correctly (the circuit is the same of the attached photos).
I've found that I was wrong to put in the right place the while statements for PENDING status during the I2C Master transmission.
As linked in the manual guide into I2C0 Chapter, the third and sixth points "Wait for the pending status to be set (MSTPENDING = 1) by polling the STAT register" has to be as follow:
LPC_I2C0 -> MSTDAT = ADDR;
MSCTL_REG = I2C_MSTCTL_MSTSTART_ON;
MSCTL_REG = I2C_MSTCTL_MSTSTART_OFF;
while(!(LPC_I2C0 ->STAT & (1 << 0)));
LPC_I2C0 -> MSTDAT = DATA;
while(!(LPC_I2C0 ->STAT & (1 << 0)));
MSCTL_REG = I2C_MSTCTL_MSTSTOP_ON;
MSCTL_REG = I2C_MSTCTL_MSTSTOP_OFF;
I've observed also that my "printf " function (for debugging) gave me issues to the right clock timing of I2C, inside the above transmission cycle code...
Thanks,
Ivan
Hi @Ivan_16
There are possible issues to double-check,
1. Incorrect Clock Configuration: Make sure that your system clock is set up correctly and that the I2C peripheral is receiving the correct clock source.
2. Missing Pull-up Resistors: Check that you have external pull-up resistors on both the SDA and SCL lines, especially since you are using an N-MOS-based level shifter.
3. Pin Muxing: Ensure that the pins are properly configured as I2C pins (PIO0_10 for SDA and PIO0_11 for SCL).
4. Incorrect Level Shifter: Double-check the connections of your level shifter circuit to make sure that the directionality is correct for both the SDA and SCL lines.
BR
Hang
Hi Hang,
In these days I've tried multiple configurations, as you listed now, the N-MOS level translator and pull-ups connected to PIO0_10 and PIO0_11 are working correctly (the circuit is the same of the attached photos).
I've found that I was wrong to put in the right place the while statements for PENDING status during the I2C Master transmission.
As linked in the manual guide into I2C0 Chapter, the third and sixth points "Wait for the pending status to be set (MSTPENDING = 1) by polling the STAT register" has to be as follow:
LPC_I2C0 -> MSTDAT = ADDR;
MSCTL_REG = I2C_MSTCTL_MSTSTART_ON;
MSCTL_REG = I2C_MSTCTL_MSTSTART_OFF;
while(!(LPC_I2C0 ->STAT & (1 << 0)));
LPC_I2C0 -> MSTDAT = DATA;
while(!(LPC_I2C0 ->STAT & (1 << 0)));
MSCTL_REG = I2C_MSTCTL_MSTSTOP_ON;
MSCTL_REG = I2C_MSTCTL_MSTSTOP_OFF;
I've observed also that my "printf " function (for debugging) gave me issues to the right clock timing of I2C, inside the above transmission cycle code...
Thanks,
Ivan