Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

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/MSP432P401R: interfacing ds1307 with msp432

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi,

I'm trying to connect ds1307 with msp432p401r launchpad (red) using i2c protocol, but no luck.

msp432 is sending the data but not receiving ( transmit-->poll and receive--> interrupt ).

I'm using the code from the driverlib  "i2c_master_rw_repeated_start-master_code" 

Could you please provide me with some kind of sample code for interfacing RTC ds1307 with msp432p401r launchpad (red) using the i2c protocol.

Thanks.

  • The DS1307 is a 5V device and the datasheet describes the I2C line with pullups to 5V. This will most likely damage the device. Can you confirm how these two devices are connected?

    Just curious, but why are you not using the internal RTC?

    Regards,
    Chris
  • Hi Chris,

    I'm using 3.3V to 5V bidirectional converter between msp432p401r and ds1307 for both SCL and SDA lines.
    I'm using external RTC because the if we power off the msp432 then the RTC(internal) will again get reset to the previous time set in the code and I have to power off the msp432 for every new test to begin again (this code will not be able to edit everytime). And each test requires a time stamp. So I cannot use low power mode of the msp432. And hence I came up with the solution of interfacing external RTC.

    Thanks,
    Sayali.
  • Do you see any issue going through the converter? How many bytes are you transmitting and how many are you receiving after the repeated start?

    Can you check out these links and see if they are applicable?
    e2e.ti.com/.../2721695

    Chris
  • Any updates or additional information on this issue?

    Thanks and Regards,
    Chris
  • Hi Chris,

    I was also trying to interface ds1307 with msp432p401r.

    Above reference helped me to send multiple byte data.

    But still ds1307  is not interfacing with msp432p401r.

    Please go through my code.

    I'm also attaching the pic of SCL and SDA Waveforms.

    Thanks.

    Pic :- Yellow waveform is SCL, Green waveform is SDA.

    CODE:


    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>

    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>

    /* Slave Address for I2C Slave */
    #define SLAVE_ADDRESS 0xD0

    /* Statics */
    //uint8_t TXData[]= {0xD0,0x07,0x10}; // Pointer to TX data
    uint8_t TXData[]= {0xD1,0x04}; // Pointer to TX data
    static uint8_t TXByteCtr;
    static volatile uint32_t xferIndex;
    static volatile bool stopSent;
    static uint8_t RXData[10];
    static uint32_t numOfRecBytes;
    int flag,flag1,i;
    uint8_t SlaveFlag = 0;

    /* I2C Master Configuration Parameter */
    const eUSCI_I2C_MasterConfig i2cConfig =
    {
    EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
    3000000, // SMCLK = 3MHz
    EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 400khz
    0, // No byte counter threshold
    EUSCI_B_I2C_NO_AUTO_STOP // No Autostop
    };

    int main(void)
    {
    volatile uint32_t ii;

    /* Disabling the Watchdog */
    MAP_WDT_A_holdTimer();

    /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function,( UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL)*/
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Initializing I2C Master to SMCLK at 400kbs with no autostop */
    MAP_I2C_initMaster(EUSCI_B0_BASE, &i2cConfig);

    /* Specify slave address */
    MAP_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS);

    /* Set Master in transmit mode */
    MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);

    /* Enable I2C Module to start operations */
    MAP_I2C_enableModule(EUSCI_B0_BASE);

    /* Enable and clear the interrupt flag */
    MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);

    /* Enable master transmit interrupt */
    MAP_I2C_enableInterrupt(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
    MAP_Interrupt_enableInterrupt(INT_EUSCIB0);

    while (1)
    {
    /* Delay between Transmissions */
    for (ii = 0; ii < 10000; ii++);

    /* Load Byte Counter */
    TXByteCtr = 1;

    // /* Making sure the last transaction has been completely sent out */
    // while (MAP_I2C_masterIsStopSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_STOP);
    //
    // /* Sending the initial start condition */
    // MAP_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, TXData[SlaveFlag]);

    while (EUSCI_B0->CTLW0 & EUSCI_B_CTLW0_TXSTP); // Ensure stop condition got sent
    EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TR | EUSCI_B_CTLW0_TXSTT; // I2C TX, start condition

    MAP_Interrupt_enableSleepOnIsrExit();
    MAP_PCM_gotoLPM0InterruptSafe();
    }
    }

    /*******************************************************************************
    * The USCIAB0TX_ISR is structured such that it can be used to transmit any
    * number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
    * points to the next byte to transmit.
    ******************************************************************************/
    void EUSCIB0_IRQHandler(void)
    {
    uint_fast16_t status;

    status = MAP_I2C_getEnabledInterruptStatus(EUSCI_B0_BASE);
    MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE, status);

    if (status & EUSCI_B_I2C_NAK_INTERRUPT)
    {
    MAP_I2C_masterSendStart(EUSCI_B0_BASE);
    }

    if (status & EUSCI_B_I2C_TRANSMIT_INTERRUPT0)
    {
    /* Check the byte counter */
    if (TXByteCtr) //4=0,3=1;2=2,1=3
    {
    /* Send the next data and decrement the byte counter */
    MAP_I2C_masterSendMultiByteNext(EUSCI_B0_BASE,TXData[SlaveFlag]);
    TXByteCtr--;
    SlaveFlag++;
    if (SlaveFlag>3) // Roll over slave address
    {
    SlaveFlag =0;
    }
    }
    else
    {
    flag++;
    MAP_I2C_masterSendMultiByteStop(EUSCI_B0_BASE);
    MAP_Interrupt_disableSleepOnIsrExit();
    MAP_I2C_disableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
    MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE);
    xferIndex = 0;
    MAP_I2C_masterReceiveStart(EUSCI_B0_BASE);
    MAP_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
    }
    }
    if (status & EUSCI_B_I2C_RECEIVE_INTERRUPT0)
    {
    if(xferIndex == 0)
    {
    RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
    numOfRecBytes = RXData[0];
    }
    else if (xferIndex == (numOfRecBytes - 2))
    {
    MAP_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE);
    RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
    }
    else if (xferIndex == (numOfRecBytes - 1))
    {
    RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
    MAP_I2C_disableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
    MAP_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_STOP_INTERRUPT);
    MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
    xferIndex = 0;
    stopSent = true;
    MAP_Interrupt_disableSleepOnIsrExit();

    }
    else
    {
    RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
    }
    }

    }

  • Vivek,
    I am not in a position to review your code. I would recommend starting with two MSP432 launchpads and creating a successful I2C interface with the examples provided and then move to interfacing with other devices. In this way, you can verify that the code is working on the MSP and limit the issue to the other device.

    Regards,
    Chris

**Attention** This is a public forum