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.

MSP432 and I2C configuration

Other Parts Discussed in Thread: BOOSTXL-EDUMKII

Hi, 

I'm using a MSP‑EXP432P401R development board with a booster pack EDU MK II.
I noticed some problem with the example software with the I2C configuration, I had to add some __delay_cycles to make it work.

Someone know why ?

Thank you

After:

/* Initialize I2C communication */
    Init_I2C_GPIO();
    __delay_cycles(10000); // bus busy bug
    I2C_init();
    /* Initialize OPT3001 digital ambient light sensor */
    OPT3001_init();
    __delay_cycles(10000);

Before:

/* Initialize I2C communication */
    Init_I2C_GPIO();

    I2C_init();
    /* Initialize OPT3001 digital ambient light sensor */
    OPT3001_init();
    __delay_cycles(100000);

  • Hi Tommaso,

    I tried the BOOSTXL-EDUMKII LightSensor BoosterPack Example on the MSP432 + Educational BoosterPack MK II, and it worked fine without adding the delay. The lux value was shown on the LCD and changed according to the applied brightness. I found this example in CCS under TI Resource Explorer in MSPWare -> Development Tools -> MSP-EXP432P401R -> BoosterPack Examples. Perhaps you're using an older version of MSPWare? I'm using version 3_30_00_18.

    Here's the example code for your reference.

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    //****************************************************************************
    //
    // main.c - MSP-EXP432P401R + Educational Boosterpack MkII - Light Sensor
    //
    //          Displays lux value measured by the OPT3001 Digital Ambient
    //          Light Sensor on the colored LCD. The MSP432 communicates
    //          with the sensor through I2C.
    //
    //          The ambient light measurement is also used to automatically
    //          adjust the LCD backlight.
    //
    //      *** Make sure J5 jumper on the BOOSTXL-EDUMKII is connected ***
    //          to 3.LCD BACKLT
    //
    //****************************************************************************
    
    #include "msp.h"
    #include <driverlib.h>
    #include <grlib.h>
    #include <HAL_I2C.h>
    #include <HAL_OPT3001.h>
    #include "Crystalfontz128x128_ST7735.h"
    #include "HAL_MSP_EXP432P401R_Crystalfontz128x128_ST7735.h"
    #include <stdio.h>
    
    /* Graphic library context */
    Graphics_Context g_sContext;
    
    /* Variable for storing lux value returned from OPT3001 */
    float lux;
    
    /* Timer_A Up Configuration Parameter */
    const Timer_A_UpModeConfig upConfig =
    {
            TIMER_A_CLOCKSOURCE_ACLK,               // ACLK Clock SOurce
            TIMER_A_CLOCKSOURCE_DIVIDER_1,          // ACLK/1 = 3MHz
            200,                                    // 200 tick period
            TIMER_A_TAIE_INTERRUPT_DISABLE,         // Disable Timer interrupt
            TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE,    // Disable CCR0 interrupt
            TIMER_A_DO_CLEAR                        // Clear value
    };
    
    /* Timer_A Compare Configuration Parameter  (PWM) */
    Timer_A_CompareModeConfig compareConfig_PWM =
    {
            TIMER_A_CAPTURECOMPARE_REGISTER_3,          // Use CCR3
            TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE,   // Disable CCR interrupt
            TIMER_A_OUTPUTMODE_TOGGLE_SET,              // Toggle output but
            100                                         // 50% Duty Cycle
    };
    
    /*
     * Main function
     */
    void main(void)
    {
        /* Halting WDT and disabling master interrupts */
        MAP_WDT_A_holdTimer();
        MAP_Interrupt_disableMaster();
    
        /* Initializes Clock System */
        MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
        MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
        MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
        MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
        MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    
        /* Initializes display */
        Crystalfontz128x128_Init();
    
        /* Set default screen orientation */
        Crystalfontz128x128_SetOrientation(0);
    
        /* Initializes graphics context */
        Graphics_initContext(&g_sContext, &g_sCrystalfontz128x128);
        Graphics_setForegroundColor(&g_sContext, GRAPHICS_COLOR_RED);
        Graphics_setBackgroundColor(&g_sContext, GRAPHICS_COLOR_WHITE);
        GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
        Graphics_clearDisplay(&g_sContext);
        Graphics_drawStringCentered(&g_sContext,
                                        "Light Sensor:",
                                        AUTO_STRING_LENGTH,
                                        64,
                                        30,
                                        OPAQUE_TEXT);
    
        /* Configures P2.6 to PM_TA0.3 for using Timer PWM to control LCD backlight */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN6,
                GPIO_PRIMARY_MODULE_FUNCTION);
    
        /* Configuring Timer_A0 for Up Mode and starting */
        MAP_Timer_A_configureUpMode(TIMER_A0_BASE, &upConfig);
        MAP_Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE);
    
        /* Initialize compare registers to generate PWM */
        MAP_Timer_A_initCompare(TIMER_A0_BASE, &compareConfig_PWM);
    
        /* Initialize I2C communication */
        Init_I2C_GPIO();
        I2C_init();
    
        /* Initialize OPT3001 digital ambient light sensor */
        OPT3001_init();
    
        __delay_cycles(100000);
    
        while(1)
        {
            /* Obtain lux value from OPT3001 */
            lux = OPT3001_getLux();
    
            char string[20];
            sprintf(string, "%f", lux);
            Graphics_drawStringCentered(&g_sContext,
                                            (int8_t *)string,
                                            6,
                                            48,
                                            70,
                                            OPAQUE_TEXT);
    
            sprintf(string, "lux");
            Graphics_drawStringCentered(&g_sContext,
                                            (int8_t *)string,
                                            3,
                                            86,
                                            70,
                                            OPAQUE_TEXT);
    
            /* Adjust LCD Backlight */
            if (lux < 2000)
                compareConfig_PWM.compareValue = ((2000*0.1) + (lux*0.9))/2000 * 200;
            else
                compareConfig_PWM.compareValue = 200;
            Timer_A_initCompare(TIMER_A0_BASE, &compareConfig_PWM);
        }
    }
    

    Hope this helps.

    Regards,

    James

    MSP Customer Applications

  • I'm using your configuration, hardware and software. 

  • Using the code above, are you still encountering the issue? Hopefully it was fixed, but I wanted to make sure before closing the thread.

    Regards,

    James
    MSP Customer Applications
  • Hi Tommaso,

    I've closed the thread, but feel free to reply if you have any more related questions.

    Regards,

    James
    MSP Customer Applications

**Attention** This is a public forum