I am trying to interface with a mouse sensor and am not able to get data back. datasheet link I have it still soldered to the original PCB but have cut the traces to pins 1-4,6,7 (NCS [SS], MISO, SCLK, MOSI, RESET, NPD [power down {set to 3.3v}])


According to the Datasheet, by default the sensor is setup with the pull-up resistors enabled [pg. 29] which enables the open-drain, allowing me to directly connect NCS,MISO,SCLK,MOSI directly to the 5v microcontroller [pg. 15]. This also requires the SPI speed set to 500khz [pg. 10]. RESET is in a (10k)(10k+10k) resistor bridge.

SPI should be set to Mode3 as SCLK is normally high and data should be captured on the rising edge of the clock pulse [pg. 16]

Here is my code:

#include <SPI.h>
const int MOUSEVERSION = 0x00; //mouse version
const int CSmouse = 10;
const int mouseReset = 2;
char val;

void setup() {
  SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE3));
  pinMode(CSmouse, OUTPUT);
  pinMode(mouseReset, OUTPUT);
  digitalWrite(CSmouse, HIGH);
  //pull reset pin high for a half second to make sure mouse is ready to go after powering on [pg. 22]
  digitalWrite(mouseReset, HIGH);
  delay(500); //half a second
  digitalWrite(mouseReset, LOW);
  Serial.println("end setup");

void loop() {
  Serial.println("Start loop");
  digitalWrite(CSmouse, LOW); //CS enable
  SPI.transfer(MOUSEVERSION); //0x00 = read register Product_ID, should reply 0x17
  Serial.println(SPI.transfer(0)); //actually just gives 0

You have SPI.beginTransaction but no SPI.begin().

SPI.begin() is needed to initialize the SPI hardware.

More details about SPI at SPI - Serial Peripheral Interface - for Arduino.

| improve this answer | |
  • Thank you! I was under the impression that beginTransaction() superseded begin() since setClockDivider() and the like were depreciated. That is what I get for assuming. – user2497991 Sep 8 '15 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.