Hi!
I am working on an electronic drum as a final school project and we are using the TMS320C6720. Right now , i am working on the I2C and i have a problem. Whenever i begin a transmission, i always get a dummy byte sent first (0x00) even though i set the first byte to be 0x40 ( write address of the I/O expander).For example if i want to send 0x40(Addr), 0x06 (command), 0x0F and 0x00 (datas), on the oscilloscope, i get 0x00 , 0x40 ,0x06,0x0f and 0x00.
I tried to set the address to sent before going out of reset mode (I2CMDR.IRS) and after, i still get the same thing. A little bit of spec on the I2C setup : Master transmitter mode, non-repeat mode , not extended adress. I've followed the diagram in the datasheet for the master transmitter in non repeat mode. The slave address device is set to 0x40 and whatever i do, i always get a dummy byte of 0x00. Is it supposed to be that way? Or am i missing something in the datasheet (it may be the case, my native language is french).
Here's my code in it's form right now. It is disorganised because i test/tested a lot of possible error still to no avail.
I'll seperate what function is in what file.
We use only one slave device so the slave adress is hard coded
IOExp.c : My I/O expander functions
unsigned char ucIOWrite (unsigned char ucCommand,unsigned char ucData1, unsigned char ucData2)
{
unsigned char i;
i2c1->i2cmdr.IRS = 0; //to be sure its in reset state, test only purpose
while (uiI2CCheckBusy()); // I2C bus is free?
while (i2c1->i2cmdr.MST);
while (!(i2c1->i2cstr.ICXRDY)); //data ready to be written?
vI2CSetTxBuff(ADDR_WR); //ADDR_WR = 0x40
vI2CSetDataCount(4); // Address + Command + 2 data
vI2CStart(); //generate start condition
for (i=0;i<3;i++)
{
while (!(i2c1->i2cstr.ICXRDY || i2c1->i2cstr.ARDY));
if (i2c1->i2cstr.NACK) // NACK error
{
i2c1->i2cmdr.STP = 1; // stop transmission
i2c1->i2cstr.NACK = 0; // reset NACK
return (2); // return NACK error
}
vI2CSetTxBuff(ucTab[i]); // no error
} //lsend data
return 0; //no error
}
I2CFunc.c : I2C general functions( i'll post only pertinent ones)
void vInitI2C (void)
{
i2c1->i2cmdr.MST = 1; // Master mode
i2c1->i2cmdr.TRX = 1; // Transmitter mode
i2c1->i2cmdr.RM = 0; // Non Repeat Mode
i2c1->i2cmdr.DLB = 1; // Digital Loopback on
i2c1->i2cmdr.BC=0; // 8 bits data format
i2c1->i2cmdr.XA = 0; // 7 bit address format
i2c1->i2cmdr.IRS = 1; // I2C enabled out of reset
}
//***********************************************
unsigned int uiI2CCheckBusy (void)
{
return (i2c1->i2cstr.BB);
}
//***********************************************
void vI2CStart (void)
{
i2c1->i2cmdr.STT = 1;
}
/************************************************
void vI2CSetTxBuff (unsigned char ucData)
{
i2c1->i2cdxr.D = ucData;
}
//***********************************************
void vI2CSetDataCount (unsigned int uiCount)
{
i2c1->i2ccnt.ICDC = uiCount;
}
//**********************************************
Main.c : where i made my test loop
{
unsigned char ucErreur=0;
while (1)
ucErreur = ucIOWrite (CONFIG,0x0F,0x00);
}
I made a structure of structure pointing on the I2C1 registers (base adress of 0x4A000000)
struct I2C *i2c1 = (struct I2C*)0x4A000000;
Like i said, i can generate a transmission but i always get a dummy byte of 0x00 before the first byte i sent. The code written here is the last test i made, so it possibly have an error but i can't point it out so any help on solving my problem would be great! Thanks!