• 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 » MSP430™ Microcontrollers » MSP430 Ultra-Low Power 16-bit Microcontroller Forum » i2c slave program
Share
MSP430™ Microcontrollers
  • Forum
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
MSP430 Resources
  • MSP430 Product Folder
  • MSP-EXP430G2 - MSP430 LaunchPad Value Line Development kit
  • MSP430 Getting Started Guide
  • MSP430 Microcontroller Projects
  • More Resources >
  • i2c slave program

    i2c slave program

    This question has suggested answer(s)
    Shimonshami
    Posted by Shimonshami
    on Aug 20 2012 02:32 AM
    Prodigy70 points

    Hi All,

     

    I’m new on the following system.

    I’m working with the CC430F6137IRGC on the eZ430 watch with the IAR program IAR for MSP430.

    I’m looking for a Slave i2C program for the above uP.

    To read the sent data to it through J.2 and the J.3 (SDA and SCL) ports.

    Hope to get a good sample for it.

     

    Thanks,

    Shimon

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Leo Hendrawan
      Posted by Leo Hendrawan
      on Aug 20 2012 04:44 AM
      Suggested Answer
      Mastermind28725 points

      Hi,

      the example code of CC430F6137 should have some example code for I2C slave:

      http://www.ti.com/litv/zip/slac279b

      It might not be the one exactly matching your requirement working at PJ.2 and PJ.3, but this should at least help you for starting.

      Regards,

      Leo Hendrawan

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimonshami
      Posted by Shimonshami
      on Aug 20 2012 09:29 AM
      Prodigy70 points

      Hi Leo,

       

      First: Thanks a lot for the link.

      Second: Can you please show me how to change it from P2.6 and P2.7 (on the slave) to PJ.2 and PJ.3?

       

      Thanks,

      Shimon.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Leo Hendrawan
      Posted by Leo Hendrawan
      on Aug 20 2012 09:34 AM
      Mastermind28725 points

      Hi,

      sorry but i think i miss something here. It is not possible to use the hardware USCI I2C with Port J. You can take any pin from P1 - P3, and you can use the Port Mapping Controller to map the I2C input output to the selected pin.

      Regards,

      Leo Hendrawan

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimonshami
      Posted by Shimonshami
      on Aug 21 2012 01:18 AM
      Prodigy70 points

      Hi Leo,

      Thanks for your reply answer.

      The Hw that I’m using is with the following ports i.e. J.2 and J.3.

      I can’t use other ports now beside the above (J.2 and J.3.) is there another way to send/receive i2c information (slave!!!) by/with those ports?

      I’m really stuck…

       

      Shimon.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Leo Hendrawan
      Posted by Leo Hendrawan
      on Aug 21 2012 02:31 AM
      Suggested Answer
      Mastermind28725 points

      Hi Shimon,

      Shimonshami

      The Hw that I’m using is with the following ports i.e. J.2 and J.3.

      I can’t use other ports now beside the above (J.2 and J.3.) is there another way to send/receive i2c information (slave!!!) by/with those ports?

      You can try to implement software I2C (bit banging). however this is of course not so efficient since the CPU will occupied to bit bang the I2C signals everytime you want to send something via I2C. Try to google for "I2C bit banging", i am pretty sure you will get many detailed information out there.

      Regards,

      Leo Hendrawan

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimon Shamsiyan
      Posted by Shimon Shamsiyan
      on Oct 17 2012 10:24 AM
      Intellectual520 points

      Hi leo,

       

      I’ve changed the Hw ports to P1.6 as the SDA and P1.7 as the SCL as you’ve told me.

      How can I use the: cc430x613x_uscib0_i2c_05.c program that was on the examples that you’ve sent?

       

      Thanks,

      Shimon.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Leo Hendrawan
      Posted by Leo Hendrawan
      on Oct 17 2012 10:37 AM
      Mastermind28725 points

      Shimon,

      you can edit the code which uses the port mapping controller to setup the pins like this:

      PMAPPWD = 0x02D52; // Get write-access to port mapping regs
      P1MAP6 = PM_UCB0SDA; // Map UCB0SDA output to P1.6
      P1MAP7 = PM_UCB0SCL; // Map UCB0SCL output to P1.7
      PMAPPWD = 0; // Lock port mapping registers

      Regards,

      Leo Hendrawan

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimon Shamsiyan
      Posted by Shimon Shamsiyan
      on Oct 17 2012 14:03 PM
      Intellectual520 points

      Hi Leo,

       

      Let me recheck with you.

      Do you mean that I can use the program that is on the examples (that you’ve sent to me...) i.e. the cc430x613x_uscib0_i2c_05.c with the following (and also change my address) to the following as follows:

      //******************************************************************************

      //  CC430F613x Demo - USCI_B0 I2C Slave TX single bytes to MSP430 Master

      //

      //  Description: This demo connects two MSP430's via the I2C bus. The master

      //  reads from the slave. This is the SLAVE code. The TX data begins at 0

      //  and is incremented each time it is sent. An incoming start condition

      //  is used as a trigger to increment the outgoing data. The master checks the

      //  data it receives for validity. If it is incorrect, it stops communicating

      //  and the P1.0 LED will stay on. The USCI_B0 TX interrupt is used to know

      //  when to TX.

      //  ACLK = n/a, MCLK = SMCLK = default DCO = ~1.045MHz

      //

      //                                /|\  /|\

      //               CC430F6137      10k  10k     CC430F6137

      //                   slave         |    |        master

      //             -----------------   |    |   -----------------

      //           -|XIN  P2.6/UCB0SDA|<-|----+->|P2.6/UCB0SDA  XIN|-

      //            |                 |  |       |                 | 32kHz

      //           -|XOUT             |  |       |             XOUT|-

      //            |     P2.7/UCB0SCL|<-+------>|P2.7/UCB0SCL     |

      //            |                 |          |             P1.0|--> LED

      //

      //   M Morales

      //   Texas Instruments Inc.

      //   April 2009

      //   Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B

      //******************************************************************************

       

      #include "cc430x613x.h"

       

      unsigned char TXData;

      unsigned char i=0;

       

      void main(void)

      {

        WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

       

        PMAPPWD = 0x02D52; // Get write-access to port mapping regs

        P1MAP6 = PM_UCB0SDA; // Map UCB0SDA output to P1.6

        P1MAP7 = PM_UCB0SCL; // Map UCB0SCL output to P1.7

        PMAPPWD = 0; // Lock port mapping registers

       

        //PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs 

        //P2MAP6 = PM_UCB0SDA;                      // Map UCB0SDA output to P2.6

        //P2MAP7 = PM_UCB0SCL;                      // Map UCB0SCL output to P2.7

        //PMAPPWD = 0;                              // Lock port mapping registers

       

        P2SEL |= BIT6 + BIT7;                     // Select P2.6 & P2.7 to I2C function

         

        UCB0CTL1 |= UCSWRST;                      // Enable SW reset

        UCB0CTL0 = UCMODE_3 + UCSYNC;             // I2C Slave, synchronous mode

        UCB0I2COA = 0x48;                         // Own Address is 048h

        UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation

        UCB0IE |= UCTXIE + UCSTTIE + UCSTPIE;     // Enable TX interrupt

                                                  // Enable Start condition interrupt

        TXData = 0;                               // Used to hold TX data

       

        __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0 w/ interrupts

        __no_operation();                         // For debugger

      }

       

      // USCI_B0 State ISR

      #pragma vector = USCI_B0_VECTOR

      __interrupt void USCI_B0_ISR(void)

      {

        switch(__even_in_range(UCB0IV,12))

        {

        case  0: break;                           // Vector  0: No interrupts

        case  2: break;                           // Vector  2: ALIFG

        case  4: break;                           // Vector  4: NACKIFG

        case  6:                                  // Vector  6: STTIFG

           UCB0IFG &= ~UCSTTIFG;                  // Clear start condition int flag

           break;

        case  8:                                  // Vector  8: STPIFG

          TXData++;                               // Increment TXData

          UCB0IFG &= ~UCSTPIFG;                   // Clear stop condition int flag

          break;

        case 10: break;                           // Vector 10: RXIFG 

        case 12:                                  // Vector 12: TXIFG

          UCB0TXBUF = TXData;                     // TX data

          break;

        default: break;

        }

      }

       

      And the slave program ought to work?

       

      Thanks,

      Shimon.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Leo Hendrawan
      Posted by Leo Hendrawan
      on Oct 17 2012 14:06 PM
      Mastermind28725 points

      Hi Shimon,

      i haven't really tested it myself, but i think this should work. 

      Looking to the code, maybe you shall also change:

      P2SEL |= BIT6 + BIT7;                     // Select P2.6 & P2.7 to I2C function

      to:

      P1SEL |= BIT6 + BIT7;                     // Select P1.6 & P1.7 to I2C function

      Regards,

      Leo Hendrawan

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimon Shamsiyan
      Posted by Shimon Shamsiyan
      on Oct 17 2012 15:04 PM
      Intellectual520 points

      Ofcourse...:-)

      I'll try it tommorow and notify you.

       

      thanks a lot for the help...

      Shimon.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimon Shamsiyan
      Posted by Shimon Shamsiyan
      on Oct 18 2012 04:23 AM
      Intellectual520 points

      Hi Leo,

      I’ve inserted the code as spoke last night.

      My problems are as follows:

      1st: I don’t know how to give the Master and the slave address while there is only the: UCB0I2COA = 0x48; // Own Address is 048h.

      2nd: when running the code it seems that after processing the line  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation.

      It seems that there is a contention on the SCL line have you got any idea regarding my problems?

       

      Waiting,

      Shimon.

      P.S. The entire problems are concerning the: USCI_B0 I2C Slave TX single bytes to cc430 Slave code on the last example.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Leo Hendrawan
      Posted by Leo Hendrawan
      on Oct 19 2012 06:15 AM
      Mastermind28725 points

      Hi Shimon,

      Shimon Shamsiyan

      1st: I don’t know how to give the Master and the slave address while there is only the: UCB0I2COA = 0x48; // Own Address is 048h.

      the UCB0I2C0A is used only when the MSP430 is set to work as slave. In I2C bus, the master doesn't really need an address since it is the one which initiates the communication, and the address is used to choose the slave only.

       

      Shimon Shamsiyan

      2nd: when running the code it seems that after processing the line  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation.

      It seems that there is a contention on the SCL line have you got any idea regarding my problems?

      I am not sure whether i understand the problem here, i think you missed something after "it seems that".

      Could you download the CC430 example code: http://www.ti.com/litv/zip/slac279b, and try to pair the master running cc430x613x_uscib0_i2c_04.c and the slave running cc430x613x_uscib0_i2c_05.c? Don't forget to attach pull-up resistors between SDA, SCL lines and Vcc.

      Regards,

      Leo Hendrawan

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimon Shamsiyan
      Posted by Shimon Shamsiyan
      on Oct 20 2012 09:01 AM
      Intellectual520 points

      Hi Leo,

       

      I’ve used the same example on the slac279b.

      On my Hw the master has an address and the slave has it’s address, to configure them I’ve used the slau208k.pdf in it there is a notification of the registers that need to be configured (UCBxI2COA and the UCBxI2CSA).

      Besides I’ve changed the lines that we discussed about on the early discussion i.e. the: P2MAP6, P2MAP7 and P2SEL to: P1MAP6, P1MAP7 and P1SEL because I’m using the P1.6 and the P1.7.

      Besides on the same document (slau208d.pdf page number 958) there is a notification that the Bus stalled (SCL held low) if UCBxRXBUF not read.

      It seems that my problem is over there because I see that my SCL line is derived LOW after preceding the line:  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation

      On the example above.

      My problem is how can I make/disable LOW driving on the SCL line?

      And how the CPU knows that I’ve read the information that “he read”?

       

      I really appreciate your help until now and moreover I’ll appreciate it for solution of the problem

       

       

      Thanks,

      Shimon.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • George Standish1
      Posted by George Standish1
      on Oct 21 2012 00:46 AM
      Prodigy90 points

      I was brought here by googling I2C bit banging for MSP430.  I am using a MSP430 with 2 USCI blocks that I am using for I2C, but the problem is I need a couple more I2C buses where the MSP430 will be the slave.  I also found:

      http://www.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=slaa330

      but this is written in assembly and I am not sure how well that will translate to the variant I am using. Has anyone seen anything written in C for MSP430 that I could somewhat easily bring into a project?

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Shimon Shamsiyan
      Posted by Shimon Shamsiyan
      on Oct 21 2012 02:21 AM
      Intellectual520 points

      Hi All,

       

      It’s disappointing that I’m not getting any answer regarding it while I’m just using the TI code.

      With minor changes.

       

      Shimon.

      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