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.

MSP432P401R: VL6180X Proximity Sensor I2C Problem

Part Number: MSP432P401R

Hi all,

I am attempting to interface my MSP432P401R MCU with a VL6180X proximity sensor on a breakout board purchased from Adafruit. I have gotten it working with an Arduino and the library provided by Adafruit. When I attempt to use the sensor with the MSP432, I can read the registers using I2C. However, I am encountering an error with the sensor that says I have a "VCSEL Continuity Error". I am not sure what this means, but because I am able to successfully read the registers from the sensor, I have to assume that I am having issues writing to the registers on the sensor. Does anyone have experience with this particular sensor?

  • If there's a concern about whether writes are "sticking", the first thing I'd do is add something to the "write register" function which immediately reads the register back and sees if it matches. There may be some registers where this doesn't work, but I expect most do.

    I see Adafruit's ::init method writes a bunch of registers without much explanation. Are you doing all those?
  • The first thing I'd suggest aside from the readback is to get a logic analyzer and verify that you are generating the same kind of traffic on the MSP432-based code as on Arduino. Do you have that capability?
    -Bob L.
  • Hi Bruce,

    Thanks for looking into the library. Yes, I am writing all of those registers. Though they don't offer explanations in the Arduino library, STMicroelectronics (the manufacturer of the VL6180X) has documentation available on their website such as datasheets and C libraries that explain that those are private registers that need to be written for proper initialization of the sensor.

    I have tried reading back some of those libraries after I have written them and I keep getting 0 as output. I guess this means that I'm not writing the registers correctly.

    However, I'm not sure what is going wrong. When I read from a register, I have to write to the sensor first with the correct register address. I'm pretty sure I'm doing the read operation correctly because I can correctly get the device ID from the 0x0000 register. Additionally, when I do my write operation, I use

    int configRegWriteInitVL(uint16_t reg, uint8_t data) {
        MAP_I2C_setSlaveAddress(EUSCI_B1_BASE, VL_6180X_ADDR);
        printf("writing\n");
        MAP_I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
    
        uint8_t regLSB = reg & 0xFF;
        uint8_t regMSB = reg >> 8;
        int result = false;
        MAP_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, regMSB);
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, regLSB);
        result = MAP_I2C_masterSendMultiByteFinishWithTimeout(EUSCI_B1_BASE, data, TEMP_TIMEOUT);
        printf("write result: %d\n", result);
        return result;
    }

    and when I am writing the registers, it prints out "write result: 1" for all of the write operations, which indicates that the writes were completed successfully. Do you have any insights on what could be going wrong?

  • Hi Bob,
    Thanks for responding. I do not believe I have access to a logic analyzer. I do have access to oscilloscopes, but a quick search on Google makes me think that the oscilloscope isn't as good for this kind of analysis. Do you think I can use an oscilloscope?
  • I should also note that this is what my read operation looks like: 

    uint8_t configReadRegVL(uint16_t reg) {
        int result = false;
        uint8_t range = 0;
        uint8_t regLSB = reg & 0xFF;
        uint8_t regMSB = reg >> 8;
    
        MAP_I2C_setSlaveAddress(EUSCI_B1_BASE, VL_6180X_ADDR);
        MAP_I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
    
        MAP_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, regMSB);
        result = MAP_I2C_masterSendMultiByteFinishWithTimeout(EUSCI_B1_BASE, regLSB, TEMP_TIMEOUT);
    
        if (result == true) {
            printf("vl read success\n");
            MAP_I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_MODE);
    
            range = MAP_I2C_masterReceiveSingleByte(EUSCI_B1_BASE);
            printf("regvalue: %d\n", range);
        }
    
        return range;
    }

    Additionally, the "unexplained write operations" you mentioned that appeared in the Adafruit library are initializers that written when the device is reset. Thus, theoretically, if I use the sensor with the Arduino first and then don't use the initializers when I use the sensor with the MSP, the sensor should already be initialized correctly. However, I did that and it still gives me the VCSEL error. I don't know if this information helps or makes the problem even more complicated.

  • A scope can be used to analyze I2C traffic, but it requires rather more time/patience.

    Here's another thought: Looking through the Adafruit code and the RangeSingleShot example, I don't see anything that actually checks register RESULT__RANGE_STATUS (0x4D). What happens if you just ignore the error code and press on? Do you get reasonable results?
  • Hi Bruce,

    Thanks for looking through the Adafruit documentation. The register RESULT_RANGE_STATUS (0x4D) is checked in the readRange() method in the Adafruit library. I have attempted to ignore the error code before I posted on the forum, and the sensor returns a value of 0 for every measurement.

  • Sorry, I had the wrong code.

    UM1983 Table 6 seems pretty emphatic: "This error can only happen at the first boot-up. Device needs to be reset to clear the error. If the error persists, then device is defective and must be replaced." They make it sound like it's independent of setup. The device/board might be broken, but that's a rarity in my experience.

    1) It might be worth wiggling the GPIO0 (SHDN) pin to reset it (wait 1ms for it to start). I'm not very optimistic, but it seems like a quick experiment -- maybe just short it briefly to GND with a piece of wire before you start your program.
    2) If you read this register before any other setup, what do you get?

    "VCSEL Continuity" makes it sound like a power flaw (AVDD_VCSEL). How are you connecting VIN? The MIC5225 claims <0.3V dropout, but you might try powering it from the (Launchpad) 5V pin anyway. Peak current is 38mA, which I expect the Launchpad can handle.
  • Hi Bruce,

    Sorry for the delayed response. I did not go into school over the weekend and I forgot to take the sensor home with me. I tried wiggling the GPIO0 (SHDN) pin to reset it before the program started and the same error occurred.

    I also read the register before doing any setup and interestingly enough, it returned 0x01 which means no error. However, immediately after that, I read the device ID register and it returned the wrong value. Then, when I read the problematic register again, it returned the VCSEL Continuity error. I tried doing the above steps with wiggling the SHDN pin and not wiggling the SHDN pin, and the same thing occurred both times.

    I also tried using the 5V output on the Launchpad and I still got the same error.

    I really appreciate the effort you're putting into helping me but right now, it's looking like this is an error that can't be fixed. Sorry for wasting your time.

  • Maybe it's worth asking over at the Adafruit forum. Someone might recognize the symptom (particularly if it's really broken).
  • Phillip,
    The LaunchPad has a 5V SUPPLY pin (from the USB 5v supply). It does not have a 5v output. What exactly are you connections? Do you have a schematic or drawing you could post?
    -Bob L.
  • Phillip,
    Do you have any further response on this? Are you still working this issue or should I close the post?
    -Bob L.
  • Hi Bob,

    Sorry for the lack of response. It turns out that the sensor sometimes works if I toggle the reset pin. This has a very low success rate and doesn't really help too much. I am not sure what to do from here, but I got it working for long enough to finish my class project. Thanks for all the help!

**Attention** This is a public forum