Code: Select all
byte CMDNunchukInit[] = {0xA4, 0x40, 0x00};
byte CMDNunchukWrite[] = {0xA4, 0x00};
byte CMDNunchukRead[] = {0xA4};
byte outbuf[];
byte count = 6;
byte nByteReady;
task main()
{
SetSensorLowspeed(S1);
while (true)
{
while (I2CStatus(S1, nByteReady) == STAT_COMM_PENDING); //Wait until bus is free
I2CWrite(S1, 0, CMDNunchukInit); //When the I2C bus is ready, send message
while (I2CStatus(S1, nByteReady) == STAT_COMM_PENDING); //Wait until bus is free
I2CWrite(S1, 0, CMDNunchukWrite); //When the I2C bus is ready, send message
while (I2CStatus(S1, nByteReady) == STAT_COMM_PENDING); //Wait until bus is free
I2CBytes(S1, CMDNunchukRead, count, outbuf) //Read the registers
if (ArrayLen(outbuf)==count) {
ClearScreen();
for(int i=0; i<ArrayLen(outbuf); i++ ) {
NumOut(0, LCD_LINE2-(i*8), outbuf[i]);
}
}
Wait(100);
}
}
It always displays (returns) 255 (0xFF) for all six bytes.
It doesn't work at all if I do either of the following:
- switch the serial lines (I don't have them mixed up).
Remove either or both of the pullups.
I am sure the nunchuck is sending some sort of data, but it sure doesn't seem to be anything other than 0xFF.
Any ideas?
Any code you know works that you want to share?
Could someone with a working NXTified nunchuck please try my code, and tell my what happens?