|Purpose||Use in other project|
USBTinyISP is a project based on a software USB implementation on the Atmel ATTINY2313 by Dick Streefland, http://dicks.home.xs4all.nl/index.html
USB was invented for usb.org by the late Brad Hosler, http://www.usb.org/inmemory It is by far the most successful standard is the consumer electronics industry, supporting all operating systems and many devices.
USB comes in several speeds: Initial 1.1 spec:
- 4 mbps (low speed)
- 12 mbps (USB 1.1 'full' speed)
USB 2.0 spec:
- 480 mbps (USB 2.0 high speed)
USB 3.0 spec:
- 5 gbps (USB 3.0, using 2 new pairs with new SERDES scheme)
The speed is determined by the hostcontroller, which is integrated in the PC's chipset. The hostcontroller implements busmastering DMA with chains of buffers, can be quite efficient. Depending on driver quality latency down to a few msec can be reached. USB works with a SOF packet every millisecond. Within such frame, every endpoint on a device gets only one chance of attention. Devices are slaves and must respond to packets within a few usec.
Atmel Datasheet + instruction set: http://www.atmel.com/Images/doc2543.pdf
The UsbTinyIsp can be forced via nifty software to pretend to be a low speed USB device, http://www.adafruit.com/products/46 On the AdaFruit circuit, apparently it can get away with a simple ceramic resonator instead of a 12 MHz crystal for the clocking. The clock speed seems to be a quite a bit off, but the host does communicate.
On the AdaFruit preprogrammed chip, the following USB commands are implemented:
- Device signals plugin + low speed back to host (device pulls up D- signal with 1k5 pullup to 3V3 (on sample circuit 5V was taken -> different current, but seems to work...). See USB Specification chapter 5.
- Detection of SE0 reset (host drives both D+ and D- low -> SE0 bus state, held for few msec means RESET). After this, the D- pullup takes over again.
- Bit decoding on incoming packet (using NRZ decoding on the fly)
- After EOP is detected, packet can be processed without the software need to pay attention to the USB bus
- C code parses the packet and prepares a packet to be sent back
- The device does Bit encoding for the return packet (using NRZ encoding on the fly, a DATA packet or a ACK/NAK packet)
USB Chapter 9 (identification of USB devices in lower software layers)
- GetDescriptor(device, string, configuration)
The actual device-specific functionality is also implemented on basis of SETUP packets, targetted at endpoint 0 Followed by an IN packet (back to host) and empty OUT packet that needs to be acked as well. Setup packet fields:
- Request: uint8
- wValue: uint16
- wIndex: uint16
- wLength: uint16
SPI with the UsbTinyIsp
For external SPI transfers, Vendor Request In (0x07) can be used. it accepts no more than 4 bytes, that are put in wValue c1c0,wIndex c3c2). There is no chip-select, and no way of controlling other peripherals on the SPI bus (reset). There are not enough IO buffers on the board to convert the 5V rails of the TINY2313 to the target level (VDDext = 3V3). To work around this, I want to use a simple diode.
First investigation is outputting a clock and bytes, and verify this on the scope. The SPI clock coming out of my tinyISP it looks very distorted - it looks almost like the normal slow clock of ca 10 kHz was interrupted by a 40 kHz clock.
Bitbanging SPI with the UsbTinyIsp
It might be possible to use bitbanging using some other USB commands implemented in the TinyISP.
USBTinyIsp hardware mods
- Use remaining IO's for other purposes, with bit set/clear register read/write addressing on PC side.
- Use an extra buffer to control an external chipselect, or external reset signal of a target chip
- Use a real 12 MHz crystal and see if this has any impact on reliability on some OS'es
- Use a voltage divider to get the 1k5 pullup current right. It might draw too much current from VBUS - spec states it should be 2.5 mA on powerup, and up to 100-500 mA once SetConfiguration() is called