Closed jacky4566 closed 4 years ago
The USB device is shut down already as long as there is no USB_VBUS detected. So what you are asking for is already implemented.
Right but how do I check for that in my program? Otherwise nothing gets printed because the device is sleeping.
void setup() {
Serial.begin(9600);
}
void loop() {
if (/*Check for USB*/) {
Serial.println(STM32.getTemperature());
delay(1000);
} else {
STM32.stop(1000);
}
}
VBUS = STM32L0.getVBUS();
On Wed, Oct 9, 2019 at 12:33 PM jacky4566 notifications@github.com wrote:
Right but how do I check for that in my program? Otherwise nothing gets printed because the device is sleeping.
void setup() { Serial.begin(9600); }
void loop() { if (/Check for USB/) { Serial.println(STM32.getTemperature()); delay(1000); } else { STM32.stop(1000); } }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GrumpyOldPizza/arduino-STM32L4/issues/49?email_source=notifications&email_token=ABTDLKUNYPELL5SAGA7DSI3QNYW2JA5CNFSM4I7DWTRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAZB3SQ#issuecomment-540155338, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTDLKQQCZHQHTDEXFQYEWLQNYW2JANCNFSM4I7DWTRA .
We are talking about the L4 here. That function doesn't exist in STM32.h
I found a workaround by changing the variant.cpp file for my board. Changing Null to GPIOB allows me to read the pin. Is there any disadvantage to doing this?
USBConnected = USBDevice.connected(); on L4...
Great that seems to work. This should be in the documentation.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, USBDevice.connected());
}
Is there a method to check for USB_VBUS?
I see it is tied to GPIO_PIN_PB2. I tried to read pin 27 but it just returns false.
My intention is to shutdown the device when USB is not connected.