mauricio fernandez montoya

MCF51JM128+ Wii Motion Plus

Discussion created by mauricio fernandez montoya on May 25, 2012
Latest reply on May 29, 2012 by TomE

Hi.  i been trying to get gyro data from a Wii Motion Plus trough I2C module.

i get no response from the device, so i think i've made a mistake in configuration of IIC module.

 this is how i configured the module.  baud rate is 400kbps.


void IIC1_Init(void){  IIC1C1=0xC0;    //IIC habilitado, Interrupcion por IIC habilitada, Modo esclavo habilitado, transmision apagada,no hay recibido ACK,No se repite start.   IIC1S=0x10;     //Bandera transferencia en proceso, No direccionamiento a esclavo, bus ocupado, bus operando normal, master escribe esclavo recibe, no hay interrupciones, recibe ACK.  //IIC1F=0x1F;     //Factor MULT: 1, rata de baudios 100KHz para WM+ (24Mhz/1*100Khz)=240=0x1F, 100Khz.  IIC1F=0x45;     //Factor MULT: 2, rata de baudios 400KHz para WM+ (24Mhz/2*400Khz)=30=0x05, 400Khz.}

 start and stop condition procedures:


void IIC1_StartBit(){  //while(IIC1S_BUSY);           //espere a que el IIC se desocupe  IIC1C_TX=1;                  //habilite modo TX por el maestro                       //se envia ACK  IIC1C_MST=1;                 //modo maestro.}void IIC1_StopBit(void){  IIC1C = 0xC0;                         //genere una condicion de STOP  //while(IIC1S_BUSY);                   //espere a que el IIC se desocupe    }

 writing condition:

void IIC1_PutChar(unsigned char Tx1_Data){  IIC1_Flag=0;                 //Baje la bandera de atención a interrupción  IIC1D=Tx1_Data;              //Cargue dato a registro. while(!IIC1S_BUSY);          //espere a que el IIC se desocupe  while(IIC1S_IICIF);         //espere a que el modulo IIC no tenga interrupciones pendientes  //IIC1S &= ~0X02;   IIC1S_IICIF=0;  }

 and reading:


unsigned char IIC1_GetChar(unsigned char Ack_Req){  unsigned char Dummy_Byte=0;  IIC1C_TX=0;           //Modo de recepcion. Dummy_Byte= IIC1D;    //Lea dato de basura para despejar el buffer. while(IIC1S_IICIF);  //espere a que el modulo IIC no tenga interrupciones pendientes  //IIC1S &= ~0X02;   IIC1S_IICIF=0;  if(Ack_Req){    IIC1C_TXAK=0;           //Habilitar ACK     }   else if (Ack_Req==0){    IIC1C_TXAK=1;           //Deshabilitar ACK   }  IIC1RX_Data=IIC1D;       //lea el dato solicitado  return(IIC1RX_Data);}


what do you think??? 

main routine has the following structure:

 IIC1_StartBit();   IIC1_PutChar((0X53<<1)|I2C_WRITE); //Adressing   IIC1_PutChar(0XFE);                //Register     IIC1_PutChar(0X04);                //Register Value   IIC1_StopBit();

 reading route looks like:

IIC1_StartBit();     IIC1_PutChar((0X52<<1)|I2C_READ);     IIC1_PutChar(0X00);     IIC1_StopBit();     for (i=0;i<5;i++){      Dato[i]=IIC1_GetChar(1);     }     Dato[5]=IIC1_GetChar(0);

 what do you think?  does anybody have worked with Wii Motion Plus???


i've tested a routime made for arduino with same structure, registers and data and works fine!!


Thank you so much;