Jump to content

USB and low power

Recommended Posts



I have a project of data logger based on F5510 and I want it sleeping when USB is not connected. My question is pretty simple : if I use USBSerial library, do I have a special thing to do it (except play with sleep() commands of course)?


First I thought that I would have to play with begin() and end() to activate/deactivate USB peripheral to go low power, but after all, if VBUS is not present, USB can't work ?


In the end it would just consist in a flag I would add in the library, but if I can do it without any modification it would be a good thing ... :)




EDIT : another precision in my demand : I want to be in sleep mode when USB is not connected (a lithium battery supply the module when usb is not connected). What's the best way ? A simple if(!(USBCNF&USB_EN)) sleep(500) ?


EDIT 2 : so I made some tests, using USBCNF&USB_EN is a good logic test :) but I found another problem : it does not work if I use sleepSeconds() (sleep() is OK). Any idea ? I looked into USBSerial lib + wiring.c but I did not find anything that could cause that.

Link to post
Share on other sites

EDIT2 : using USBCNF&USB_EN works, but Ifound another problem. If I use sleep() it's OK, but not with sleepSeconds(). I looked into USBSerial lib and wiring.c but I could not anything. Apparently, in sleepSeconds() no USB interrupt are managed (device not recognized by PC, "device unknown" or completely deconnected). Any idea ?

Link to post
Share on other sites

PS: It looks like USB does support LPM3 (or even LPM4?) if the USB connection is suspended (e.g. when the PC goes into sleep).


From an example in MSP430ware usblib:

switch(USB_connectionState()) {
             // This state indicates  the device is enumerated on a USB host, but the host has suspended it.  The device is
             // not allowed to draw more than 2.5mA from VBUS during this time, and thus the main loop might look different
             // than it did during ST_ENUM_ACTIVE.  It's recommended to insert code into handleSuspendEvent() (or here)
             // that disables any circuitry drawing excessive current from VBUS.  During suspend, the power mode may enter
             // LPM3 or LPM4.
             __bis_SR_register(LPM3_bits + GIE);            // Enter LPM3, until a resume or VBUS-off event
             // Here, write the main loop for how the device should behave when USB is disconnected. 

But I have a hard time finding more specific documentation.


Also not sure how to craft this into an Energia project.

Link to post
Share on other sites

PS: It looks like USB does support LPM3 (or even LPM4?) if the USB connection is suspended (e.g. when the PC goes into sleep).



Yup, you can only go to LPM0 with USB active.

That's because the USB host (the computer) sends periodically package polling if the slave (msp430f5510) have something to read or to write.

Then, you always need the capability to get polling packages from the host, and answer those (NAK if you don't have nothing to do, but still sending something).

And to talk with the host you need the USB oscillator/clock working, so you can't shutdown the clock system further.

See Programmers_Guide_MSP430_USB_API.pdf 11.1.6 Use of Low-Power Modes


Also not sure how to craft this into an Energia project.



In your sleep/timing function of interest you should check out the usb state -for msp430 parts with usb module- using USB_getConnectionState().


I guess something like:

//Add to your function of interest
int sleepMode = LPM3_bits;
if( ST_USB_DISCONNECTED != USB_getConnectionState() )
  sleepMode = LPM0_bits;
//__bis_SR_register(LPM0_bits + GIE);    //enable interrupts when sleeping
__bis_SR_register(sleepMode + GIE);    //enable interrupts when sleeping
Link to post
Share on other sites



thanks for your answers.


@@colotron : maybe you misunderstood my problem. I do not want the MSP to be sleeping and connected by USB, I want it to be sleeping when it's not connected, and it is able to manage usb when it's connected.


Finally I did not mesure current consumption, but I have something working, but I don't know exactly why it does not work with sleepSeconds(). First I noticed that LPM3 is not a problem. I simply used LPM3 command in parallel with USB functions and everything work. Finally I wrote my own routines to manage sleeping :

    if((USBCNF&USB_EN)) {
      manageSerial(); // here I manage my Serial stuff (order from computer etc ...)

    } else {



And :

void mySleepSeconds(uint32_t seconds)
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  TA0CCTL0 |= CCIE; //Enable Interrupts on Timer
  TA0CCR0 = seconds*(32768/8UL); //Number of cycles in the timer
  TA0CTL |= TACLR + TASSEL_1 + MC_1 + ID_3; //Use ACLK as source for timer UP mode timer


  TA0CTL=MC_0; // stop timer


void enableWatchDogIntervalMode(void)
#if F_CPU < 8000000L

  /* WDT interrupt enable */
#ifdef __MSP430_HAS_SFR__
  IE1 |= WDTIE;

#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)

So I stop the watchdog (the interruptions from WDT doesn't allow to sleep), I configure a timer to wakeup clocked by ACLK and go LPM3. On wake up, timer is stopped WDT is re-enabled.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...