[an error occurred while processing this directive]
|
void I2C_setup(I2C_Setup *pSetup)
{
ASSERT( (pSetup->rate >= 10) && (pSetup->rate <= 400));
// I2C_I2CMDR_RMK(free, stt, idleen, stp, mst, trx, xa, rm, dlb, irs, stb, fdf, bc)
UINT nSetup = I2C_I2CMDR_RMK(pSetup->free, 0, 0, 0, 1, 1, pSetup->addrmode,0,pSetup->dlb,0, 0, 0, pSetup->bitbyte);
I2C_FSET(I2CMDR, IRS, 0); // !!! reset module
// IRS must be 0 while you configure/reconfigure the I2C module. Forcing IRS
// to 0 can be used to save power and to clear error conditions. spru146a.pdf p.19
I2C_RSET(I2CMDR, nSetup);
// set own address (if master don't care)
I2C_RSET(I2COAR, pSetup->ownaddr);
// calculating properly clocking see spru146a.pdf p.5,6
// calculating IPSC
// module_clock = dsp_clock/(IPSC+1)
// I want module_clock = 10 MHz always (must be in range 7-12MHz)
UINT ipsc_val = pSetup->sysinclock / 10 - 1;
I2C_RSET(I2CPSC, ipsc_val);
// calculating the ICCLKL and ICCLKH register values
// bit_rate = module_clock / [ (ICCL+d)+ (ICCH+d) ] spru146a p.6
// parameter d depends on IPSC
UINT d_val;
switch (ipsc_val)
{
case 0:
d_val = 7;
break;
case 1:
d_val = 6;
break;
default:
d_val = 5;
}
UINT iccl_val = (10000/2/pSetup->rate) - d_val;
I2C_RSET(I2CCLKL, iccl_val);
I2C_RSET(I2CCLKH, iccl_val);
I2C_FSET(I2CMDR, IRS, 1); // reset out
}