Wii Nunchuck Over I2C issues

Questions on control of serial busses
Post Reply
FIREWALL
Posts: 15
Joined: Thu Nov 08, 2012 6:31 pm

Wii Nunchuck Over I2C issues

Post by FIREWALL »

Has anyone had any luck interfacing a Wii Nunchuck to the SuperPro? I am programming in C. Here is the latest version of the code I am trying (with no luck). Any Ideas?

//================================================================================
#ifdef LPC175x // SUperPRO PROplus -- connected to OUR internal test PCB
#define SCL (1<<16) + 28 //P1.28
#define SDA 0 //P0.0
#else
#define SCL 5 //P0.10
#define SDA 6 //
#endif

int nunchuk_ID = 0x52;

char nunchuck_init[2] = {0x40,0x00}; // sends memory address, sends sent a zero.
char chuckResponse[6];
I2COUT (SDA, SCL, nunchuk_ID, 2, nunchuck_init);
while(1)
{
WAIT(50);
//read 6 bytes in
I2CIN(SDA, SCL, nunchuk_ID, -1, -1, -1, -1, -1, 6, chuckResponse);

//output last 2 bytes to Serial LCD
char tmpString[50];
serial_lcd_selectLine(1);
serial_lcd_setCursor(1, 1);
sprintf(tmpString,"%x %x",chuckResponse[4],chuckResponse[5]);
serial_lcd_write(tmpString);

//capture the next set of data for reading
nunchuck_init[0] = 0x00;
I2COUT (SDA, SCL, nunchuk_ID, 1, nunchuck_init);
}



basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Wii Nunchuck Over I2C issues

Post by basicchip »

P1.28 would be IO(60). 32+28

FIREWALL
Posts: 15
Joined: Thu Nov 08, 2012 6:31 pm

Re: Wii Nunchuck Over I2C issues

Post by FIREWALL »

I am having trouble getting the attached code to work. I have my logic analyzer hooked up to the pins 57 and 58. If I toggle the pins using HIGHX and LOWX my logic analyzer picks it up so I know the analyzer is hooked up correctly. When I run the attached code I get this as output
Analyzer Capture
Analyzer Capture
nunchuck_LPC1756_error.png (25.87 KiB) Viewed 30120 times

Anyone have any idea what am I doing wrong?


Thanks,
Dan
Attachments
nunchuck.c
Source Code
(865 Bytes) Downloaded 1149 times

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Wii Nunchuck Over I2C issues

Post by basicchip »

Have you got pullups on the SDA and SCL pins?

Could you zoom in on the scope trace?

While the bit bang macros were tested, they were not tested for all pins, the I2CIN and I2COUT rely on INPUTx(pin), OUTPUTx(pin) ,LOWx(PIN) and INx(pin)

you might verify that by writing a program to wiggle pins using those macros and the pins you intend to use.

FIREWALL
Posts: 15
Joined: Thu Nov 08, 2012 6:31 pm

Re: Wii Nunchuck Over I2C issues

Post by FIREWALL »

I decided to use P0.0 and P0.1 . I tested the pins using INPUTx, OUTPUTx, LOWx, and INx, and the macros worked propperly. I decided to take a look at the code that was doing the bit-banging to try and understand what was happening. I now have a question about the i2c_start function in cor_bitbang.c (snippet below).

How can the statement "if (INx(sda_pin) && INx(scl_pin))" ever evaluate to TRUE when the pins are set to Output Low by the SET_SCL_LOW and SET_SDA_LOW macros? There must be something I am missing.

I ask because on my SuperPro, the call to i2c_start inside of I2COUT is always returning -1 (not able to get the bus)

//==================================================================================
//I2C_START FROM cor_bitbang.c
//==================================================================================
int i2c_start (int sda_pin, int scl_pin) {
int start;

SET_SCL_HIGH; SET_SDA_HIGH; // don't drive SDA or SCL,
SET_SCL_LOW; SET_SDA_LOW; // drive both low when enabled

start = LPC_TIM0->TC;

while (LPC_TIM0->TC-start < 100000) {

if (INx(sda_pin) && INx(scl_pin)) {
SET_SDA_LOW; // drive SDA low
i2c_stall();
if ((INx(scl_pin)) == 0) { // check we got control
SET_SCL_HIGH; SET_SDA_HIGH; // release both
} else {
SET_SCL_LOW; // drive SCL low
return 0; // we got control
}
}
}
return -1;
}

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Wii Nunchuck Over I2C issues

Post by basicchip »

Yes, that line in I2CSTART looks to be wrong

SET_SCL_LOW; SET_SDA_LOW; // drive both low when enabled

Comment it out and try it. From the comment on the line I remember some testing with I believe the LPC812 which the state of an IO is not maintained when the direction is turned around, and that may have been an attempt to fix that.

FIREWALL
Posts: 15
Joined: Thu Nov 08, 2012 6:31 pm

Re: Wii Nunchuck Over I2C issues

Post by FIREWALL »

I removed SET_SCL_LOW; SET_SDA_LOW; Last night (forgot to update forum post). That does solve the problem of start signal, etc not being generated properly. However, Now the stop signal is not being generated properly. I will upload screen caps from my logic analyzer later tonight.

-Dan

teckfine
Posts: 1
Joined: Thu Feb 27, 2020 11:36 am

Re: Wii Nunchuck Over I2C issues

Post by teckfine »

I removed SET_SCL_LOW; SET_SDA_LOW; Last night (forgot to update forum post). That does solve the problem of start signal, etc not being generated properly. However, Now the stop signal is not being generated properly. I will upload screen caps from my logic analyzer later tonight.

Post Reply