• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » Hercules™ Safety Microcontrollers » Hercules™ Safety Microcontrollers Forum » TMS570LS3137: Read over I2C
Share
Hercules™ Safety Microcontrollers
  • Forum
  • E2E Wiki
Options
  • Subscribe via RSS

TMS570LS3137: Read over I2C

TMS570LS3137: Read over I2C

This question is answered
Daniel Dueringer
Posted by Daniel Dueringer
on Feb 07 2012 08:10 AM
Intellectual365 points

I’m trying to write and read from a Microchip 24AA01 EEPROM over the I2C1 of the TMS570LS3137. I configured the I2C driver with HALCoGen (version 3.00.00) in master mode, address size = 7 bits, count = 8 bits and baud rate = 100 kHz. I had to correct the generated initialization sequence: I2CMDR.BC = 0 instead of 7 and I2CMDR.FDF = 1 (otherwise it doesn’t work) instead of 0. At this time I can write to the EEPROM, but the reading still fails since the second start condition isn’t set correctly. I should set Start Bit - Device Address - Internal Address – Start Bit – Device Address (with read) – Response 0 - … - Response N – Stop Bit, but on the I2C bus I get Start Bit - Device Address - Internal Address– Device Address (with read) – Start Bit – Response 0. My read function is:

// Set the bus in master and transmitter mode and set the START condition

I2C->MDR |= I2C_MASTER | I2C_TRANSMITTER | I2C_START_COND;

// Send the slave address

i2cSendByte(I2C, slaveDeviceAddress);

// Send the internal address

i2cSendByte(I2C, (Uint8)readAddress);

// Set the bus in master, repeat and receiver mode and set the START condition

I2C->MDR &= ~I2C_TRANSMITTER;

I2C->MDR |= I2C_MASTER | I2C_REPEATMODE | I2C_START_COND;

// Send the slave address (for reading)

i2cSendByte(I2C, slaveDeviceAddress | 0x01);

// Receive n-1 bytes

while (readLength > 1)

{

  *readBuffer++ = i2cReceiveByte(I2C);

  readLength--;

}

// Receive the last bytes (and set the STOP condition)

I2C->MDR |= I2C_STOP_COND;

*readBuffer = i2cReceiveByte(I2C);

// Wait until the bus isn't busy and the master mode bit is cleared

while (I2C->STR & I2C_BUSBUSY);

