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/MSP430FR5949: I2C- is ucb0txbuf having 27 byte only ?

Part Number: MSP430FR5949

Tool/software: Code Composer Studio

hi i tried to transmit

I2cWrite("1234567891234567891234567891"); //see the red marked "1", now it is not working if above 27 character is transmitted

hi tried to write the above string but it fails to write on I2C channel,

I2cWrite("123456789123456789123456789");//see the red marked "1" is removed here, now it works fine, if the total string is 27 or less, 

how to increase the total number  of string to transmit.

thanks

 

  • void I2cWrite(char *str)
    {
        UCB0I2CSA = 0x08;               // configure slave address
        i2cDataPointer=str;             //string need to print data pointer
        UCB0TBCNT=0x100;                //mantatory keep maximum byte counter, IV will take care to end the string
        while (UCB0CTLW0 & UCTXSTP);            // Ensure stop condition got sent
        UCB0CTLW0 |= UCTR | UCTXSTT;            // I2C TX, start condition
        while (UCB0CTLW0 & UCTXSTP);            // Ensure stop condition got sent
        delay;                          // delay mandatory, otherwise wont work
    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
      {
        case USCI_NONE:          break;         // Vector 0: No interrupts
        case USCI_I2C_UCALIFG:   break;         // Vector 2: ALIFG
        case USCI_I2C_UCNACKIFG:                // Vector 4: NACKIFG
          UCB0CTLW0 |= UCTXSTT;                 // resend start if NACK
          break;
        case USCI_I2C_UCSTTIFG:  break;         // Vector 6: STTIFG
        case USCI_I2C_UCSTPIFG:  break;         // Vector 8: STPIFG
        case USCI_I2C_UCRXIFG3:  break;         // Vector 10: RXIFG3
        case USCI_I2C_UCTXIFG3:  break;         // Vector 12: TXIFG3
        case USCI_I2C_UCRXIFG2:  break;         // Vector 14: RXIFG2
        case USCI_I2C_UCTXIFG2:  break;         // Vector 16: TXIFG2
        case USCI_I2C_UCRXIFG1:  break;         // Vector 18: RXIFG1
        case USCI_I2C_UCTXIFG1:  break;         // Vector 20: TXIFG1
        case USCI_I2C_UCRXIFG0:
            RXData[RXDataCounter] = UCB0RXBUF;                 // Get RX data
            RXDataCounter++;
            break;                              // Vector 22: RXIFG0
        case USCI_I2C_UCTXIFG0:                 // Vector 24: TXIFG0
            if(*i2cDataPointer=='\0')
            {
                UCB0CTLW0 |= UCTXSTP;               // I2C stop condition
                UCB0IFG &= ~UCTXIFG;                // Clear USCI_B0 TX int flag
                //            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
            }
            else if(*i2cDataPointer=='$')           // this block will execute only at read process for repeated start and slave address with read bit
            {
                UCB0IFG &= ~UCTXIFG;
                UCB0I2CSA = address;                // load the slave address
                UCB0CTLW0 &= ~UCTR;                 // TX RX direction change bit
                UCB0CTLW0 |=  UCTXSTT;              // I2C TX, start condition
                delay;                              //delay mandatory otherwise wont work
                UCB0IFG &= ~UCTXIFG;
            }
            else
            {
            UCB0TXBUF = *i2cDataPointer;            // Load TX buffer
            }
            i2cDataPointer++;                       //incrementing the pointer
            delay;                                  //delay mandatory otherwise wont work
            break;
        case USCI_I2C_UCBCNTIFG:                    // Vector 26: BCNTIFG
            UCB0IFG &= ~UCRXIFG;                    // Clear USCI_B0 RX int flag
            UCB0IFG &= ~UCTXIFG;                    // Clear USCI_B0 TX int flag
            break;
        default: break;
      }
    }

  • Hi,

    Thanks for your question. I will look into this and reply back to you on Monday.

    Best regards,

    Angelo

  • Hi,

    At the moment, nothing in your code jumps out at me that would prevent more than 27 bytes from being transmitted. The MSP430FR5949 has a byte counter threshold register UCBxTBCNT that controls how many bytes can be transmitted in one frame, but it looks like you're setting this register above 27. However, please confirm that UCASTPx is not 00 and that UCSWRST = 1. The code snippet that you shared doesn't write to these registers, so I would like to rule out this possibility.

    Aside from that, can you please give more details about the behavior when you try to transmit more than 27 bytes at a time? For example:

    1) Are only the first 27 bytes transmitted, or is nothing transmitted at all?

    2) Have you tried single-stepping through your code to see which interrupt vectors are being entered?

    3) Can you share some logic analyzer waveforms to show what's happening on the TX and RX lines?

    Lastly, can you share your whole CCS project with me so I can look into this further? If you would prefer to share this privately, feel free to email me at a-zhang2@ti.com.

    Best regards,

    Angelo

  • hi anglo,

     if       TXByteCtr = 27 or less it works fine, if i increase the       TXByteCtr more than 27 it is not responding,the code is below

    thanks

    #include <msp430.h>

    const unsigned char TXData[] = { 'a','b', 'c', 'd' };
    const unsigned char SlaveAddress[] = { 0x08, 0x08, 0x08, 0x08 };
    volatile unsigned char TXByteCtr;
    volatile unsigned char SlaveFlag = 0;

    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;

      // Configure GPIO
      P1SEL1 |= BIT6 | BIT7;                    // I2C pins

      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;

      // Configure USCI_B0 for I2C mode
      UCB0CTLW0 = UCSWRST;                      // put eUSCI_B in reset state
      UCB0CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK; // I2C master mode, SMCLK
      UCB0BRW = 0x8;                            // baudrate = SMCLK / 8
      UCB0TBCNT=100;
      UCB0CTLW0 &= ~UCSWRST;                    // clear reset register
      UCB0IE |= UCTXIE0 | UCNACKIE;             // transmit and NACK interrupt enable

      SlaveFlag = 0;                            // Initialize SlaveFlag
      while(1)
      {
          TXByteCtr = 35;                          // Load TX byte counter
        UCB0I2CSA = SlaveAddress[SlaveFlag];    // configure slave address
         while (UCB0CTLW0 & UCTXSTP);            // Ensure stop condition got sent

        UCB0CTLW0 |= UCTR | UCTXSTT;            // I2C TX, start condition

        __bis_SR_register(LPM0_bits | GIE);     // Enter LPM0 w/ interrupts
                                                // Remain in LPM0 until all data
                                                // is TX'd
        // Change Slave address


      }
    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
      {
        case USCI_NONE:          break;         // Vector 0: No interrupts
        case USCI_I2C_UCALIFG:   break;         // Vector 2: ALIFG
        case USCI_I2C_UCNACKIFG:                // Vector 4: NACKIFG
          UCB0CTLW0 |= UCTXSTT;                 // resend start if NACK
          break;
        case USCI_I2C_UCSTTIFG:  break;         // Vector 6: STTIFG
        case USCI_I2C_UCSTPIFG:  break;         // Vector 8: STPIFG
        case USCI_I2C_UCRXIFG3:  break;         // Vector 10: RXIFG3
        case USCI_I2C_UCTXIFG3:  break;         // Vector 12: TXIFG3
        case USCI_I2C_UCRXIFG2:  break;         // Vector 14: RXIFG2
        case USCI_I2C_UCTXIFG2:  break;         // Vector 16: TXIFG2
        case USCI_I2C_UCRXIFG1:  break;         // Vector 18: RXIFG1
        case USCI_I2C_UCTXIFG1:  break;         // Vector 20: TXIFG1
        case USCI_I2C_UCRXIFG0:  break;         // Vector 22: RXIFG0
        case USCI_I2C_UCTXIFG0:                 // Vector 24: TXIFG0
          if (TXByteCtr)                        // Check TX byte counter
          {
            UCB0TXBUF = TXData[0];      // Load TX buffer
            TXByteCtr--;                        // Decrement TX byte counter
          }
          else
          {
            UCB0CTLW0 |= UCTXSTP;               // I2C stop condition
            UCB0TBCNT=100;
            UCB0IFG &= ~UCTXIFG;                // Clear USCI_B0 TX int flag
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
          }
          break;
        default: break;
      }
    }

  • hi, worst people in the world is e2e, they wont give solution for anything , i dont know why they have forum at all?

    i ve asked so many question so far, no question is being replied with valid answer, no problem is solved so far.

  • Hi,

    I apologize for the delay; I had several tasks come up on my side. I'm still looking into your code to see if I can find your issue.

    From your previous reply, it sounds like nothing is being transmitted at all (not even the first 27 bytes) if you set TXByteCtr > 27. However, everything works correctly if TXByteCtr <= 27.

    Have you been able to check my 2nd and 3rd suggestions? Single-stepping through your code to compare the TXByteCtr <= 27 case and the TXByteCtr >27 case could provide useful clues. If you have access to a logic analyzer, it would also be helpful to compare the TX and RX waveforms in both cases.

    Lastly, it would definitely speed up the debugging process if you could share your entire CCS project with me. I'd like to compile, run, and debug it on my side to see if I can hone in on the issue. Again, please feel free to email the project to me at a-zhang2@ti.com if you're more comfortable sharing this privately.

    Sorry again for the delay.

    Best regards,

    Angelo

  • hi

    thanks Angelo, i can not give you the entire project due to company rules, but if the above file is corrected then i can adapt that file in to my project.

    thanks

  • #include <msp430.h>

    const unsigned char TXData[] = { 'a','b', 'c', 'd' };
    const unsigned char SlaveAddress[] = { 0x08, 0x08, 0x08, 0x08 };
    volatile unsigned char TXByteCtr;
    volatile unsigned char SlaveFlag = 0;

    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;

      // Configure GPIO
      P1SEL1 |= BIT6 | BIT7;                    // I2C pins

      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;

      // Configure USCI_B0 for I2C mode
      UCB0CTLW0 = UCSWRST;                      // put eUSCI_B in reset state
      UCB0CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK; // I2C master mode, SMCLK
      UCB0BRW = 0x8;                            // baudrate = SMCLK / 8
      UCB0TBCNT=100;
      UCB0CTLW0 &= ~UCSWRST;                    // clear reset register
      UCB0IE |= UCTXIE0 | UCNACKIE;             // transmit and NACK interrupt enable

      SlaveFlag = 0;                            // Initialize SlaveFlag
      while(1)
      {
          TXByteCtr = 35;                          // Load TX byte counter
        UCB0I2CSA = SlaveAddress[SlaveFlag];    // configure slave address
         while (UCB0CTLW0 & UCTXSTP);            // Ensure stop condition got sent

        UCB0CTLW0 |= UCTR | UCTXSTT;            // I2C TX, start condition

        __bis_SR_register(LPM0_bits | GIE);     // Enter LPM0 w/ interrupts
                                                // Remain in LPM0 until all data
                                                // is TX'd
        // Change Slave address


      }
    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
      {
        case USCI_NONE:          break;         // Vector 0: No interrupts
        case USCI_I2C_UCALIFG:   break;         // Vector 2: ALIFG
        case USCI_I2C_UCNACKIFG:                // Vector 4: NACKIFG
          UCB0CTLW0 |= UCTXSTT;                 // resend start if NACK
          break;
        case USCI_I2C_UCSTTIFG:  break;         // Vector 6: STTIFG
        case USCI_I2C_UCSTPIFG:  break;         // Vector 8: STPIFG
        case USCI_I2C_UCRXIFG3:  break;         // Vector 10: RXIFG3
        case USCI_I2C_UCTXIFG3:  break;         // Vector 12: TXIFG3
        case USCI_I2C_UCRXIFG2:  break;         // Vector 14: RXIFG2
        case USCI_I2C_UCTXIFG2:  break;         // Vector 16: TXIFG2
        case USCI_I2C_UCRXIFG1:  break;         // Vector 18: RXIFG1
        case USCI_I2C_UCTXIFG1:  break;         // Vector 20: TXIFG1
        case USCI_I2C_UCRXIFG0:  break;         // Vector 22: RXIFG0
        case USCI_I2C_UCTXIFG0:                 // Vector 24: TXIFG0
          if (TXByteCtr)                        // Check TX byte counter
          {
            UCB0TXBUF = TXData[0];      // Load TX buffer
            TXByteCtr--;                        // Decrement TX byte counter
          }
          else
          {
            UCB0CTLW0 |= UCTXSTP;               // I2C stop condition
            UCB0TBCNT=100;
            UCB0IFG &= ~UCTXIFG;                // Clear USCI_B0 TX int flag
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
          }
          break;
        default: break;
      }
    }

  • below is working code

    if you change the TXByteCtr more than 27 it is not working

    #include <msp430.h>

    const unsigned char TXData[] = { 'a','b', 'c', 'd' };
    const unsigned char SlaveAddress[] = { 0x08, 0x08, 0x08, 0x08 };
    volatile unsigned char TXByteCtr;
    volatile unsigned char SlaveFlag = 0;

    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;

      // Configure GPIO
      P1SEL1 |= BIT6 | BIT7;                    // I2C pins

      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;

      // Configure USCI_B0 for I2C mode
      UCB0CTLW0 = UCSWRST;                      // put eUSCI_B in reset state
      UCB0CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK; // I2C master mode, SMCLK
      UCB0BRW = 0x8;                            // baudrate = SMCLK / 8
      UCB0TBCNT=100;
      UCB0CTLW0 &= ~UCSWRST;                    // clear reset register
      UCB0IE |= UCTXIE0 | UCNACKIE;             // transmit and NACK interrupt enable

      SlaveFlag = 0;                            // Initialize SlaveFlag
      while(1)
      {
          TXByteCtr = 20;                          // Load TX byte counter
        UCB0I2CSA = SlaveAddress[SlaveFlag];    // configure slave address
         while (UCB0CTLW0 & UCTXSTP);            // Ensure stop condition got sent

        UCB0CTLW0 |= UCTR | UCTXSTT;            // I2C TX, start condition

        __bis_SR_register(LPM0_bits | GIE);     // Enter LPM0 w/ interrupts
                                                // Remain in LPM0 until all data
                                                // is TX'd
        // Change Slave address


      }
    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
      {
        case USCI_NONE:          break;         // Vector 0: No interrupts
        case USCI_I2C_UCALIFG:   break;         // Vector 2: ALIFG
        case USCI_I2C_UCNACKIFG:                // Vector 4: NACKIFG
          UCB0CTLW0 |= UCTXSTT;                 // resend start if NACK
          break;
        case USCI_I2C_UCSTTIFG:  break;         // Vector 6: STTIFG
        case USCI_I2C_UCSTPIFG:  break;         // Vector 8: STPIFG
        case USCI_I2C_UCRXIFG3:  break;         // Vector 10: RXIFG3
        case USCI_I2C_UCTXIFG3:  break;         // Vector 12: TXIFG3
        case USCI_I2C_UCRXIFG2:  break;         // Vector 14: RXIFG2
        case USCI_I2C_UCTXIFG2:  break;         // Vector 16: TXIFG2
        case USCI_I2C_UCRXIFG1:  break;         // Vector 18: RXIFG1
        case USCI_I2C_UCTXIFG1:  break;         // Vector 20: TXIFG1
        case USCI_I2C_UCRXIFG0:  break;         // Vector 22: RXIFG0
        case USCI_I2C_UCTXIFG0:                 // Vector 24: TXIFG0
          if (TXByteCtr)                        // Check TX byte counter
          {
            UCB0TXBUF = TXData[0];      // Load TX buffer
            TXByteCtr--;                        // Decrement TX byte counter
          }
          else
          {
            UCB0CTLW0 |= UCTXSTP;               // I2C stop condition
            UCB0TBCNT=100;
            UCB0IFG &= ~UCTXIFG;                // Clear USCI_B0 TX int flag
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
          }
          break;
        default: break;
      }
    }

  • i ve solved the issue , the issue was in another hardware.

    thanks

  • sorry the issue is not solved, still the issue is in the msp430fr5949only

    please kindly give solution

  • while watching in logic analyzer analyzer slave is replying continuously "NAK", if number of byte is more than 27.

  • Hi,

    Thank you very much for the additional information. I'll continue looking into your code, but it's interesting that leaving the rest of your code untouched and only changing TXByteCtr from 20 to 35 causes an issue.

    Can you please share the logic analyzer waveforms that you captured? I'd like to see the TX and RX lines for both the TXByteCtr <= 27 case and the TXByteCtr > 27 case. As shown below, several conditions can cause an I2C NACK, so I want to make sure that I'm fully clear on the behavior you're seeing.

    Finally, what device is your MSP430FR5949 communicating with? Can you confirm that the receiving device is able to receive more than 27 bytes at a time if the transmission is done using different hardware (not the MSP430FR5949)?

    Best regards,

    Angelo

  • hi

    i am making bridge between Msp430fr5949 and my PC,

    for that

    msp430gives i2c signal-->i2c to uart converter(arduino uno)-->hyperterminal 

    here arduino uno program is also attached

    #include <Wire.h>

    void setup() {
      Wire.begin(8);                // join i2c bus with address #8
      Wire.onReceive(receiveEvent); // register event
      Serial.begin(9600);           // start serial for output
    }

    void loop() {
      delay(100);
    }

    // function that executes whenever data is received from master
    // this function is registered as an event, see setup()
    void receiveEvent(int howMany)
    {
      while (1 < Wire.available())
      { // loop through all but the last
        char c = Wire.read(); // receive byte as a character
        Serial.print(c);         // print the character
      }
      char x = Wire.read();    // receive byte as an integer
      Serial.println(x);         // print the integer
    }

  • Hi,

    Thanks for that additional information.

    Can you please send the logic analyzer waveforms that I requested in my last post? I'd like to see the TX and RX lines for both the TXByteCtr <= 27 case and the TXByteCtr > 27 case.

    Also, can you confirm that your Arduino Uno program is able to successfully receive more than 27 bytes at a time if the transmission is done using different hardware (not the MSP430FR5949)? I want to verify that there's no issue on that end and that the issue is indeed related to the MSP430FR5949.

    Thank you for your patience with this issue. Debugging is much more difficult since I don't have access to your whole CCS project, but I'd like to rule out as many potential sources of error as possible.

    Best regards,

    Angelo

  • Hi,

    I haven't heard back from you for over a week, so I am assuming you were able to resolve your issue. If not, just post a reply below or create a new thread if the thread has locked due to time-out.

    Best regards,

    Angelo

  • hi Angelo,

    sorry for the delay, i thought that i have replied already; found the solution, the issue was not in the msp430, the issue was in the supporting hardware, that has the capability to receive limited number of byte in I2C.if the in-coming byte goes more than the limit, it stops sending 'ACK'.

    thanks for your support

    thank you very much..

  • Hi,

    Thank you very much for the update! I'm glad you were able to resolve the issue.

    Best regards,

    Angelo

**Attention** This is a public forum