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.

i2c Problem TMS570LS3137

Other Parts Discussed in Thread: TMDS570LS31HDK, HALCOGEN, ADS1015

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!

  • Hello Leandro,

    I have forwarded your post to one of our I2C experts. They will be replying to your request soon.

  • Hi, I'm still waiting for a response

  • Leandro,

    In the I2C communication with ADS1015, ADS1015 is always a slave and Hercules is always a master. There should be no mode switch during operation. The data format of I2C communication can be seen from page 17 to page 19 of ADS1015 datasheet. Reading from ADS1015 involves two separate I2C transactions: writing to the pointer register and reading from data register. I am attaching some code snip to show what is needed. In this example, I set up the message size so that a stop condition will be automatically generated after the message is sent.

    5148.i2c.zip

    Thanks and regards,

    Zhaohong

  • Hi,

    I'm not trying to mode switch during the operation, what happens is that after sending the first three bytes the i2c config register changes to slave, so I have to put it back to master.

    I already know how to comunicate with adc1015, if you look at my code you'll see that first I'm writing the adc config register, second I'm writing the pointer to convertion register (addr 00) and after that I'm reading the value.

    The problem is that I have to put delays between the sends and between the send and receive in order to get the stop from de microcontroller, otherwise it isnt generated.

  • Hi, there.

    In the communication with ADC, MCU is always an I2c master. It first writes to ADC and then read from ADC. There is no master/slave mode switch.

    Thansk and regards,

    Zhaohong

  • Leandro,

    You need match the count to #of bytes to TX/RX for automatic Stop generation.

    After a stop, Master Bit will be cleared by hw, so you need to set it again, set the count of bytes to RX and issue a start, set stop, wait for start bit and address to TX (Wait for ARDY) then change the mode to receive. When you receive 'count' bytes NAK and stop will be issued for you.

    -Joe