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.

CCS/TMS570LS1227: Reading TMP468 temperature sensor via I2C

Part Number: TMS570LS1227
Other Parts Discussed in Thread: HALCOGEN, TMP468

Tool/software: Code Composer Studio

Hello,

I'm brand new to i2c and have an idea of what's required to read from a slave device using a master, however I am struggling to successfully code my pseudocode.

I'm wanting to read the local temperature sensor on the TI TMP468 using the TMS50ls1227PGE's i2c bus. I've enabled the i2c driver, pinmux, and enabled all of the i2c interrupts in HalCoGen. 

In CCS, I've typed the following code within a FreeRTOS task (I did i2cInit() in main): 

/* Set direction to receiver */
               i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
               i2cSetMode(i2cREG1, I2C_MASTER);
               i2cSetSlaveAdd(i2cREG1, 0b1001000);

               i2cSetStart(i2cREG1); //start bit
               i2cSendByte(i2cREG1, 0b10010000); //write to address 1001000, the address of the temperature sensor
               i2cSendByte(i2cREG1, 0b00000000); //the internal temperature sensor is at register 0 

               i2cSetStart(i2cREG1); // resend the start bit
               i2cSendByte(i2cREG1, 0b10010001); //read from device 1001000

               while(i2cIsRxReady(i2cREG1)){}; //wait until clear 
               i2cSetDirection(i2cREG1, I2C_RECEIVER); //set i2c to receive data

               data = i2cReceiveByte(i2cREG1); //receive byte from register

               i2cSetStop(i2cREG1); //send stop bit

I'm not seeing any activity in my data variable and when I debug my code is always stuck inside of i2cSendByte at the "while ((i2c->STR & (uint32)I2C_TX_INT) == 0U)"

I'm not really sure where to go from here, any ideas or obvious mistakes?

Thank you!

  • Ben,

    Did you configure the I/O multiplexing to allow I2C signals to be output on the assigned terminals? I2C is not the default function on the assigned terminals and the I/O Multiplexing Module (IOMM) needs to be configured to select I2C signals to be output.
  • Hello Sunil,

    Yes, I've enabled the i2c pinmux using halcogen. As for the i2c interrupts, I'm not sure which ones I need to enable. Is there documentation somewhere that covers that?

    I also updated my code, where Slave_Address = 0b100100, Slave_Word_Address = 0x0, DATA_COUNT = 1, and Receive_data_setup = 0x1.

    Please see below

    /* wait until MST bit gets cleared, this takes
             * few cycles after Bus Busy is cleared */
            //while(i2cIsMasterReady(i2cREG1) != true);
    
            /* Configure address of Slave to talk to */
            i2cSetSlaveAdd(i2cREG1, Slave_Address);
    
            /* Set direction to Transmitter */
            /* Note: Optional - It is done in Init */
            i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
    
            /* Configure Data count */
            /* Slave address + Word address write operation before reading */
            i2cSetCount(i2cREG1, Receive_data_setup);
    
            /* Set mode as Master */
            i2cSetMode(i2cREG1, I2C_MASTER);
    
            /* Set Stop after programmed Count */
            i2cSetStop(i2cREG1);
    
            /* Transmit Start Condition */
            i2cSetStart(i2cREG1);
    
            /* Send the Word Address */
            i2cSendByte(i2cREG1, Slave_Word_address);
    
            /* Wait until Bus Busy is cleared */
            while(i2cIsBusBusy(i2cREG1) == true);
    
            /* Wait until Stop is detected */
            while(i2cIsStopDetected(i2cREG1) == 0);
    
            /* Clear the Stop condition */
            i2cClearSCD(i2cREG1);
    
            /*****************************************/
            //// Start receving the data From Slave
            /*****************************************/
    
            /* wait until MST bit gets cleared, this takes
             * few cycles after Bus Busy is cleared */
            while(i2cIsMasterReady(i2cREG1) != true);
    
            /* Configure address of Slave to talk to */
            i2cSetSlaveAdd(i2cREG1, Slave_Address);
    
            /* Set direction to receiver */
            i2cSetDirection(i2cREG1, I2C_RECEIVER);
    
            /* Configure Data count */
            /* Note: Optional - It is done in Init, unless user want to change */
            i2cSetCount(i2cREG1, DATA_COUNT);
    
            /* Set mode as Master */
            i2cSetMode(i2cREG1, I2C_MASTER);
    
            /* Set Stop after programmed Count */
            i2cSetStop(i2cREG1);
    
            /* Transmit Start Condition */
            i2cSetStart(i2cREG1);
    
            /* Tranmit DATA_COUNT number of data in Polling mode */
            i2cReceive(i2cREG1, DATA_COUNT, RX_Data_Master);
    
            /* Wait until Bus Busy is cleared */
            while(i2cIsBusBusy(i2cREG1) == true);
    
            /* Wait until Stop is detected */
            while(i2cIsStopDetected(i2cREG1) == 0);
    
            /* Clear the Stop condition */
            i2cClearSCD(i2cREG1);
    
            asm(" nop");
            asm(" nop");
            asm(" nop");
    
            while(1);

    This code always hangs inside of "i2cInterrupt()" so I think I have messed up my i2c interrupts in halcogen. I currently have all of them selected. For my use case, is that correct?

  • Hi Ben,

    Just read the TMP468 datasheet, the TMP468 registers can be accessed with block or single register reads. Pointer values 00h to 08h are for single register reads. The data_count = 1 is ok for pointer=0x00 (Slave_Word_Address).

    1. start, then slave address, write bit (transmit). ACK

    2. write data: Pointer byte. ACK

    3. repeat start, the slave address, read bit (receiver). ACK

    4. read data byte 1 from sensor. NAK

    5. STOP

    You don't follow this sequence. There is no STOP between step and step 3. You need to enable repeat mode.