AnsweredAssumed Answered

Help with MC9S12DT256 IIC

Question asked by Simon X on Sep 5, 2014
Latest reply on Sep 8, 2014 by Daniel Lundin

I am using a MC9S12DT256 microprocessor. I need to communicate with a chip using IIC. The code that I have I believe was written by looking at online samples. It seems very simmilar to others I have seen online. Once the "EnableInterupts" command has ben run, the IIC function crashes the program. Using Codewarrior, in the True Time Simulator & Debugger, when it crashes, no code is highlighted in the "Source" window and if single stepped, it runs Assembly code line by line in the "Assembly" window. If I remove "EnableInterupts" from the program, it runs without crashing. I have verified with an oscilloscope that the correct waveform is being transmitted over the IIC but the instructions are still not getting through. Does anyone know why “EnableInterupts” which is in Codewarrior by default, is crashing my program? Below is my code for the IIC function.

 

void IIC_writeByte(unsigned char device__address, unsigned char registeraddress, unsigned char data)

{   

    int temp;

    IBCR_MS_SL=1;        //Generate start signal

    IBCR_TX_RX=1;           

    temp=device__address<<1;

    IBDR=temp;           //Device address shifted left one position & LSB=0

    while(!IBSR_IBIF);   //Wait untill IBIF is HIGH

    IBSR_IBIF=1;         //Clear interrupt event flag

    //while(IBSR_RXAK);  //Check for acknowledge from device

    IBDR=registeraddress;

    while(!IBSR_IBIF);   //Wait untill IBIF is HIGH

    IBSR_IBIF=1;         //Clear interrupt event flag

    //while(IBSR_RXAK);  //Check for acknowledge from device

    IBDR=data;             

    while(!IBSR_IBIF);   //Wait untill IBIF is HIGH

    IBSR_IBIF=1;         //Clear interrupt event flag

    //while(IBSR_RXAK);  //Check for acknowledge from device

    IBCR_MS_SL=0;        //Generate stop signal

    delay_50us(1);

}

Outcomes