LPC845 Brk - I2C example

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC845 Brk - I2C example

2,848件の閲覧回数
tomato
Contributor III

Hi all,

I want to try the I2C of the LPC845 BRK following what reported in the user manual

tomato_0-1674818545971.png

This is the initialization function of the I2C0 in the LPC845brk

tomato_1-1674818861357.png

And this is the send data function

tomato_2-1674818959822.png

I tried to launch a program with these two function called but I am doing something wrong.

While debugging the code is stuck here

tomato_6-1674819642284.png

 

 

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 

tomato_4-1674819347568.png

Can you tell me what I am doing wrongly?

Thanks 

 

 

 

 

 

 

0 件の賞賛
21 返答(返信)

2,775件の閲覧回数
luca_rimondini
Contributor I

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.

2,725件の閲覧回数
tomato
Contributor III
Hi @luca_rimondini did you solve your problem?
0 件の賞賛

2,786件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @tomato 

How is your slave configured? Are you using another board for the slave or something else?

 

B.R

VaneB

0 件の賞賛

2,771件の閲覧回数
tomato
Contributor III

Hi @VaneB 

 

The slave is an IC (with I2C interface (the adress is correct)) placed on a breadboard 

0 件の賞賛

2,728件の閲覧回数
tomato
Contributor III
@VaneB can you help me?
0 件の賞賛

2,717件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

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.

0 件の賞賛

2,713件の閲覧回数
tomato
Contributor III

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? 

 

0 件の賞賛

2,706件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @tomato 

Make sure you have the following to configure the I2C:

  • Provide main_clk as function clock to I2C0
  • Enable bus clocks to I2C0 and SWM
  • Configure the SWM
  • Give I2C0 a reset
  • Configure the I2C0 clock divider
  • Configure the I2C0 CFG register
  • Enable the I2C0 slave pending interrupt
0 件の賞賛

2,696件の閲覧回数
tomato
Contributor III

Hi @VaneB  I think I have made almost everything you mentioned below (you can check it in my first post)

  • Provide main_clk as function clock to I2C0 

SYSCON->FCLKSEL[5]=0x0; // i2c clock selection: main clock

  • Enable bus clocks to I2C0 and SWM

SYSCON->SYSAHBCLKCTRL0|=(1<<5); /* enable clock to I2C0 */

  • Configure the SWM

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 */

  • Give I2C0 a reset

SYSCON->PRESETCTRL0&=~(1<<5);
SYSCON->PRESETCTRL0|=(1<<5); /* reset I2C0 */

  • Configure the I2C0 clock divider

I2C0->CLKDIV=500;

  • Configure the I2C0 CFG register

I2C0->CFG=(1<<0); /* master mode */

  • Enable the I2C0 slave pending interrupt

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

tomato_0-1675847110317.png

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.

tomato_0-1675857698544.png

 

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?

0 件の賞賛

2,689件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @tomato 

I suggest to take a look at the I2C example included on LPC845 Example Code Bundle MCUXpresso.

0 件の賞賛

2,685件の閲覧回数
tomato
Contributor III

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

0 件の賞賛

2,678件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @tomato 

Did you try that the I2C_masterslave works for you?

0 件の賞賛

2,653件の閲覧回数
tomato
Contributor III

@VaneB 

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?

0 件の賞賛

2,651件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @tomato 

When testing the example code and that it works, we ensure that there are no problems whit the HW.

0 件の賞賛

2,642件の閲覧回数
tomato
Contributor III

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

0 件の賞賛

2,628件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

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.

0 件の賞賛

2,254件の閲覧回数
tomato
Contributor III
@VaneB can you take a look at the post below?
0 件の賞賛

2,573件の閲覧回数
tomato
Contributor III

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

tomato_0-1676284572991.png

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

 

0 件の賞賛

1,968件の閲覧回数
ErichStyger
Senior Contributor V

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.

0 件の賞賛

2,033件の閲覧回数
tomato
Contributor III

@VaneB 

Can you tell me if you can help me? 

0 件の賞賛