I2C stop working after C_CAN Init

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

I2C stop working after C_CAN Init

1,665 Views
davidesalvetti
Contributor II

I have a problem with the  i2C when I initialize the C_Can on LPC11C24. If I don't initialize the C_Can in my code everything works well, but when I add it and i debug the system the I2C stops working. To integrate the C-Can into my code I used the nxp example. My I2C initialization is:

//I2C
Chip_SYSCTL_PeriphReset(RESET_I2C0);
Chip_I2C_Init(I2C0);
Chip_I2C_SetClockRate(I2C0, I2C_SPEED);
i2c_set_mode(I2C0, 0);

While the C_Can initialization is:

void Init_Can(void){// //CAN
/* Publish CAN Callback Functions */
CCAN_CALLBACKS_T callbacks = {
CAN_rx,
CAN_tx,
CAN_error,
NULL,
NULL,
NULL,
NULL,
NULL,
};
baudrateCalculate(TEST_CCAN_BAUD_RATE, CanApiClkInitTable);
LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE);
//Configure the CAN callback functions
LPC_CCAN_API->config_calb(&callbacks);
// Enable the CAN Interrupt
NVIC_SetPriority(CAN_IRQn, 7);
NVIC_EnableIRQ(CAN_IRQn);

}

The system remains into the following function:

void Chip_I2C_EventHandler(I2C_ID_T id, I2C_EVENT_T event)
{
struct i2c_interface *iic = &i2c[id];
volatile I2C_STATUS_T *stat;

/* Only WAIT event needs to be handled */
if (event != I2C_EVENT_WAIT) {
return;
}

stat = &iic->mXfer->status;
/* Wait for the status to change */
while (*stat == I2C_STATUS_BUSY) {}   // the system remains here
}

any ideas? I need to use the I2C and the C_Can together but it seems that at the I2C doesn't like the C_Can.

0 Kudos
12 Replies

1,244 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Davide Salvetti,

   I already test it on our LPCXpresso LPC11C24, and use the lpcopen_v2_00a_lpcxpresso_nxp_lpcxpresso_11c24 code.

   I copy the CAN code to the I2C, after testing, I find both I2C and CAN are working, this is my testing result.

   Because I didn't add I2C slave, just use master send 0XB6, then NACK.

   I have test it a long time, all my CAN and I2C works.

pastedImage_1.png

I have attached my test project for your reference.

0 Kudos

1,244 Views
matijapichler
Contributor I

Greetings kerryzhou ,

In post above, a picture/screenshot of PC Windows desktop is shown(also in this post attachment),  which PC software for CAN debugging / analyzing and which hardware analyser for observing and creating CAN messages is used there?
I'm interested in brand of hardware and name of PC software for CAN debugging that is used.


Thank you. 

0 Kudos

1,244 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Matja Pichler,

      The PC software is from my CAN analyzer tool, this is the Tool is from china local site.

      Actually, you also can find some other CAN analyzer tool, all the CAN analyzer has it's own PC software.

     Maybe you can use the peak CAN-USB, you can find it from peak official website, it has it's own software.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,244 Views
matijapichler
Contributor I

Greetings kerryzhou,

I had several CAN analyzers that  didn't work correctly, and were a source of problems. I will put  Peak CAN-USB on my list, but if it's not to much off a trouble for you, to look at name/ serial number/ect.. of your CAN analayzer, anything that could lead me to buy online your CAN analyzer. My reasoning is specific options that showed CAN software has, that looks very useful to me.

Thank you!

0 Kudos

1,244 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Matija Pichler,

    You had a lot of CAN analyzers?

    Nothing work? When you use the one of them as a CAN send, another as a CAN receive, the CAN analyzer can receive it? You must test your tool at first, and make sure it works.

   Actually, the PC software is not the important point, it just to help you to check the CAN data, I think if your CAN analyzers can work, it is enough to use.

     Now, if you have more questions, please create a new question post for yourself, because now, your problem is not the same as the post author.

   You can create your own post, then I will give your detail reply for your own problem.

    My CAN analyzer is the China local tool, I don't think you can buy it from your own country.

    So, you can create your post, then we can talk your tool which you already have.

  


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,244 Views
matijapichler
Contributor I

Greetings Kerry Zhou,

Thank you for your time.

0 Kudos

1,244 Views
davidesalvetti
Contributor II

Hi Kerry,

thank you for the answer. I have already tried to copy the CAN sample to the the I2C and both of them work well in the sample. But when I use them into my program I really don't understand why they don't work. 

I have done some other tests and I find that if I try to write something on the Eeprom immediately after I have received a command on the CAN the program stucks like it always does, but if I try to write on the Eeprom for example 5 second after I have received the command on the CAN the I2C doesn't stuck and it works well. May this help you?

Have a great day,

Davide

0 Kudos

1,244 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Davide,

     Now, could you do more testing on your side?

    Use the official sample code to realize your own program function, and test it, after receive the CAN data, then send the I2C data to EEPROM, whether the official sample code also be stuck or not? Do this test just make sure your problem is not caused by other factors which you didn't find.

     Please use the official code, if you can't reflect the problem, then compare your own code with the official code, include clock configuration, module configurations.

     If you can reflect your problem on the official project, please send me that official modified project, I will continue to help you to check it.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,244 Views
davidesalvetti
Contributor II

Hi Kerry,

I can't upload here my project, is it possible to send it to you in private?

Thank you.

Davide.

0 Kudos

1,244 Views
davidesalvetti
Contributor II

Hi Kerry,

thank you for the answer.

I have tried both of your solutions but nothing has changed. If I change the I2C mode to polling mode the I2C stucks at the same way. And nothing works also if I change the position of the CAN initialization.

I have checked the I2C waves with the oscilloscope and the signals are right when the CAN is not initialized but when I try to initialize the CAN the SDA and SCL remains at an high value and nothing works.

I also made a test where I start my system without initializing the CAN and after 10 seconds, into a task, the system automatically initializes the CAN: the interesting thing is that for 10 seconds the signals of the SDA and SCL are right and are continually working, but after the automatic initialization of the CAN the signals stuck on an high level and stop working.

Other ideas?

Davide

0 Kudos

1,244 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Davide Salvetti,

     Thank you for your details!

     I will test it on my side, and checking the root problem, after I get the progress, I will let you know ASAP.

     If you are convenient, you can upload your project, it will save the time to create this project.

    Now, please wait patiently.

    Thanks a lot for your understanding.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,244 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Davide,

   Please try these two ways:

1. Change the I2C mode to polling mode, and try again.

2. Initialize the CAN at first, then initialize the I2C module and try again.

Beside, please check the I2C wave with oscilloscope, and send the wave to me.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos