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.

MSP430FR2676: I2C Remapping issue

Part Number: MSP430FR2676
Other Parts Discussed in Thread: CAPTIVATE-FR2676, CAPTIVATE-PGMR

Hello All,

I want to interface an I2C based sensor with MSP430FR2676 where i have connected I2C sensor to Pin P4.3 and P4.4.

For this i am using Captivate-FR2676 with Captivate-PGMR Board, 

I am referring the "msp430fr267x_eusci_i2c_standard_master.c" example code.

For testing purpose first i used pin P1.2 and P1.3 and was able to read and write the registers of I2C based sensor.

However when i made the respective changes in the code for pin P4.3 and P4.4 i was not able to test the I2C interface.

Refering the below post and datasheet i also remapped the I2C pins but i was not able to solve my issue.

Also i have attached my code files for reference so please check if i am missing out on something.

8105.i2c.zip

I have observed that my code gets stuck on the "__bis_SR_register(LPM0_bits + GIE); " line in both I2C read and write functions.

Please help me to understand what i missing out.

Thanks and Regards.

  • To use UCB1 with P4.3/4, you need to set SYSCFG3:USCIB1RMP=1 [Ref data sheet (SLASEO5C) Table 6-11 and User Guide (SLAU445I) Table 1-32]. Just add:

    > SYSCFG3 |= USCIB1RMP; // Use P4 pins per data sheet Table 6-11

  • Hello All,

    Thnak You for your suggestion and help

    However, I had already made the respective changes and also verified it again as per your suggestions which is mentioned in i2c.c file which is attached in the last post,

    But stil i am not able to solve the issue, I have also attached the code below,

    void I2CInit(void)
    {
        SYSCFG3|=USCIB1RMP;                       //Set the remapping source   
    
       // I2C pins
        P4SEL0 |= BIT4 | BIT3;
        P4SEL1 &= ~(BIT4 | BIT3);
    
    
        //Initialize Clock if required
        UCB1CTLW0 = UCSWRST;                      // Enable SW reset
        UCB1CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK | UCSYNC; // I2C master mode, SMCLK
        UCB1BRW = 100;                            // fSCL = SMCLK/160 = ~100kHz
        UCB1I2CSA = SLAVE_ADDR;                   // Slave Address
        UCB1CTLW0 &= ~UCSWRST;                    // Clear SW reset, resume operation
        UCB1IE |= UCNACKIE;
    }
    
    I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count)
    {
        /* Initialize state machine */
        MasterMode = TX_REG_ADDRESS_MODE;
        ui8TransmitRegAddr = reg_addr;
        ui8RXByteCounter = count;
        ui8TXByteCounter = 0;
        ui8ReceiveIndex = 0;
        ui8TransmitIndex = 0;
    
        /* Initialize slave address and interrupts */
        UCB1I2CSA = dev_addr;
        UCB1IFG &= ~(UCTXIFG + UCRXIFG);       // Clear any pending interrupts
        UCB1IE &= ~UCRXIE;                       // Disable RX interrupt
        UCB1IE |= UCTXIE;                        // Enable TX interrupt
    
        UCB1CTLW0 |= UCTR + UCTXSTT;             // I2C TX, start condition
        __bis_SR_register(LPM0_bits + GIE);              // Enter LPM0 w/ interrupts
    
        return MasterMode;
    
    }
    
    I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
    {
        /* Initialize state machine */
        MasterMode = TX_REG_ADDRESS_MODE;
        ui8TransmitRegAddr = reg_addr;
    
        ui8TXByteCounter = count;
        ui8RXByteCounter = 0;
        ui8ReceiveIndex = 0;
        ui8TransmitIndex = 0;
    
        /* Initialize slave address and interrupts */
        UCB1I2CSA = dev_addr;
        UCB1IFG &= ~(UCTXIFG + UCRXIFG);       // Clear any pending interrupts
        UCB1IE &= ~UCRXIE;                       // Disable RX interrupt
        UCB1IE |= UCTXIE;                        // Enable TX interrupt
    
        UCB1CTLW0 |= UCTR + UCTXSTT;             // I2C TX, start condition
        __bis_SR_register(LPM0_bits + GIE);              // Enter LPM0 w/ interrupts
    
        return MasterMode;
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B1_VECTOR
    __interrupt void USCI_B1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B1_VECTOR))) USCI_B1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      //Must read from UCB0RXBUF
      uint8_t rx_val = 0;
      switch(__even_in_range(UCB1IV, 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
          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:                 // Vector 22: RXIFG0
            rx_val = UCB1RXBUF;
            if (ui8RXByteCounter)
            {
              ui8ReceiveBuffer[ui8ReceiveIndex++] = rx_val;
              ui8Dummy[ui8dmyi++] = rx_val;
              ui8RXByteCounter--;
            }
    
            if (ui8RXByteCounter == 1)
            {
              UCB1CTLW0 |= UCTXSTP;
            }
            else if (ui8RXByteCounter == 0)
            {
              UCB1IE &= ~UCRXIE;
              MasterMode = IDLE_MODE;
              __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
            }
            break;
        case USCI_I2C_UCTXIFG0:                 // Vector 24: TXIFG0
            switch (MasterMode)
            {
              case TX_REG_ADDRESS_MODE:
                  UCB1TXBUF = ui8TransmitRegAddr;
                  if (ui8RXByteCounter)
                      MasterMode = SWITCH_TO_RX_MODE;   // Need to start receiving now
                  else
                      MasterMode = TX_DATA_MODE;        // Continue to transmision with the data in Transmit Buffer
                  break;
    
              case SWITCH_TO_RX_MODE:
                  UCB1IE |= UCRXIE;              // Enable RX interrupt
                  UCB1IE &= ~UCTXIE;             // Disable TX interrupt
                  UCB1CTLW0 &= ~UCTR;            // Switch to receiver
                  MasterMode = RX_DATA_MODE;    // State state is to receive data
                  UCB1CTLW0 |= UCTXSTT;          // Send repeated start
                  if (ui8RXByteCounter == 1)
                  {
                      //Must send stop since this is the N-1 byte
                      while((UCB1CTLW0 & UCTXSTT));
                      UCB1CTLW0 |= UCTXSTP;      // Send stop condition
                  }
                  break;
    
              case TX_DATA_MODE:
                  if (ui8TXByteCounter)
                  {
                      UCB1TXBUF = ui8TransmitBuffer[ui8TransmitIndex++];
                      ui8TXByteCounter--;
                  }
                  else
                  {
                      //Done with transmission
                      UCB1CTLW0 |= UCTXSTP;     // Send stop condition
                      MasterMode = IDLE_MODE;
                      UCB1IE &= ~UCTXIE;                       // disable TX interrupt
                      __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
                  }
                  break;
    
              default:
                  __no_operation();
                  break;
            }
            break;
        default: break;
      }
    }

    Please Help me with this at the earliest.

    Thanks and Regards.

    Utkarash

  • I just realized that I've been looking at the schematics for the CAPTIVATE-2633 (linked from the CAPTIVATE-2676 page (!)), which doesn't have UCB1 nor P4. I haven't been able to find the correct schematics, so as a result I'm kind of working blind.

    Since you've apparently figured this out already, I have to ask you: How have you connected to UCB1/P4.3-4? I'm concerned in particular about the pullups which are supplied outbound (MSP_SDA/_SCL) -- are they connected to your circuit? If your I2C bus were lacking pullups, you would see this sort of symptom.

    In many cases the internal pullups can suffice (if the wires are very short, and you don't run the bus too fast). A quick experiment might be to add:

    > P4OUT |= (BIT3|BIT4); // Engage

    > P4REN |= (BIT3|BIT4); //     internal pullups -- maybe they'll work

  • Since you've apparently figured this out already, I have to ask you: How have you connected to UCB1/P4.3-4? I'm concerned in particular about the pullups which are supplied outbound (MSP_SDA/_SCL) -- are they connected to your circuit? If your I2C bus were lacking pullups, you would see this sort of symptom.

    -- I have connected 4.7 k Pullup register to SCL and SDA pins which were recommended in "msp430fr267x_eusci_i2c_standard_master.c" example code. 

    Also when i interface the sensor on eUSCB0 pins of I2C (i.e., P1.2 and P1.3) i was able to communicate, however when i interfaced sensor on eUSCB1 pin of I2C (i.e., P4.3 and P4.4) i am not able to interface the same.

     

    In many cases the internal pullups can suffice (if the wires are very short, and you don't run the bus too fast). A quick experiment might be to add:


    -- I tried without pullup register, However still my issues remains the same.

    Please help where i am missing out ?

    Thanks and regards

  • > #pragma vector = USCI_B1_VECTOR

    This should be 

    > #pragma vector = EUSCI_B1_VECTOR

    -----------------

    Also, do you have anything connected to J6 ("Sensor PCB Connector")? I see that P4.3/.4 are also connected to that.

    -----------------

    [For archaeologists: The CAPTIVATE-FR2676 design files are SLAC789.zip, posted over here:

    https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/978973

    ]

**Attention** This is a public forum