Hi,
I'm using TMDS570LS31HDK board, Halcogen 03.08.01 and Code Composer Studio.
I'm trying to read and write ads1015 from TI but I'm having problems with i2c comunication.
First of all I've noticed that init function inside i2c.c file has a problem bringing out of reset the module, it is done before writing some of the configuration registers. I've modified the code so the bring out of reset is done after writing the configuration registers. I don´t have any more troubles there.
What I need to do is:
1) Send write command to ads1015, write three bytes.
2) Send write command and write one byte
3) Receive two bytes from ads1015
To do 1) the code is:
i2cInit();
i2cSetSlaveAdd(i2cREG1, 0x48);
//Config
i2cREG1 -> MDR |= I2C_TRANSMITTER;
i2cSetCount(i2cREG1, 3);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1, 0x01);
i2cSendByte(i2cREG1, 0xc1);
i2cSendByte(i2cREG1, 0x83);
This is working correctly, I get the ACK and the stop bit after the third SendByte.
After this the module goes to slave, don't know why, so I set it back to master using the SetMode function, why does it happen?
So, the code for 2) and 3) is:
// 2) write
i2cSetMode(i2cREG1,I2C_MASTER);
i2cSetCount(i2cREG1,1);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1, 0x00);
// 3) read
i2cSetCount(i2cREG1,2);
i2cREG1 -> MDR &= ~I2C_TRANSMITTER;
i2cSetStart(i2cREG1);
a=i2cReceiveByte(i2cREG1);
b=i2cReceiveByte(i2cREG1);
What I get is a start bit+addr+read - ACK - BYTE - ACK - BYTE - NACK two times, after that SCL remains low and SDA remains High, no stop bit.
If I comment the code after "// 3) read" I get start bit+addr+write - ACK - 0X00 - ACK - STOP, wich is correct.
If I leave the code after "// 3) read" uncommented and try to send a second 0x00 after the first, like this:
// 2) write
i2cSetMode(i2cREG1,I2C_MASTER);
i2cSetCount(i2cREG1,1);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1, 0x00);
i2cSendByte(i2cREG1, 0x00);
// 3) read
i2cSetCount(i2cREG1,2);
i2cREG1 -> MDR &= ~I2C_TRANSMITTER;
i2cSetStart(i2cREG1);
a=i2cReceiveByte(i2cREG1);
b=i2cReceiveByte(i2cREG1);
I get: start bit+addr+write - ACK - 0x00 - ACK - start bit+addr+read - ACK - BYTE - ACK - BYTE - NACK - STOP, so Im missing stop bit after the write.
I've debugged the program paying attention to MDR and STR registers, but cant find anything helpfull.
Can you help me? Thanks!