ATTiny85/Digispark DigiUSB/DigiCDC makes P3/P4 pins unusable?

DigiUSB and DigiCDC are the two modules that enable user-defined host-device communication over the USB connector from both sides for Digispark. However, when either of two is enabled, pins P3 and P4 cannot be claimed for use. Attempted use of pinMode(3, OUTPUT); results into errors in the USB device detection on the host side, like usb usb2-port2: unable to enumerate USB device. There is definitely some interference between DigiUSB/DigiCDC and pins availability, but it remains unclear and docs/readme do not mention anything. So, what's going on here?

The docs mentioned P3/P4 pins are somehow involved in USB programming as well. I understand it as one could possibly wire D+ and D- USB lanes to P3/P4 and have the communication through them instead of the miniUSB connector. So, it could be possible that DigiUSB/DigiCDC enables USB connection for both miniUSB and P3/P4 at the same time. Nonetheless, I hope they still could be reclaimed as normal digital pins by disabling some switches in DigiUSB/DigiCDC.

Call void DigiCDCDevice::end(void) when you want to free Pin 3 and Pin 4 for your own purposes. You can call .begin() again when you want to use USB again. It will be up to you to make sure that whatever you connect to Pin 3 or Pin 4 doesn't interfere with USB.

Thanks @johnwasser this could be a solution for someone. But I really want to have P0/P1/P2/P3/P4 available permanently to my code, while the DigiUSB is running through the microUSB port. Is there any particular limitation for doing just that?

I've noticed USB_CFG_DMINUS_BIT and USB_CFG_DPLUS_BIT are indeed doing something to P3 and P4. Maybe this line PORTB &= ~(_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DPLUS_BIT)); is for claiming the pins, and could be disabled?

You can't do that. The MicroUSB port is connected to Pin 3 and Pin4 and you can't use those pins for other stuff at the same time you are using USB.

Maybe you need a processor with more pins, like an ATtiny84.

1 Like

Digispark and Adafruit Trinket are very similar in use of V-USB bitbanging to achieve USB. In the Adafruit line, they have a Trinket Pro that uses the atmega328.

Adafruit Pro Trinket - 5V 16MHz : ID 2000 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.