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.

MSP430G2433 I2C CODE FOR BQ32002.

Other Parts Discussed in Thread: MSP430G2433, BQ32002, MSP430G2553

hi,

i am tying to interface the bq32002 to msp430g2433 if some one help me with sample code it will be helpful, i tried a lot on web and TI website dint found it for USCI_B0. please help if any one have the sample code. 

  • Hi Rajendra,

    I have moved this to the MSP E2E board for help configuring the MSP as a interface master.

    Gabe
  • dear sir i need the code urgent i m struggling since 3 days please help
  • There already is example code that shows how to use I²C. What specific problem do you have with adapting this for the BQ?
  • Hi Rajendra,

    I don't know of any existing code for interfacing the BQ32002 and an MSP430. However, for the MSP430G2553 device you can find all of the device code examples in TI Resource Explorer built into CCS, by going to View > Resource explorer and then using the tabs to expand MSPware and find the device you are using. There is also Cloud Resource explorer available online at https://dev.ti.com - here is a link to the code examples for MSP430G2553 in cloud resource explorer: dev.ti.com/.../
    Look there for the various USCI_B0 I2C examples - there are several of them for different I2C modes.

    Looking in the datasheet for the BQ32002 RTC, I see that in p.7-8 it has the descriptions for the I2C protocol used by the device. You can see that it says the RTC device will respond to the I2C slave address 1101000b and then there is the R/W bit. Because the MSP430 USCI module will append the R/W bit for you based on what you have set in the USCI registers (if you've set the UCTR bit to 0 or 1 in the UCB0CTL1 register for doing a transmit or receive) then I think you will need to simply change the MSP430 slave address register UCB0I2CSA to 1101000b or 0x68. Figure 4 and 5 in the BQ32002 datasheet shows the protocol for a read vs a write to the RTC device.

    You would also need to make some changes to the code examples linked above to match the protocol shown in Figure 4 of the BQ32002 datasheet- the Sub Address will be the address of the register that you want to access in the BQ32002 device - those registers are described in p.9-15 of the BQ32002 datasheet. You will also need to do a repeated start for your reads - send the Sub Address, then do a repeated start and start receiving from the slave instead. This is discussed in the MSP430x2xx user's guide www.ti.com/.../slau144 section 17 USCI I2C mode specifically section 17.3.4.2.1 I2C Master Transmitter Mode. This MSP430 user's guide will be your good resource for understanding what the sample code does because it explains all of the registers and bits.

    I hope this helps to point you to the right places to help you get started.

    Regards,
    Katie
  • sir i tried mostly all things but still not working if some one can help me with rtc code it will be helpful or else i have to write a discreet full cycle by cycle code for the rtc considering all the read and write waveform like we do in 8051 controller.
  • Hi Rajendra,

    Unfortunately, as I mentioned before, demo code for this specific combination of two boards simply doesn't exist already - TI sells thousands of parts, and while we do try to provide a lot of examples we don't have them for every single combination that might be out there.

    Could you try posting more information about what modifications to the code examples you have already tried to try to get it to work, and what specifically was not working, so that the community can help you better? Some waveforms of what you are getting out of the MSP when you are trying your code could be helpful to pinpoint what is not matching with the specification in the RTC datasheet. For an initial test, maybe you'd want to try to make a piece of code that simply reads the CFG2 register out of the RTC, since it looks like that register has a defined initial value at startup (see the datasheet for the BQ32002 on Table 14 it says it should start as 10101010b). So that would let you check if you read the correct byte.

    Regards,
    Katie
  • I do see that there is an application note www.ti.com/.../spma069 for interfacing a Tiva device with the BQ32002 - you may be able to try porting these APIs to MSP430, however the Tiva I2C module may be fairly different from the MSP430 one.
    -Katie
  • //I2C Config
    P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
    P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
    P1REN |= BIT6+BIT7; //Enable pull up resistors


    UCB0CTL1 = UCSWRST; //Hold I2C bus during initiation
    UCB0CTL0 = UCMODE_3 + UCMST + UCSYNC; //sets I2C mode, master mode, synchronous mode
    UCB0CTL1 |= UCSSEL_3; //select SMCLK
    UCB0I2CSA = 0xD0; //slave address
    UCB0CTL1 &= ~UCSWRST; //enable i2c
    UCB0CTL1 |= UCTR + UCTXSTT; //set transmit, generate start
    while(!(UCB0TXIFG)){;} //wait for transmission to finish
    UCB0TXBUF = 0x00; //send command byte
    while(!(UCB0TXIFG)){;} //wait for transmission to finish
    UCB0TXBUF = 10; //set sec value
    UCB0CTL1 |= UCTXSTP; //generate stop condition
    while(!(UCB0TXIFG)){;} //wait for transmission to finish
    UCB0CTL1 = UCSWRST; //release I2C bus

    read_sec:
    UCB0CTL1 = UCSWRST; //Hold I2C bus during initiation
    UCB0CTL0 = UCMODE_3 + UCMST + UCSYNC; //sets I2C mode, master mode, synchronous mode
    UCB0CTL1 |= UCSSEL_3; //select SMCLK

    UCB0I2CSA = 0xD0; //slave address dummy write
    UCB0CTL1 &= ~UCSWRST; //enable i2c
    UCB0CTL1 |= UCTR + UCTXSTT; //set transmit, generate start
    while(!(UCB0TXIFG)){;} //wait for transmission to finish

    UCB0TXBUF = 0x00; //send command byte
    while(!(UCB0TXIFG)){;} //wait for transmission to finish

    UCB0I2CSA = 0xD1; //slave address
    UCB0CTL1 &= ~UCSWRST; //enable i2c
    UCB0CTL1 |= UCTR + UCTXSTT; //set transmit, generate start
    while(!(UCB0TXIFG)){;}

    UCB0CTL1 |= UCTXSTT; // I2C start condition
    while (UCB0CTL1 & UCTXSTT); // Start condition sent?

    RxWord = UCB0RXBUF;

    UCB0CTL1 |= UCTXSTP; //generate stop condition
    while(!(UCB0TXIFG)){;} //wait for transmission to finish
    UCB0CTL1 = UCSWRST; //release I2C bus

    goto read_sec;

    dear sir, this is the code written for to take only second data from rtc
  • Hi Rajendra,

    As I mentioned in my post here: e2e.ti.com/.../1707373 I think that because the MSP430 appends the last bit of the slave address (the r/w bit) automatically, I think that instead of using 0xD0 and 0xD1 for your read/write slave addresses, you should instead just set the address in the UCB0I2CSA slave address register as 1101000b or 0x68 for both reads and writes. Can you try this?

    I suspect that if you look at the output of your current code on a logic analyzer or oscilloscope you will see that it is probably sending the slave address incorrectly relative to the diagrams in the BQ32002 datasheet due to your setting to 0xD0 vs 0xD1.

    In addition, I don't see that you divide down SMCLK at all - what is your SMCLK set to? If it is the default 1MHz that will be far too fast for I2C - I'd recommend putting some dividers on it using the bits in the USCI module for this purpose, UCB0BR0 and UCB0BR1. Finally, make sure that you have correctly sized external pullup resistors on the I2C lines between the two devices and that they have the same Vcc and GND. If you look at your waveforms on the oscilloscope and they have bad slew rise/time on them, you may need to change the size of your pullup resistors.
     
    Regards,
    Katie

  • dear sir, for 0x68 also i am not getting any output.
  • I don't see that you divide down SMCLK at all - what is your SMCLK set to? If it is the default 1MHz that will be far too fast for I2C - I'd recommend putting some dividers on it using the bits in the USCI module for this purpose, UCB0BR0 and UCB0BR1. Finally, make sure that you have correctly sized external pullup resistors on the I2C lines between the two devices and that they have the same Vcc and GND. If you look at your waveforms on the oscilloscope and they have bad slew rise/time on them, you may need to change the size of your pullup resistors.

    Could you upload any waveforms showing your issue from your oscilloscope or logic analyzer?

    -Katie
  • thank you sir, finally i completed the code now my i2c is working properly i can send the data to bq32002 and also receive the data but now i am facing problem related to the clock i am getting the same data from bq32002 its not updating i have also set the stop bit in second sfr to 0 so it can start the oscillation but its not getting oscillated. please help how to enable the rtc oscillations so that it will update the time.  

  • Hi Rajendra,

    Good to hear that you got the I2C working! At this point it sounds like your questions now are about how to set up the RTC, rather than how to use the MSP430 - for this, you'll probably need help from the Clock & timing forum .

    Regards,
    Katie

**Attention** This is a public forum