I captured the usb packets on a usb1.1 mouse using a generic 24mhz logic analyzer.

here is the sigrok capture for the first token.

as per the usb docs.. a CRC5 is calculated for the token by taking into account the address(7bits) and endpoint(4bits) fields.

since both the addr and endp are zero for this transaction, the 11 bits are – 00000000000 so the crc calculated by the crc5 polynomial( 100101) should give zero, but i'm not able to understand that the crc field is 0x2.

now for a different transaction.. after the host has allocated address to the device.

fields are–

addr – 11;

endp – 0;

so, from the datasheet(pg 173), the final 11 bit field is – 11010000000 . when crc5 is calculated on this field.. it gives 4 which matches correctly with the crc field.

I used the long division method to calculate the crc.

am i miscalculating the crc for the first token?

## Best Answer

The USB CRC5 uses an initial shift register value of 11111b (5 ones in a row). The reason for this is that without it the CRC cannot detect lengthening or shortening of a message that leads with zeros. This is demonstrated in your particular sequence, where the CRC is always zero for any length of leading zeros if you use an initial value of 00000b.

This is quite a common problem in CRC implementations.