Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
A lil 2nd question:"Do I need any resistor for terminate the SCl and SDa data?" I read about this, bit I'm not shure because there isn't any on this tobot.com-tutorial
DDRD = 0b11110011; //configure ports for output
sbi(PORTD, PD0); // SCL pull-up sbi(PORTD, PD1); // SDA pull-up DDRD = 0b11110011; //configure ports for output
#define Wii_ADDR 0x52#define BUFFSIZE 0x06void nunchunk_data(void){ volatile u08 databuffer; volatile u08 readbuffer[BUFFSIZE]; databuffer=0; i2cMasterSend(Wii_ADDR, 0x01, &databuffer); delay_ms(10); i2cMasterReceive(Wii_ADDR, BUFFSIZE, &readbuffer); rprintf("\n Data: "); for (i = 0; i < BUFFSIZE; i++) { rprintfu08(readbuffer[i]); rprintfChar('.'); } rprintf("\n"); accx = readbuffer[2]; // ranges from approx 70 - 182 accy = readbuffer[3]; // ranges from approx 65 - 173 accz = readbuffer[4]; zbut =((readbuffer[5] >> 0) & 1) ? 0 : 1; cbut =((readbuffer[5] >> 1) & 1) ? 0 : 1; xjoy =readbuffer[0]; yjoy =readbuffer[1];}void nunchuck_init(void){ i2cMasterSend(0x52, 0x02, 0x4000);}
#define Wii_ADDR 0x52#define BUFFSIZE 0x06void nunchunk_data(void){ volatile u08 databuffer; volatile u08 readbuffer[BUFFSIZE]; databuffer=0; int i; rprintfInit(uart1SendByte); // Set up rprintf to be USB i2cSetBitrate(100); //set I2C transaction bit rate to 100 kHz i2cSendStart(); //Send I2C start condition in Master mode i2cSendByte(Wii_ADDR | 0x40 | 0x00); //Send (address| memory address |R/W) combination or a data byte over I2C i2cSendStart(); //Send I2C start condition in Master mode i2cSendByte(Wii_ADDR | 0x00); //Send (address|R/W) combination or a data byte over I2C for (i=0;i<BUFFSIZE;i++) { i2cReceiveByte(1); readbuffer[i] = nunchuk_decode_byte (i2cGetReceivedByte()); } i2cSendStop(); //Send I2C stop condition in Master mode rprintf("\n Data: "); for (i = 0; i < BUFFSIZE; i++) { rprintfu08(readbuffer[i]); rprintfChar('.'); } rprintf("\n"); accx = readbuffer[2]; // ranges from approx 70 - 182 accy = readbuffer[3]; // ranges from approx 65 - 173 accz = readbuffer[4]; zbut =((readbuffer[5] >> 0) & 1) ? 0 : 1; cbut =((readbuffer[5] >> 1) & 1) ? 0 : 1; xjoy =readbuffer[0]; yjoy =readbuffer[1];}static u08 nunchuk_decode_byte (u08 x){ x = (x ^ 0x17) + 0x17; return x;}
Still not working, but on a god way. Have receaved some date (but still not the right interpratation or some small mistake).Here some code, I'm open for help, loding up thecorrect code if it runs correctly.