USB VBUS monitor input doesn't work

Dear friends

In my application I need to detect if the USB port is plugged to the board. I used a piede of code (see below) that works fine with Arduino Pro Micro 5V, but from another brand (not from Sparkunf). I need this function for checking if the USB port is plugged to my laptop, and starting a communication task. As you can see, I take advantage of the hardware connected VBUS pin from the ATmega32u to the VBUS1 terminal in the USB connector through the UVCC net (see schematics: https://cdn.sparkfun.com/datasheets/Dev … o_v13b.pdf)

The problem arise when using an Arduino Pro Micro 5V form Sparkun (https://www.sparkfun.com/products/12640). The applications works ok, but not the commented function. The USB - laptop communication is ok, but bypassing that function.

Furthermore, when I remove the Sparkfun unit from my circuit and use the other board from another brand, the function works fine (it detects if the board is still plugged into USB).

This is the function I use:

int8_t Check_USB()
{ // check if USB is plugged. Return: 0= USB plugged, -1== USB not plugged
	USBCON|= 0x10; //(1<<OTGPADE); // enable VBUS pad
	if ((USBSTA & 1) == 0 ) // USBSTA.VBUS== 0: USB not plugged
	{
		if(Serial) // then close any Serial port
		{
			Serial.end();
		}		
		return -1; // returning USB not plugged
	}
	else  // bit VBUS==1: USB plugged
	{
		if(!Serial) // Start comm
		{
			Serial.begin(9600);
			while(!Serial); // waiting for comm
		}
		// Clear buffer
		while(Serial.available())
		{
			Serial.read();
		}
	}
	return 0; // USB plugged
}

I checked also the connection in the PCB layout, but I couldn’t find any problem.

Any recommendation to solve the problem?

Thanks in advance

I’m wondering if something in the bootloader we use or how we set the fuses on our board is what’s causing your issue. You might compare both boards and see what’s different. Start with the bootloader from the other board and see if that corrects it, if not, check the fuses.

Thank you for responding so quickly.

I have never had to change the fuses, nor the bootloader, so I wouldn’t know how to check or do it. For that, I would like you to point me to some reference, please.

I’m afraid we don’t have any kind of guide for this, it’s pretty advanced stuff. More than you really would be doing inside the Arduino IDE anyway.

Thanks anyway.

In any case I don’t think it has to do with the fuses: both boards have been programmed from IDE version 1.8.13, and in particular the Sparkfun board has been programmed with Sparkfun Pro Micro configuration. I think it must be a problem with the factory bootloader, so I kindly ask you to employ that code (or similar) to detect if the USB cable is plugged.

I’ll put in a request, but I can’t guarantee it will get changed. :frowning: