There is a bug in this routine the prevents a "1" in the high (9th) bit from being received. The line: d |= 0x80; needs to be changed to d |= 0x100;