Hi all,
I want to try the I2C of the LPC845 BRK following what reported in the user manual
This is the initialization function of the I2C0 in the LPC845brk
And this is the send data function
I tried to launch a program with these two function called but I am doing something wrong.
While debugging the code is stuck here
and the i2c0 registers tell that the i2c is with communication in progress but i tried to see the SCL and SDA lines with the oscilloscopes and I do not see anything passing (always at 3v3). The MSTDAT register has the correct devaddr that I am passing
Can you tell me what I am doing wrongly?
Thanks
Hi @tomato I'm having the same problem, with the only difference that I don't wait in a while loop, but enabled an interruption. I'm trying to do a loopback to the same board only to make it work.
If you want I can share my code with you so maybe both codes end up working right. I leave you my phone so you can text me on whatsapp to communicate more easily, and if we get to a solution then post it here.
+54 11 3588-0405
Sorry if I wrote something wrong, English is not my mother tongue.
Hi @tomato
How is your slave configured? Are you using another board for the slave or something else?
B.R
VaneB
Hi @tomato
I apologize for the late reply.
Could you help me with an oscilloscope image showing the SDA and SCL? It seems that your program is waiting for the ACK.
hi @VaneB thanks for the reply
Actually the SDA and SCL lines are always high at 3v3. It seems that the communication does not start. As you said the program is waiting for the ACK but probing the SDA and SCL with an oscilloscopes I do not see even the address being sent by the lpc845.
Do you think the i2c initialization is correct?
Hi @tomato
Make sure you have the following to configure the I2C:
Hi @VaneB I think I have made almost everything you mentioned below (you can check it in my first post)
SYSCON->FCLKSEL[5]=0x0; // i2c clock selection: main clock
SYSCON->SYSAHBCLKCTRL0|=(1<<5); /* enable clock to I2C0 */
SYSCON->SYSAHBCLKCTRL0|=(1<<7); // Enable SWM clock
SWM0->PINENABLE0&=~(1<<12); /* connect I2C0_SDA to PIO0_11 */
SWM0->PINENABLE0&=~(1<<13); /* connect I2C0_SCL to PIO0_10 */
SYSCON->SYSAHBCLKCTRL0&=~(1<<7); /* disable clock to SWM */
SYSCON->PRESETCTRL0&=~(1<<5);
SYSCON->PRESETCTRL0|=(1<<5); /* reset I2C0 */
I2C0->CLKDIV=500;
I2C0->CFG=(1<<0); /* master mode */
I am not sure about this. Why do I need a slave pending interrupt? I would like to do it in polling mode: when the MSTpending bit is 1 I write to the MSTDAT register.
This is the basic function that I would like to call in my main()
void i2c0_send_data(uint8_t devaddr,uint8_t value){
I2C0->MSTDAT=(devaddr<<1); // send address with R/W bit =0
I2C0->MSTCTL|=(1<<1); // send start
while(!(I2C0->STAT & 1)); /* wait for i2c0 idle or pending*/
I2C0->MSTDAT= value;
I2C0->MSTCTL=(1<<0); // send continue
while(!(I2C0->STAT & 1)); /* wait for i2c0 idle or pending*/
I2C0->MSTCTL|=(1<<2); // send stop
}
As I said before what I do not see working is this highlighted
At first, I doublechecked that the connections are good and probed the lines directly at the lpc pins but the oscilloscope shows that the i2c lines are always high.
Therefore I tried to do something more direct like this
while(1){
I2C0->MSTDAT=(14<<1); // send address with R/W bit =0
I2C0->MSTCTL|=(1<<1); // send start
}
I keep seeing the SCL and SDA lines stucked at 3v3 eventhough the start bit is set.
Therefore I tried to unplug and plug again the SDA pull-up external 2k2 resistor (i am using the LPC845brk on a breadboard) while the while loop was running and the SCL and SDA lines started sending the address. Indeed what I did was to force a start condition. So in my opinion there should be something that hinders having the start condition of the i2c (lpc does not put sda low) but I am not able to figure out what.
Do you have any idea that can help me?
Hi @tomato
I suggest to take a look at the I2C example included on LPC845 Example Code Bundle MCUXpresso.
Hi @VaneB
Can you tell me if i am doing something wrong? In my opinion I am following the steps reported in the manual but there should be something wrong. Do you agree?
However I looked at i2c_masterslave_main.c and it basically does what I am currently doing
Hi @tomato
Did you try that the I2C_masterslave works for you?
Not yet. The example you mentioned has a slightly different approach and it would need to be adapted... why can't we discuss about the code I posted? From your experience can't you tell me if I am doing everything in the reight way?
Hi @tomato
When testing the example code and that it works, we ensure that there are no problems whit the HW.
hi @VaneB
Can you guide me to the installation of the core bundle? Can you give me a list of the steps that I have to follow in order to test the I2C corresctly?
I want to do it correctly 100% since you want to be sure that the HW is working
Hi @tomato
Attached to the example you can find the README file describing the intended purpose, functional description, external connections, program flow and how to run the code.
Hi @VaneB
I am trying to use the attached code bundle
Can you tell me how to import the code bundle in the MCUxpresso?
I am having this issue maybe related to the compiler or to how I imported the project in my folder
After that what shall I do to use test the I2C? I have seen that the I2C folder misses some files that are in the common folder
Thanks
Best regards
Just as an idea: looking at the MCUXpresso SDK I2C driver? This is what I'm using in my projects, and that works fine for me.
Can you tell me if you can help me?