Pages: [1]   Go Down
Author Topic: Clone Nunchuk initialisation problems [FIXED]  (Read 791 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Full Member
***
Karma: 9
Posts: 220
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[FIX]
 A delay between requestFrom and available makes it work  smiley-yell
I tested briefly with delay(1) and still looks good. MEGA irritating as my son would say
Code:
   
...
  Wire.requestFrom (0x52, 6);
  delay(10);
  while (Wire.available ())
...
...
[/FIX]

I am reposting this from "Sensors" as it seems to have generated no reaction.

I have just received a MadCatz.com Nunchuk and I am unable to initialise it.

I have another Nunchuk clone and an official Nunchuk which I can initialise and read.

I have tried all I can find on the Internet and they are shown below and none have worked.

'Official' Nunchuk code

Code:
 
  Wire.beginTransmission (0x52);
  Wire.write (0x40);
  Wire.write (0x00);
  Wire.endTransmission ();
and this which works for my clone and the official Nunchuk


  
Code:
 Wire.beginTransmission(0x52);  

  Wire.write(0xF0);              // 1st initialisation register
  Wire.write(0x55);              // 1st initialisation value

  Wire.endTransmission();

  delay(10);
  Wire.beginTransmission(0x52);
  Wire.write(0xFB);              // 2nd initialisation register
  Wire.write(0x00);              // 2nd initialisation value


I have also tried


  
Code:
 Wire.beginTransmission(0x53);    //WM+ starts out deactivated at address 0x53
  Wire.write(0xfe);                 //send 0x04 to address 0xFE to activate WM+
  Wire.write(0x05);
  Wire.endTransmission();          //WM+ jumps to address 0x52 and is now active
and


 
Code:

  Wire.beginTransmission(0x52);
  Wire.write(0xfe);
  Wire.write (0x05);
  Wire.endTransmission();

and this one which is getting more sophisticated

Code:
// params:
// timeout: abort when timeout (in ms) expires, 0 for unlimited timeout
// return: 0 == ok, 1 == timeout
byte x2nunchuck_init (unsigned short timeout)
{
  byte rc = 1;
  unsigned long time = millis();
  do
  {
    Wire.beginTransmission (0x52); // transmit to device 0x52
    Wire.write (0xF0); // sends memory address
    Wire.write (0x55); // sends data.
    if(Wire.endTransmission() == 0) // stop transmitting
    {
      Wire.beginTransmission (0x52); // transmit to device 0x52
      Wire.write (0xFB); // sends memory address
      Wire.write (0x00); // sends sent a zero.
      if(Wire.endTransmission () == 0) // stop transmitting
      {
        rc = 0;
      }
    }
  }
  while (rc != 0 && (!timeout || ((millis() - time) < timeout)));
  return rc;
}
and finally this most complex one
Code:

void  nunchuck_init ()        {

  // init controller
  delay(1);
  Wire.beginTransmission(0x52);      // device address
  Wire.write(0xF0);                    // 1st initialisation register
  Wire.write(0x55);                    // 1st initialisation value
  Wire.endTransmission();
  delay(1);
  Wire.beginTransmission(0x52);
  Wire.write(0xFB);                    // 2nd initialisation register
  Wire.write(0x00);                    // 2nd initialisation value
  Wire.endTransmission();
  delay(1);

  // read the extension type from the register block        
  Wire.beginTransmission(0x52);
  Wire.write(0xFA);                    // extension type register
  Wire.endTransmission();
  Wire.beginTransmission(0x52);
  Wire.requestFrom(0x52, 6);               // request data from controller
  for (cnt = 0; cnt < 6; cnt++) {
    if (Wire.available()) {
      pwbuff[cnt] = Wire.read(); // Should be 0x0000 A420 0101 for Classic Controller, 0x0000 A420 0000 for nunchuck
    }
  }
  Wire.endTransmission();
  delay(1);

  // send the crypto key (zeros), in 3 blocks of 6, 6 & 4.
  Wire.beginTransmission(0x52);
  Wire.write(0xF0);                    // crypto key command register
  Wire.write(0xAA);                    // sends crypto enable notice
  Wire.endTransmission();
  delay(1);
  Wire.beginTransmission(0x52);
  Wire.write(0x40);                    // crypto key data address
  for (cnt = 0; cnt < 6; cnt++) {
    Wire.write(0x00);                    // sends 1st key block (zeros)
  }
  Wire.endTransmission();
  Wire.beginTransmission(0x52);
  Wire.write(0x40);                    // sends memory address
  for (cnt = 6; cnt < 12; cnt++) {
    Wire.write(0x00);                    // sends 2nd key block (zeros)
  }
  Wire.endTransmission();
  Wire.beginTransmission(0x52);
  Wire.write(0x40);                    // sends memory address
  for (cnt = 12; cnt < 16; cnt++) {
    Wire.write(0x00);                    // sends 3rd key block (zeros)
  }
  Wire.endTransmission();
  delay(1);
  // end device init
}

Although I can get back a set of data from the Nunchuk it is all the same and never changes I thought that I must be reading something but I'm not so sure now...

I ran up the scanner test sketch and it doesn't find any I2C devices when this clone is plugged in. Does this help identify the cause and possible solution BUT I dug out the Wii and it works on the Wii okay.  
« Last Edit: July 02, 2013, 01:46:54 pm by acboother » Logged

sig

UK
Offline Offline
Full Member
***
Karma: 9
Posts: 220
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Diagnostic update...

I didn't notice this first time round but after the intialisation routine immediately after uploading the Nunchuk does NOT read correctly but hangs!!!

If I unplug the Nunchuk and then plug it back in without a reset or upload it starts to read but it is now that the values do not change.

Using this initialisation routine

Code:
 


  Wire.beginTransmission(0x52);   // device address

  Wire.write(0xF0);              // 1st initialisation register

  Wire.write(0x55);              // 1st initialisation value

  Wire.endTransmission();

  Wire.beginTransmission(0x52);

  Wire.write(0xFB);              // 2nd initialisation register

  Wire.write(0x00);              // 2nd initialisation value

;


and registers 0x32 and 0x33 for reading 

<I promised myself I wouldn't look it this again until I ha some new information to work with...  smiley-sad-blue
Logged

sig

UK
Offline Offline
Full Member
***
Karma: 9
Posts: 220
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have put a 'scope on the SDA and SCL pins for both the official Nunchuk and the clone an as far as I can tell they both look the same (mind you I barely know what I'm looking at).

Here is the trace from the clone



So something similar is going on for both controllers
Logged

sig

Pages: [1]   Go Up
Jump to: