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/MSP430I2040: How to use example I2C code for ds3231 RTC?

Part Number: MSP430I2040


Tool/software: Code Composer Studio

Hello,

As there are separate code for master transmit and master receive in examples. No example with tx and rx both.

Also functions are bit confusing.

For interfacing with DS3231 rtc the procedure is START -slave address(write)- data address(write)- stop- restart -slave address(read)- data -NCK.

I followed same sequence  but no response from slave.

Please give me any example code.

Thanks,

Anuradha.

  • The Web-side Resource Explorer has an "extra" (not in the Examples .zip file): msp430i20xx_eusci_i2c_standard_master:

    http://dev.ti.com/tirex/explore/node?node=ABxIzb6H4Ur8ka5kZRvh4Q__IOGqZri__LATEST

    I'm not completely sure what the TYPEs are about, but it looks as though you could just remove the other calls and call I2C_Mode I2C_Master_ReadReg with your data array. The state machine stuff is all there.

  • Hello,

    I am trying I2C communication between MSP430i2040 to DS3231 (RTC) without interrupt.

    Initially trying to read seconds only(single byte)

    CODE as follows,

    main(){

    ..........

    // Setting up I2C communication at 400kHz using SMCLK

         EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &i2cConfig);

         // Set master in transmit mode
        EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE);

         // Settings slave address
         EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, 0xD0);

         // Enable the module for operation
         EUSCI_B_I2C_enable(EUSCI_B0_BASE);

    while(1){

             HWREG16(0x0140 + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;                        //start condition
             HWREG16(0x0140 + OFS_UCBxTXBUF) = 0xD0;                                               //send byte 0x0D (Slave ID) write mode
             HWREG16(0x0140 + OFS_UCBxTXBUF) = 0;                                                     //send byte 0 (Reg address of seconds data)
             HWREG16(0x0140 + OFS_UCBxCTLW0) |= UCTXSTP;                                     //Stop condition
             // HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCTR;                            //receive mode-------(?)

             // EUSCI_B_I2C_masterReceiveStart(0x0140);                                                    //Is it required-------(?)

                               HWREG16(0x0140 + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;                       //start condition
             
                               HWREG16(0x0140 + OFS_UCBxTXBUF) = 0xD1;                                                //send byte 0xD1 read mode
          
                               HWREG16(0x0140 + OFS_UCBxCTLW0) &= ~UCTR;//receive mode
                               RX_Byte=UCB0RXBUF;//EUSCI_B_I2C_masterReceiveSingle(0x0140);          //Read seconds data
           
                               HWREG16(0x0140 + OFS_UCBxCTLW0) |= UCTXSTP;//Stop condition          //stop
           
                                EUSCI_A_UART_transmitData(0x0140,RX_Byte); __delay_cycles(500);         //display received data on UART 

    }}

    Not getting expected result.

    Please guide me.

    Thanks,

    Anuradha.

  • I encourage you to study the Examples, along with the state diagrams in User Guide (SLAU335) Figs 12-12 and 12-13.

    1) The DS3231 address is 0x68, not 0xD0 [Ref DS3231 data sheet (19-5170, rev 10) Figs 3-4]

    2) You should not be sending the SLA (SLave Address) byte yourself, since the I2C unit will do that based on UCTR and I2CSA.

    3) You should not write into TXBUF until TXIFG is presented, else the byte will be lost.

    4) You should not read from RXBUF until RXIFG is presented, else you're reading junk.

    5) DS3231 data sheet p. 11 ("I2C Interface") describes a post-reset recovery sequence. This may or may not be a problem now, but I expect it will be eventually.

  • Hello,

    1.The DS3231 slave address is 0xD0. Please check datasheet,

    https://datasheets.maximintegrated.com/en/ds/DS3231.pdf , specifically Fig. No. 3,4,5.

    Can you send me link of datasheet in which it is given as 0x68?

    2. Also please share me link of SLAU335 for state diagram.

    3.For sure state machine would work. But I am trying to write code without interrupt and using basic instructions.

    2) You should not be sending the SLA (SLave Address) byte yourself, since the I2C unit will do that based on UCTR and I2CSA.----Didn't get this. As basic I2C protocol says, need to send slave address first before data? You meant to say without state machine I2C code can not written with msp430i2040?

     

    Thanks,

    Anuradha.

  • 1) The document you linked appears to be the same as mine. Fig 3 shows the "<Slave Address>" as 1101000 which is 0x68.

    2) SLAU335 is at http://www.ti.com/lit/ug/slau335/slau335.pdf  I keep this open all the time when I'm writing code for this chip.

    2A) E.g. SLAU335 Sec 12.3.5.2.1 (second paragraph) says "The eUSCI_B module [...] generates the START condition, and transmits the slave address." If you were implementing I2C, you would have to do this, but it's the USCI that's implementing I2C.

    3) I'm not sure what "state machine" you're referring to. The USCI informs you of the need to send/receive using the TXIFG/RXIFG flags. If you ignore them your transactions won't (in general) work properly.

    In addition to the User Guide and Data Sheet, TI came up with a nice Troubleshooting Guide (SLAA734A) which might be useful:

    http://www.ti.com/lit/an/slaa734a/slaa734a.pdf

  • 1101 0000 is 0xD0, not 0x68

    0x68 is 0110 1000

    It looks like you shifted in an extra 0 on the left. 8^)

  • The Slave address is only 7 bits (it doesn't include the R/W bit). "1101000" is copied from DS3231 data sheet Fig 3.

  • Never mind, I forgot that the R/W was *after* the address, not *before*.

    This is all why I prefer SPI. 8^)

  • Hello,

    Slave address is 1101000 and read write bit after this means for read it becomes 11010000 i.e 0xD0 and for write 0xD1. I don't know how you figured it out as 0x68?

    I referred many examples of interfacing DS3231 in which slave address is 0xD0.

  • You have made a true statement. By appending the R/W bit, you have created what is commonly called an "SLA Byte" (I don't think UM10204 r6  has a term for it). Using the USCI, there is no reason for your code to construct an SLA Byte.

    You're welcome to continue loading 0xD0 (or is it 0xD1?) into I2CSA, and sending your own SLA Byte, but I predict that will not achieve your goal.

**Attention** This is a public forum