AnsweredAssumed Answered

I2C Peripheral Control

Question asked by yilmaz.orhan on Dec 1, 2014
Latest reply on Dec 3, 2014 by Erwan Y
Hello,

I trying use the I2C periph. But, It is not work. Have you a I2C referance manual ? or What should I do?
My Example code :
void I2C_initial(void)
{
/*
*   Note: Clk is startup enabled.
*  for Ex:
*              ME.RUNPC[1].R = 0x00000010;//.B.RUN0 = 1;//
*
*       ME.PCTL[44].R = 0x01;           //I2C0          - RunPC[1]
*              //Mode Transition to Enter RUN0 MODE
*       ME.MCTL.R = (0x40000000|KEY);//RUN0 MODE & KEY
*       ME.MCTL.R = (0x40000000|INVERT_KEY);//RUN0 MODE
*
*       //Check Configurations
*       while(ME.GS.B.MTRANS);//Global Status Register wait for mode transition to complete
*
*       while(ME.GS.B.CURRENTMODE != 4);//Global Status Register verify RUN0 Current mode
*
*/
////////////////////////////////////////////////////////////////
// I2C Pads
////////////////////////////////////////////////////////////////
        //CLK
        //SIU.PCR[PA11].R       = 0x0800;       //I2C SCL
        SIU.PCR[PB3].R      = 0x0800;       //I2C SCL
 
        //DATA
        //SIU.PCR[PA10].R       = 0x0800;       //I2C SDA
        SIU.PCR[PB2].R      = 0x0800;       //I2C SDA
 
        //SDA Select
        //SIU.PSMI[30].B.PADSEL = 0; //for PA10
        SIU.PSMI[30].B.PADSEL = 1; //for PB2
 
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
 
I2C_0.IBAD.B.ADR = 0x02;//Address = 0x01
    /*
     * IBC7-6 - MUL
     * -------------
     * 00 -> 1
     * 01 -> 2
     * 10 -> 4
     * 11-Reserved
     *
     * IBC5-3   scl2start   scl2stop    scl2tap     tap2tap
     * ---------------------------------------------------------
     * 000      2           7           4           1
     * 001      2           7           4           2
     * 010      2           9           6           4
     * 011      6           9           6           8
     * 100      14          17          14          16
     * 101      30          33          30          32
     * 110      62          65          62          64
     * 111      126         129         126         128
     *
     * IBC2-0   SCL_Tap     SDA_Tap
     * ------------------------------------
     * 000      5           1
     * 001      6           1
     * 010      7           2
     * 011      8           2
     * 100      9           3
     * 101      10          3
     * 110      12          4
     * 111      15          4
     *
     * RM0017 pdf(page 355-357) for more
     */
    I2C_0.IBFD.B.IBC = 0;
 
    I2C_0.IBCR.B.MDIS = 0; //Module Enable
    I2C_0.IBCR.B.IBIE = 0; //Bus Interrupt Disabled
    I2C_0.IBCR.B.MS = 1; //Master mode
    I2C_0.IBCR.B.RSTA = 1; //Generate repeat start cycle
////////
}
 
//
void I2C_Write(U_8 data)
{
    I2C_0.IBSR.B.IBIF = 1;//Flag Clear
    I2C_0.IBCR.B.MS = 1; //Master mode
    I2C_0.IBCR.B.TX = 1;
    I2C_0.IBDR.B.DATA = data; //( Page: 360 )
    I2C_0.IBCR.B.RSTA = 1;
}

Outcomes