About MPR121 return value!

Showing results for 
Search instead for 
Did you mean: 

About MPR121 return value!

Contributor I

When i use a mpr121,and have wrong return value of the register 0x00,0x01.

when push ELE0,return 0x0000;

when push ELE1,return 0x0001;

when push ELE2,return 0x0002;

when push ELE3,return 0x0004;

when push ELE4,return 0x0008;

when push ELE5,return 0x0010;

when push ELE6,return 0x0020;

when push ELE7,return 0x00c0;

when push ELE8,return 0x0000;

when push ELE9,return 0x0001;

when push ELE10,return 0x0002;

when push ELE11,return 0x0004;

according to the manual,it should be

when push ELE0,return 0x0001;

when push ELE1,return 0x0002;

when push ELE2,return 0x0004;

when push ELE3,return 0x0008;

when push ELE4,return 0x0010;

when push ELE5,return 0x0020;

when push ELE6,return 0x0040;

when push ELE7,return 0x0080;

when push ELE8,return 0x0100;

when push ELE9,return 0x0200;

when push ELE10,return 0x0400;

when push ELE11,return 0x0800;

The code is:

        void IIC_MPR121()
  // Section A
  // This group controls filtering when data is > baseline.
  write_i2c(touch_shield,MHD_R, 0x01);
  write_i2c(touch_shield,NHD_R, 0x01);
  write_i2c(touch_shield,NCL_R, 0x02);
  write_i2c(touch_shield,FDL_R, 0x00);

  // Section B
  // This group controls filtering when data is < baseline.
  write_i2c(touch_shield,MHD_F, 0x01);
  write_i2c(touch_shield,NHD_F, 0x01);
  write_i2c(touch_shield,NCL_F, 0xff);
  write_i2c(touch_shield,FDL_F, 0x00);
  // Section C
  // This group sets touch and release thresholds for each electrode
  write_i2c(touch_shield,ELE0_T, TOU_THRESH);
  write_i2c(touch_shield,ELE0_R, REL_THRESH);
  write_i2c(touch_shield,ELE1_T, TOU_THRESH);
  write_i2c(touch_shield,ELE1_R, REL_THRESH);
  write_i2c(touch_shield,ELE2_T, TOU_THRESH);
  write_i2c(touch_shield,ELE2_R, REL_THRESH);
  write_i2c(touch_shield,ELE3_T, TOU_THRESH);
  write_i2c(touch_shield,ELE3_R, REL_THRESH);
  write_i2c(touch_shield,ELE4_T, TOU_THRESH);
  write_i2c(touch_shield,ELE4_R, REL_THRESH);
  write_i2c(touch_shield,ELE5_T, TOU_THRESH);
  write_i2c(touch_shield,ELE5_R, REL_THRESH);
  write_i2c(touch_shield,ELE6_T, TOU_THRESH);
  write_i2c(touch_shield,ELE6_R, REL_THRESH);
  write_i2c(touch_shield,ELE7_T, TOU_THRESH);
  write_i2c(touch_shield,ELE7_R, REL_THRESH);
  write_i2c(touch_shield,ELE8_T, TOU_THRESH);
  write_i2c(touch_shield,ELE8_R, REL_THRESH);
  write_i2c(touch_shield,ELE9_T, TOU_THRESH);
  write_i2c(touch_shield,ELE9_R, REL_THRESH);
  write_i2c(touch_shield,ELE10_T, TOU_THRESH);
  write_i2c(touch_shield,ELE10_R, REL_THRESH);
  write_i2c(touch_shield,ELE11_T, TOU_THRESH);
  write_i2c(touch_shield,ELE11_R, REL_THRESH);
   write_i2c(touch_shield,0x5c, 0x30);

  // Section D
  // Set the Filter Configuration
  // Set ESI2
  write_i2c(touch_shield,FIL_CFG, 0x42);
  // Section E
  // Electrode Configuration
  // Enable 6 Electrodes and set to run mode
  // Set ELE_CFG to 0x00 to return to standby mode
// write_i2c(touch_shield,ELE_CFG, 0x0c);    // Enables all 12 Electrodes
  //write_i2c(touch_shield,ELE_CFG, 0x06);        // Enable first 6 electrodes
  // Section F
  // Enable Auto Config and auto Reconfig

write_i2c(touch_shield,ATO_CFG0, 0x0B);
  write_i2c(touch_shield,ATO_CFGU, 0xC9);    // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V  
  write_i2c(touch_shield,ATO_CFGL, 0x96);    // LSL = 0.65*USL = 0x82 @3.3V
  write_i2c(touch_shield,ATO_CFGT, 0xBb);    // Target = 0.9*USL = 0xB5 @3.3V

write_i2c(touch_shield,ELE_CFG, 0x0c);    // Enables all 12 Electrodes 

uchar get_key()

    uchar count=0;
    uchar i=0;
    uint key_data;
    uint key_data2;
     key_data=key_data| read_i2c(touch_shield,0x00);

//    for (i=0; i<12; i++)  //检测有多少按键被触摸
//      {
//        if ((dat & (1<<i)))
//          count++;
//      }
//      i=0;
//      if(count==1)
//      {

//         while(((dat & (1<<i)) == 0)&&(i<12))
//           i++;
//           i++;
//           return i;
//     }
//     return 0;

     key_data2=key_data2| read_i2c(touch_shield,0x00);

      return key_data;


i don't know what's the problem? help please.

Labels (1)
0 Kudos
1 Reply

Contributor I

I also need a usps tracking little help with this.

0 Kudos