Reading the ADNS5050 w/Arduino

I realize this isn’t a component that SF sells, but it’s the replacement for the 2620 and the code is pretty close though, maddeningly, different enough that I can’t get it to work :confused:

Thought I’d post this up here and see if anyone might see what could be wrong with it. The datasheet is here: http://www.avagotech.com/pages/en/navig … adns-5050/ and I’m following a combination of the Arduino2620 code and some atMega328 code that I found online. Since I’m working with an Uno at the moment I figured that the 328 code should be easy to convert over. So far no love though. Here’s what I’ve got:

#define SCLK                5
#define SDIO                3

#define PRODUCT_ID          0x00
#define PRODUCTID2          0x3e
#define REVISION_ID         0x01
#define DELTA_Y_REG         0x03
#define DELTA_X_REG         0x04
#define SQUAL_REG           0x05
#define MAXIMUM_PIXEL_REG   0x08
#define MINIMUM_PIXEL_REG   0x0a
#define PIXEL_SUM_REG       0x09
#define PIXEL_DATA_REG      0x0b
#define SHUTTER_UPPER_REG   0x06
#define SHUTTER_LOWER_REG   0x07
#define RESET		    0x3a
#define CPI500v		    0x00
#define CPI1000v	    0x01

const int NCS = 4;

void setup()
{
  Serial.begin(57600);
  
  pinMode(SDIO, OUTPUT);
  pinMode(SCLK, OUTPUT);
  pinMode(NCS, OUTPUT);
  digitalWrite(NCS, LOW);
  delayMicroseconds(2);
  digitalWrite(NCS, HIGH);

  //call reset
  ADNS_write(RESET, 0x5a);
  delay(50); // From NRESET pull high to valid mo tion, assuming VDD and motion is present.

}

void loop()
{
  delay(200);
  Serial.println(ADNS_read(PRODUCT_ID), BIN); // should print 00010010, doesn't
}

void ADNS_write(unsigned char addr, unsigned char data) {
  char temp;
  int n;

  digitalWrite(NCS, LOW);//nADNSCS = 0; // select the chip

  temp = addr;
  digitalWrite(SCLK, LOW);//SCK = 0;					// start clock low
  pinMode(SDIO, OUTPUT);//DATA_OUT; // set data line for output
  for (n=0; n<8; n++) {
    digitalWrite(SCLK, LOW);//SCK = 0;
    pinMode(SDIO, OUTPUT);
    delayMicroseconds(1);
    if (temp & 0x80)
      digitalWrite(SDIO, HIGH);//SDOUT = 1;
    else
      digitalWrite(SDIO, LOW);//SDOUT = 0;
    temp = (temp << 1);
    digitalWrite(SCLK, HIGH);//SCK = 1;
    delayMicroseconds(1);//delayMicroseconds(1);			// short clock pulse
  }
  temp = data;
  for (n=0; n<8; n++) {
    digitalWrite(SCLK, LOW);//SCK = 0;
    delayMicroseconds(1);
    if (temp & 0x80)
      digitalWrite(SDIO, HIGH);//SDOUT = 1;
    else
      digitalWrite(SDIO, LOW);//SDOUT = 0;
    temp = (temp << 1);
    digitalWrite(SCLK, HIGH);//SCK = 1;
    delayMicroseconds(1);			// short clock pulse
  }
  delayMicroseconds(20);
  digitalWrite(NCS, HIGH);//nADNSCS = 1; // de-select the chip
}

byte ADNS_read(unsigned char addr) {
  byte temp;
  int n;

  digitalWrite(NCS, LOW);//nADNSCS = 0;				// select the chip

  temp = addr;
  digitalWrite(SCLK, OUTPUT); //SCK = 0;					// start clock low
  pinMode(SDIO, OUTPUT); //DATA_OUT;					// set data line for output
  for (n=0; n<8; n++) {

    digitalWrite(SCLK, LOW);//SCK = 0;
    pinMode(SDIO, OUTPUT); //DATA_OUT;
    if (temp & 0x80) {
      digitalWrite(SDIO, HIGH);//SDOUT = 1;
    } 
    else {
      digitalWrite(SDIO, LOW);//SDOUT = 0;
    }
    temp = (temp << 1);
    delayMicroseconds(1);
    digitalWrite(SCLK, HIGH); //SCK = 1;
    delayMicroseconds(1);			// short clock pulse
  }
  temp = 0;					// This is a read, switch to input
  pinMode(SDIO, INPUT); //DATA_IN;
  delayMicroseconds(4);
  for (n=0; n<8; n++) {		// read back the data
    digitalWrite(SCLK, LOW); //SCK = 0;
    delayMicroseconds(1);
    digitalWrite(SCLK, HIGH);//SCK = 1;
    if(digitalRead(SDIO)) { //if (SDIN) {				// got a '1'
      temp |= 0x1;
    }
    temp = (temp << 1);		// shift left
    delayMicroseconds(1);
  }
  digitalWrite(NCS, HIGH);//nADNSCS = 1;				// de-select the chip
  return temp;
}

All I get back right now is 254 from the SDIO, so any ideas or advice would be deeply deeply appreciated. Thanks!

I am working with microchip 18F4550 and ADNS 5050 and they didn’t work, google and found this topic.

The interface is very similar with 2610 but I can’t figure out why, do you know how to work with 5050?