About writing and reading EEPROM with I2C interface and interrupt priority

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

About writing and reading EEPROM with I2C interface and interrupt priority

978 Views
wuxuliang
Contributor II

Hello:

Recently I encountered a problem with writing and reading EEPROM with I2C interface, the code as following:

HW_init();

    

    LC024T_write(0xC8);

   

//Line A

if(make_sel)

{

    while(1)

    {    

     delay(1000);

    

     u8_read_i2c = LC024T_first_read();

    

     delay(1000);   

    }

}

else

{

delay(1000);    

    u8_read_i2c = LC024T_first_read();

}

    

        

//Line B

ResetADC();

delay(100);

Reset_LTC2986();   

   delay(250);

 

configure_global_parameters(0);

configure_global_parameters(1);

 

if  make_sel  set to 1, that means the code after Line B wont be compiled or executed, the writing and reading eeprom with I2C interface are correct under this circumstance. Imake_sel  set to 0, loading the ram.elf file fail. According to the description above, it seems that the code of writing and reading eeprom with I2C interface are incompatible to the code after Line B, which is related to SPI operation.(Since delete the code between Line A and Line B, ram.elf load correct and software execute correct). The attachment is my project files. Codewarrior version is 2.10 and MCU is MPC5605B.

 

 

The other problem about this project is interrupt priority issue. There are four serial ports in this project, the com1, com3, com4 send data in PIT3_isr, and all four ports receive data in their own receive interrupt function respectively(UART0UART3 correspond to COM1~COM4). My purpose is that the com2 receive ISRs priority should be higher than PIT3_isr, but the fact is that PIT3_isr’priority is higher than com2 receive ISRs priority even though I set priority 15 to com2(UART1_Receive_ISR), the ISR initialization code as following:

INTC_InstallINTCInterruptHandler(PIT3_isr, 127, 3);

    INTC_InstallINTCInterruptHandler(UART0_Receive_ISR, 79, 4);

    INTC_InstallINTCInterruptHandler(UART1_Receive_ISR, 99, 15);

    INTC_InstallINTCInterruptHandler(UART3_Receive_ISR, 122, 13);

The PIT3_isr’s interrupt priority is higher than com2s interrupt priority leads to the fact that the UART1_Receive_ISR function wont response the message comes from PC through serial port every time(70% message will be responsed). And that is unacceptable. 

Appreciate for helping, thanks! 

 

 

Original Attachment has been moved to: Project_1.zip

Tags (1)
0 Kudos
Reply
2 Replies

754 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

your code cannot be compiled because there missing identifiers declarations such as BOOL or FALSE and some other. Please check the figure below. Could you please provide me project, which I can compile on my side?

pastedImage_1.png

Regards,

Martin

0 Kudos
Reply

754 Views
wuxuliang
Contributor II

Hello ,Martin:

     Thanks for your reply, I checked my project and find the reason my project cannot be compiled successfully on your computer. In my project ,the definitions of BOOL and TRUE and so on are defined in cstdint.h, which is not in my own project but in codewarrios's installation file folders. The attachment project has been modified and should work on your computer. The pic below shows the location of some definitions in my project before.

typedefine.jpg 

By the way, the problem of interrupt priority has been solved after I searched some solutions in this community. By setting the 

INTC_NESTED_INTERRUPT from 0 to 1.

#ifndef INTC_NESTED_INTERRUPT
#define INTC_NESTED_INTERRUPT 1
#endif

But the other problem of writing and reading EEPROM with I2C interface still unsolved. The code of writing and reading EEPROM with I2C interface is still incompatible with the code of SPI. But I found another strange thing that when the software load the ram.elf incorrectly, the software will stop at one line below.

.align SIXTEEN_BYTES
IVOR0trap: b IVOR0trap // IVOR 0 interrupt handler

.align SIXTEEN_BYTES
IVOR1trap: b IVOR1trap // IVOR 1 interrupt handler

.align SIXTEEN_BYTES
IVOR2trap: b IVOR2trap // IVOR 2 interrupt handler

.align SIXTEEN_BYTES
IVOR3trap: b IVOR3trap // IVOR 3 interrupt handler

.align SIXTEEN_BYTES
IVOR4trap: b INTC_INTCInterruptHandler // External Interrupt

.align SIXTEEN_BYTES
IVOR5trap: b IVOR5trap // IVOR 5 interrupt handler

.align SIXTEEN_BYTES
IVOR6trap: b IVOR6trap // IVOR 6 interrupt handler

.align SIXTEEN_BYTES
IVOR7trap: b IVOR7trap // IVOR 7 interrupt handler

.align SIXTEEN_BYTES
IVOR8trap: b IVOR8trap // IVOR 8 interrupt handler

so I guess maybe there are some collision between I2C and interrupt resources, after I disabled the one of lines below ,software works.I don't know why.

INTC_InstallINTCInterruptHandler(PIT3_isr, 127, 3);
INTC_InstallINTCInterruptHandler(UART0_Receive_ISR, 79, 4);//100ms
INTC_InstallINTCInterruptHandler(UART1_Receive_ISR, 99, 15);

In conclusion, the project in attachment will work under any one circumstances below:

1. Either writing or reading EEPROM with I2C code ,  not both.

2. Writing and reading EEPROM with I2C code,   but not the code related to SPI.

3. Writing and reading EEPROM with I2C code,   and the code related to SPI. but disable the one or more interrupt of  PIT3_isr, UART0_Receive_ISR and UART1_Receive_ISR.

But that's not what I expected, I need all the interrputs , reading and writing EEPROM with I2C , and some SPI operation work together.

Regards,

Xuliang Wu

0 Kudos
Reply