B@tto 51 Posted May 10, 2016 Share Posted May 10, 2016 Hi, 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 ... Regards 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. Quote Link to post Share on other sites
B@tto 51 Posted May 13, 2016 Author Share Posted May 13, 2016 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 ? Quote Link to post Share on other sites
chicken 630 Posted May 13, 2016 Share Posted May 13, 2016 From my notes, the USB peripheral on the F55xx only works down to LPM0. sleepSeconds() goes all the way down to LPM3, i.e. disables the USB peripheral. Fmilburn 1 Quote Link to post Share on other sites
chicken 630 Posted May 13, 2016 Share Posted May 13, 2016 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()) { [..] case ST_ENUM_SUSPENDED: // 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. break; But I have a hard time finding more specific documentation. Also not sure how to craft this into an Energia project. Quote Link to post Share on other sites
colotron 5 Posted May 14, 2016 Share Posted May 14, 2016 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 THERE_IS_USB_MODULE if( ST_USB_DISCONNECTED != USB_getConnectionState() ) sleepMode = LPM0_bits; #endif .... //sleep //__bis_SR_register(LPM0_bits + GIE); //enable interrupts when sleeping __bis_SR_register(sleepMode + GIE); //enable interrupts when sleeping __no_operation(); Fmilburn 1 Quote Link to post Share on other sites
B@tto 51 Posted May 16, 2016 Author Share Posted May 16, 2016 Hi, 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 { mySleepSeconds(BIG_SLEEP); } 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 LPM3; TA0CTL=MC_0; // stop timer enableWatchDogIntervalMode(); } void enableWatchDogIntervalMode(void) { #if F_CPU < 8000000L WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDT_MDLY_0_5; #else WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDT_MDLY_8; #endif /* WDT interrupt enable */ #ifdef __MSP430_HAS_SFR__ SFRIE1 |= WDTIE; #else IE1 |= WDTIE; #endif } #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER0_A0_ISR(void) { LPM3_EXIT; } 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. Quote Link to post Share on other sites
dubnet 238 Posted May 16, 2016 Share Posted May 16, 2016 Not sure if this is possible due to your design constraints, but why not sense the USB power rail to generate an interrupt (some type of one shot as the power comes up)? Then continue to monitor the power rail in your loop and when it disappears go back to sleep. Fmilburn 1 Quote Link to post Share on other sites
B@tto 51 Posted May 16, 2016 Author Share Posted May 16, 2016 It's what is done in fact but the main problem is interruptions are already managed by USBSerial.h, so you can't duplicate it in your code. But hopefully, ISR on VBUS on call a LPM3_EXIT Quote Link to post Share on other sites
dubnet 238 Posted May 16, 2016 Share Posted May 16, 2016 Should have read the thread a little closer, missed the contention issue. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.