I am using an arduino mega ADK and am trying to connect with a slave device over usb. I am finding that the connection is really difficult to obtain and only works a small amount of the time. For now, I am just looking at the USBFTDILoopback example included in the repo. In the sketch I have only changed the baud rates and the message I wish to send. I have set the mega adk define in settings.h to 1, changed the number of LUN devices to 1 and enabled spi4teensy3 driver.
#define USE_UHS_MEGA_ADK 1 #ifndef MASS_MAX_SUPPORTED_LUN #define MASS_MAX_SUPPORTED_LUN 1 //8 #endif //////////////////////////////////////////////////////////////////////////////// // Set to 1 to use the faster spi4teensy3 driver. //////////////////////////////////////////////////////////////////////////////// #ifndef USE_SPI4TEENSY3 #define USE_SPI4TEENSY3 1 #endif
When I do get it to connect this it what I get printed
Start FTDI Init Addr:01 NC:01 0000: 09 02 20 00 01 01 00 A0 2D 09 04 00 00 02 FF FF 0010: FF 02 07 05 81 02 40 00 00 07 05 02 02 40 00 00 Conf.Val: 01 Iface Num: 00 Alt.Set: 00 Endpoint descriptor: Length: 07 Type: 05 Address: 81 Attributes: 02 MaxPktSize: 0040 Poll Intrv: 00 Conf.Val: 01 Iface Num: 00 Alt.Set: 00 Endpoint descriptor: Length: 07 Type: 05 Address: 02 Attributes: 02 MaxPktSize: 0040 Poll Intrv: 00 NumEP:03 Conf:01 baud_value:809C baud_index:0000 FTDI configured
I can then send my command and receive a correct reply with no issues.
Most of the time however, the USBTaskState is 0xA0 (USB_STATE_ERROR) and I dont get any connection. As far as I can tell this gets raised in usb.Task() after running usb.Configuring().
Some of the time it will also just hang or get stuck in some other state.
I have tried disabling the spi4teensy3 driver but then I can't connect at all.
when i run the USB descr sketch I get the following
-- Device descriptor: Descriptor Length: 12 Descriptor type: 01 USB version: 0200 Device class: 00 Device Subclass: 00 Device Protocol: 00 Max.packet size: 08 Vendor ID: 0403 Product ID: 6001 Revision ID: 0600 Mfg.string index: 01 Prod.string index: 02 Serial number index: 03 Number of conf.: 01 Configuration descriptor: Total length: 0020 Num.intf: 01 Conf.value: 01 Conf.string: 00 Attr.: E0 Max.pwr: 00 Interface descriptor: Intf.number: 00 Alt.: 00 Endpoints: 02 Intf. Class: FF Intf. Subclass: FF Intf. Protocol: FF Intf.string: 02 Endpoint descriptor: Endpoint address: 81 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 02 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Addr:1(0.0.1)
What am I doing wrong? is there something else I need to change/enable/edit somewhere to get the code to work reliably?
Also, as a side question: sometimes when using a library I have written to communicate with my usb device, along with a bunch of other code that's running, my code restarts. I'm guessing it's an issue with RAM or with my arrays because when I don't use USB everything runs fine. Do you have any suggestions for reducing RAM usage with USB? I don't use the String class, command strings are stored as const uint8_t arrays
Thanks for any help