This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM3359 - I2C slave code is not working.

Hi,

I am trying to create a I2C slave device using TI's AM335x board(only reception required. I am using polling method for receiving data.

I followed the data sheets to write the code. I am using I2C2.

//Enable I2C2 clock register.
HWREG(SOC_CM_PER_REGS + CM_PER_I2C2_CLKCTRL) |=CM_PER_I2C2_CLKCTRL_MODULEMODE_ENABLE;

//Configure i2c2 pinmux
HWREG(0x44E10000+0x978 )=0X03;
HWREG(0x44E10000+0x97C )=0X03;

//Reset I2C
HWREG(SOC_I2C_2_REGS + I2C_CON) &= ~(I2C_CON_I2C_EN); // Disable
HWREG(SOC_I2C_2_REGS + I2C_SYSC) |= I2C_SYSC_SRST; // reset
HWREG(SOC_I2C_2_REGS + I2C_SYSC) &= ~I2C_SYSC_AUTOIDLE;// Autoidle disable

//12Mhz i2c module clock.
//I2C_PSC = x - Obtained from system clock frequency.
//System runs at 600MHz.
//I2C_PSC= 600/12=50


HWREG(SOC_I2C_2_REGS+I2C_PSC) = 50;


//Program I2C clock obtain 100KBps or 400Kbps(SCLL AND SCLH) - ONLY FOR MASTER so not required
//HWREG(SOC_I2C_2_REGS+I2C_SCLL) = x;
//HWREG(SOC_I2C_2_REGS+I2C_SCLH) = x;

//Configure it's own address
//I2C_OS
HWREG(SOC_I2C_2_REGS+I2C_OA) = 0x50;
HWREG(SOC_I2C_2_REGS+I2C_SBLOCK) = 0X01;

//clear transmit and receive fifo
HWREG(SOC_I2C_2_REGS+I2C_BUF) = 0X4040;

//clear any pending interrupt status
HWREG(SOC_I2C_2_REGS+I2C_IRQSTATUS_RAW) = HWREG(SOC_I2C_2_REGS+I2C_IRQSTATUS_RAW);

HWREG(SOC_I2C_2_REGS + I2C_SYSC) = I2C_SYSC_AUTOIDLE|I2C_SYSC_CLKACTIVITY; // reset


//Release I2C reset - I2CCON:I2C_EN =1
//CONFIGURE I2C mode register I2C_CON slave I2C_CON_MST=0 slave mode
HWREG(SOC_I2C_2_REGS+I2C_CON) = I2C_CON_I2C_EN;

//Enable interrupt mask I2C_IRQENABLE_SET
//Try polling 


//ENABLE DMA If required
//#todo


while(1)
{
tmp = HWREG(SOC_I2C_2_REGS+I2C_IRQSTATUS_RAW);
if(tmp & 0x08)
{
data = HWREG(SOC_I2C_2_REGS+I2C_DATA);
HWREG(SOC_I2C_2_REGS+I2C_IRQSTATUS_RAW) = HWREG(SOC_I2C_2_REGS+I2C_IRQSTATUS_RAW);
}

}