Go Down

Topic: Atmega 32u4 and VBUS/sleep mode (Read 1 time) previous topic - next topic

batelfront2

Hello,
For a project we first used an Arduino Leonardo and now we have built our own.
For the tests we are working on the sparkfun promicro board.
Our problem deal with the USB functionalities. We want to put the atmega in eco power mode and wake it up by an external interruption or by the interrupt vector of the usb.
But when i set the VBUSTE bit of the USBCON register the atmel isn't recognized any more by the computer, and the flag VBUS doesn't rise ( Full_Bat_Warn() doesn't launch).

Here the main part of the program:

Code: [Select]
void setup()
{
  Init_io();  // Input and output setup
  Init_PWM();//Init for the battery charge
  Init_Accelerometer(INT_PIN_ACCEL);
 
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  USBCON |= _BV(VBUSTE);
  delay(1000); //delay for connect via USB before sleep_mode()
}
void loop()
{
  char motion;
  char Shake;
  static char mode = OFF_MODE;
 
  if(Update_Motion_Flag){
    Update_Motion_Flag = 0;
    Shake = Detect_Motion(&motion);
  }
  switch (mode)
  {
    case OFF_MODE :
       enterSleep();
        if(Shake)
        {
          if(VBUS)
            Full_Bat_Warn();
          mode = NORMAL_MODE;
        }
    break;
   
    case CHARGE_MODE :
        Charge_control();
    break;
   
    case LOW_B_MODE :
    break;
   
    case NORMAL_MODE :
      if (state_Batterie()==EMPTY)
      {
         Low_Bat_Warn();
         mode = OFF_MODE;
         break;
      }
      mode = Launch_Normal();
    break; 
  }
}

void enterSleep(void)
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 
  sleep_enable();
 
  sleep_mode();
 
  /* The program will continue from here. */
 
  /* First thing to do is disable sleep. */
  sleep_disable();
}

Go Up