while (I2C->MDR & I2C_MASTER);

Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Sunil Oak
    Posted by Sunil Oak
    on Feb 07 2012 08:41 AM
    Expert8455 points

    Hi Daniel,

    Your question has been forwarded to our I2C expert. We will get back to you as soon as possible.

    Regards, Sunil

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Feb 07 2012 14:49 PM
    Guru14930 points

    Know nothing about the TMS570. My guess is that  you are turning off transmit too early. These lines

    // Set the bus in master, repeat and receiver mode and set the START condition
    I2C->MDR &= ~I2C_TRANSMITTER;
    I2C->MDR |= I2C_MASTER | I2C_REPEATMODE | I2C_START_COND;
    // Send the slave address (for reading)
    i2cSendByte(I2C, slaveDeviceAddress | 0x01);

    should be:

    // Send another start bit.
    I2C->MDR |= I2C_MASTER | I2C_START_COND;
    // Send the slave address (for reading)
    i2cSendByte(I2C, slaveDeviceAddress | 0x01);
    // Switch to receive.
    I2C->MDR &= ~I2C_TRANSMITTER;

    Judging from the data sheet, I don't think I2C_REPEATMODE needs to be used. Also, usually the last byte received is usually not ACKed by the master. I suspect there is another way to code this using I2C APIs without free data format and handle the last ACK.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Daniel Dueringer
    Posted by Daniel Dueringer
    on Feb 08 2012 02:51 AM
    Intellectual365 points

    I already tried your sequence for reading, but doing so I don’t get the second start bit at all! Do you have any I2C example for the TMS570 than the delivered with HALCoGen version 3.00.00 (send and receive done over the internal loopback)?

    TMS570LS HALCoGen
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Feb 08 2012 11:36 AM
    Guru14930 points

    Sorry to hear that did not work. No experience with TMS570 and HalCoGen. I don't see FDF often. Not familiar with it. The I2C controller in the TMS570 looks similiar to controllers in all of TI's ARM processors. I2C code from those processors can be used a reference. I am guessing that  code that uses the non-FDF mode would be something like this:

    /* Assumes I2CMDR.RM =0 and I2CMDR.FDF = 0 */
    I2C->SAR  = slaveDeviceAddress>>1;// 7-bit address
    I2C->MDR |= I2C_MASTER;

    I2C->CNT  = 1;
    I2C->DXR  = (Uint8)readAddress;
    I2C->MDR |= I2C_TRANSMITTER | I2C_START_COND;
    while (I2C->STR & I2C_BUSBUSY);

    I2C->CNT  = readLength;
    I2C->MDR &= ~I2C_TRANSMITTER;
    I2C->MDR |= I2C_START_COND | I2C_STOP_COND;

    while(readLength)
    {
      while (I2C->STR & I2C_RXRDY);
      *readBuffer++ = I2C->DRR;
      readLength--;
    }

    while (I2C->STR & I2C_BUSBUSY);
    while (I2C->MDR & I2C_MASTER);

    The I2C state machine automatically handles the start/address and stop parts.

    That's all I got. Hopefully Sunil Oak's I2C expert will respond soon.

    EDIT: Forgot to convert 8-bit address to 7 bit-address

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Pratip Kumar
    Posted by Pratip Kumar
    on Feb 09 2012 07:43 AM
    Intellectual2255 points

    Daniel,

    I'm preparing a sample I2C data transfer code for TMS570 . Hope it will help.

    - Pratip

    I2C TMS570
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Pratip Kumar
    Posted by Pratip Kumar
    on Feb 09 2012 11:00 AM
    Suggested Answer
    Intellectual2255 points

    Hi Daniel,

    I had a look into your case where you are trying to write and read from Microchip 24AA01 EEPROM.

    Looks like you need not have to be in FDF mode to communicate with it , you can try with repeat mode ON and set appropriate Salve Address if you need the following format both for write and read operations:

    Start Bit - Device Address - Internal Address – Start Bit – Device Address (with read) – Response 0 - … - Response N – Stop Bit,

    i2cREG1->SAR = sadd;

    i2cREG1->MDR |= RepeatMode

    You can keep the I2CMDR.BC  = 0 and I2CMDR.FDF = 0 . By the way Halcogen doesn't support FDF format at the moment.

    This should generate a start bit for each byte of data transfer.

    if I'm refering the right datasheet from microchip the slave address needs to be

    (Edit:) 0xA0   (i.e) 1010XXX

    Do give this a shot and let me  know how it moves.

    I apologise if there has been much of a delay from us to give you any help.

    - Pratip

     

     

     

    I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Daniel Dueringer
    Posted by Daniel Dueringer
    on Feb 10 2012 04:16 AM
    Intellectual365 points

    Hi Pratip

     The slave address of the EEPROM is 0xA0 [from Microchip 24A001 data sheet]:

    I have already tried with FDF = 0, RM = 0 and RM = 1, but I had no success with both combinations L

    I can successfully write in the EEPROM (the EEPROM acknowledges my commands and data), but only with FDF = 1, RM = 0 and BC = 0.

    The EEPROM is the only device on the I2C bus.

    I also noticed that the bus frequency is set incorrectly by HALCoGen. I would like to have a bus speed of 100 kHz:
    - HALCoGen sets PSC = 9 and CLKH = CLKL = 0x1E => 113.6 kHz
    - I calculated PSC = 9 and CLKH = CLKL = 0x23 => 100 kHz

    - Daniel

    HALCoGen I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Pratip Kumar
    Posted by Pratip Kumar
    on Feb 10 2012 09:32 AM
    Intellectual2255 points

    Daniel,

    Yes the slave add is 0xA0 .Since the slave expects a start condition on each byte I expect the RM to be ON.

    Let me have a closer look.

    - Pratip

    I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Pratip Kumar
    Posted by Pratip Kumar
    on Feb 11 2012 07:07 AM
    Verified Answer
    Verified by Daniel Dueringer
    Intellectual2255 points

    Daniel,

    1. In the FDF , direction cannot be changed throught out that transfer. If FDF works for you , could you try with few consecutive writes followed by consecutive  reads.

    2. While using RM , my concern is the way we switch from write to read  , refer the link  I2C Tips .

    3. I guess you could also try with RM=0 and try sending one word at a time by setting STT each time

     and set the I2CCNT : i2cREG1->CNT = cnt;

    See if the attached file helps.4747.i2c.c

    Once I have my hardware up , I can send you some verified sample codes.

    I''ll be looking forward for your observations !!!!

    - Pratip

    I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Pratip Kumar
    Posted by Pratip Kumar
    on Feb 16 2012 09:50 AM
    Intellectual2255 points

    Hi Daniel,

    Were you able to read from  the EEPROM ?

    - Pratip

    I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Pratip Kumar
    Posted by Pratip Kumar
    on Feb 17 2012 03:55 AM
    Intellectual2255 points

    Hi Daniel,

    Try with the attached file and see if it helps. I'll close on this ticket , you may raise a new one if you need further help.

    7635.i2c.zip

    -Pratip

    I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Daniel Dueringer
    Posted by Daniel Dueringer
    on Feb 22 2012 03:21 AM
    Intellectual365 points

    Pratip

     I’m back from vacation ;-)

     With the I2C Tips <http://processors.wiki.ti.com/index.php/I2C_Tips> I could solve the problems with the I2C! I have configured the I2C with RM=0, FDF=0 and SAR=0x50 (=0xA0>>1).

     I have seen that you are using HALCoGen version 03.01.00, I still have version 03.00.00! Is the newer version already available, or when will it be?

    Thanks Daniel

    HALCoGen I2C
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Brian Fortman
    Posted by Brian Fortman
    on Feb 22 2012 15:33 PM
    Expert5255 points

    Daniel,

    I'm glad that the I2C tips page helped solve your issue!  HALCoGen 3.01 is a TI internal release.  The next HALCoGen update will happen 1H2012.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Simon lapointe
    Posted by Simon lapointe
    on Mar 06 2012 15:48 PM
    Intellectual820 points

    I would like to know what is the purpose of the SAR register if, anyway, we have to send it in each message:

    «

    ...

    // Send the slave address

    i2cSendByte(I2C, slaveDeviceAddress);   

    ... 

    » 

    What it is handled exactly by the i2c controller? The ACK? The slave address?

    I have generated the Halcogen code, it`s fine but I still don't know how to use it. It doesn't work.

    I communicate as a Master to a single slave (light transmitter ISL76683 from TI). Do you have some example? (Other than from Halcogen).

    Simon 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Mar 07 2012 11:01 AM
    Guru14930 points

    Hmmm...no response from the TI guys.  Some guesses. The SAR is not used when the controller is in Free Data Format mode. In that mode you must manage the entire transaction. In the non FDF mode, SAR is used by I2C controller to automatically send the start bit, slave address and read/write bit automatically.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
12
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use