boardDetectVBus causes green LED to flash

Hi

just been trying to track the source of a very short flash on the green LED, when there’s no calls to LED_GREEN(1)

looks like it’s inside boardDetectVBus, where it calls

    BIT savedState = (P2DIR >> 4) & 1;
    if (savedState == 0)
    {
        P2DIR |= (1<<4);       // Drive the VBUS_IN low
        delayMicroseconds(2);
    }

from board.h

#define LED_GREEN(v)        {((v) ? (P2DIR |= 0x10) : (P2DIR &= ~0x10));}

so both functions are hitting the same bit in P2DIR.

Is this intentional? Why flash the green LED for 2 mics in order to detect power on the bus? The comment is a bit confusing, since it says Drive VBUS_IN low, but when it undoes that later in the func, it says “LED was on previously…”.

also

    P2DIR &= ~(1<<4);          // Make the line an input.

??? that’s the same code as turning off the green LED? Is it maybe the wrong bit being used here?

thanks

Adrien

also, it depends on getMs(), which is not returning milliseconds for me, but more like minutes. I read some discussion about sleep modes (e.g. PM2), but I didn’t think I was using that, unless the radio_queue code is doing it?

thanks

p.s. reason I’m trying to even bother doing anything about this is I’m trying to reduce power in the wixel, since in my application it’s being powered off a phone (OTG cable).

Still working on most efficient way to receive packets when you don’t know when the first one is coming… need WOR in efficient low power mode.

The Wixel uses a single I/O line to detect VBUS and also control the green LED, so that explains the code and the blinking you are seeing. You can see how the Wixel pins are connected in the “Schematic Diagram” section of the Wixel User’s Guide.

The boardDetectVbus function uses getMs to make sure that we are not checking for VBUS too often, because that would make the green LED appear dimly lit. If you want to save power then you might consider rewriting boardDetectVbus so it just assumes VBUS is always connected without actually checking. There should not be any real problem with that, especially if USB is always connected in your application.

The radio_queue library does not currently do anything with sleep modes.

If you want help figuring out why getMs is giving you minutes instead of milliseconds, please make the simplest possible Wixel app that reproduces the problem and post it here, along with a description of the expected output and the actual output.

–David

Hi David

thanks for that suggestion. Since we are solely powered by USB, then when the plug is disconnected, we’re gone anyway, so I think we can probably just comment out the checking. Doesn’t look like it checks the value of that bit that’s set anywhere either.

We have a bitbucket repo with the source in it, it includes a small number of mods to the library (to enable us to change radio parameters without changing the library). I can share it to you if you want - it’s only a single file. We connect to it with hyperterm (couldn’t get putty working on win8.1) and poll with a HELLO, and it reports current result of getMs() amongst a couple other lines.

It’s strange, some other usage of getMs seems to not break on this as I’d expect it to.

Again, if you want help figuring out why getMs is giving you minutes instead of milliseconds, please make the simplest possible Wixel app that reproduces the problem and post it here, along with a description of the expected output and the actual output. This means that instead of posting your entire app, you should simplify it as much as possible. It should probably be less than 30 lines long. As you have pointed out, the getMs function works in other contexts, so the problem is most likely with your code. The process of simplifying will help us narrow down exactly what part of your code is causing trouble. You might start by adding a very simple serial command to your app that just returns the current value of getMs(), and then slowly remove all the other features of your app.

–David

Hi David

sorry, need to eat my hat on this.

Problem was a stupid printf format specifier. I was printing getMs() using just %u, but it has to be %lu, since it’s 32 bit, so it was being truncated.

So it’s working for now, although I’ve heard there are issues once you start using PM2 or PM3, which I’m not doing yet

Thanks!