This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Programming MSP430 launchpad for FDC1004 using wire.h library.

Other Parts Discussed in Thread: FDC1004, ENERGIA

Can anyone help me, please? I am a noob at coding. I am trying to write the registers in the FDC1004 using the wire.h library. But I can not seem to get any meaningful response. Any thoughts?

/*
This is a program used for capacitive sensing.
 
 FDC1004                         MSP430G2553
 GND ----------------------------GND
 VDD ----------------------------3.3V
 SDA--------^^4.7kOhms^^----------P1.7 (15)
 SCL--------^^4.7kOhms^^----------P1.6 (14)
 
 Created by: M. Keif
 Date: 2/7/16
 */


#include <Wire.h> // Standard I2C Library

int FDC = 0b1010000;   //7-bit Address of FDC1004 Slave

int MEAS1_MSB = 0x00; //Pointer for Register MSB portion of Measurement 1
int MEAS1_LSB = 0x01; //Pointer for Register LSB portion of Measurement 1
int CONF_MEAS1 = 0x08; //Pointer for Register Measurement 1 configuration
int FDC_CONF = 0x0C; //Pointer to Configuration settings

int MEAS1_CONF_VAL = 0b0000010110000000; //16-bit stream for setting registers
int FDC_VAL = 0b0000110110000000; //16-bit stream for setting registers


int MSB1_M1;
int MSB2_M1;
int LSB1_M1;


void setup()
{

  Wire.begin(); // Starts the I2C Connection
  Serial.begin(9600); // Starts the Serial Communication
  delay(500); // Wait for setup to complete before running program
}


void loop()
{

  Wire.beginTransmission(FDC);//FDC address (RW bit already set?)
  Wire.write(CONF_MEAS1);//Register pointer (where written)
  Wire.write(MEAS1_CONF_VAL);//Data to write into register (what is written)
  Wire.endTransmission();//Sends the above

  Wire.beginTransmission(FDC);//FDC address (RW bit already set?)
  Wire.write(FDC_CONF);//Register pointer (where written)
  Wire.write(FDC_VAL);//Data to write into register (what is written)
  Wire.endTransmission();//Sends the above

  delay(100); 

  Wire.beginTransmission(FDC);//FDC address (RW bit already set?)
  Wire.write(MEAS1_MSB);//Point to read register
  Wire.endTransmission();//Sends the above
  delay(100);
 
  Wire.requestFrom(FDC, 2); // Ask for 2 bytes to be transmitted
  while(Wire.available()) {
    MSB1_M1 = Wire.read(); // Left byte 1 (1st MSB)
    MSB2_M1 = Wire.read(); // Right byte 1 (2nd MSB) 
  }

  Wire.beginTransmission(FDC);//FDC address (RW bit already set?)
  Wire.write(MEAS1_LSB);//Point to read register
  Wire.endTransmission();//Sends the above
  delay(100);
 
  Wire.requestFrom(FDC, 1); // Ask for 1 byte to be transmitted
  while(Wire.available()) {
    LSB1_M1 = Wire.read(); // Left byte 1 (LSB)
  }

  Serial.print("Bytes:  ");
  Serial.print(MSB1_M1);
  Serial.print("          ");
  Serial.print(MSB2_M1);
  Serial.print("          ");
  Serial.print(LSB1_M1);
  Serial.print("\n");


}

  • Hello Malcolm,

    You mention not being able to receive a meaningful response, does that mean you are getting a response of some sort? This would help determine if the communication hardware is successful and the issue lies with the commands you are sending. Can you use an oscilloscope or logic analyzer to prove that your I2C communication frames are as expected by Figure 14 of the FDC1004 datasheet?

    Your first two I2C write sequences appear to be correct, assuming 0x0580 and 0x0D80 are the values you want to set to the MEAS1_CONF_VAL and FDC_VAL registers, respectively. I would try not using lines 57-60 and 68-71, the re-start after initially pointing to the register byte should already be included in Wire.requestFrom and you could be confusing the FDC1004 through unintentionally re-issuing the slave address byte a third time.

    Regards,
    Ryan
  • Hi Ryan,

    Thank you for responding to my request for help. I really appreciate it.

    I have access to an oscilloscope at work (not there currently) but I'm not entirely sure where to put it in my circuit or what exactly I'd be looking to do with it.
    If you can advise, I can report back. I do not have access to a logic analyzer (nor do I know what one is :)

    What I get currently when I upload this is 0 for all readings.

    Also, don't I need 57-60 and 68-71 as the datasheet shows that to read a register, you must first write (or point) to it with a wire.write (RW bit low)? I assume that the wire.write function actually ensures the RW bit is set low and the wire.read function sets the RW bit high. Is that a correct assumption?

    I am concerned that my 16 bit stream (0x0580) that sets the register parameters is not supplied in a usable format. Can I send 16 bits in one chunk like that?

    Thanks

  • Hi Malcolm,

    You would connect the oscilloscope to the I2C SDA line and use the trigger to capture I2C sequences and compare them to Figure 14 of the FDC1004 datasheet to see what part of the communication is incorrect.

    I2C lines are pulled high by default and reading zero indicates that the SDA line is low, this makes me wonder if the line is being pulled up correctly.

    Most I2C read commands operate with a start bit, the slave address + 0 R/W bit, the register number you want to read from, a repeated start bit, the slave address + 1 R/W bit, and finally reading the registers from the slave. I believe this entire process before reading from the slave is encapsulated by the Wire.requestFrom function.

    I believe Wire.write is capable of handling multiple bytes, but if you are not sure feel free to write the bytes individually. Keep trying different small changes until something works, sometimes that's part of debugging code.

    If using the MSP-EXPG2 LaunchPad make sure that the P1.6 jumper connecting LED2 is unpopulated, otherwise the I2C SCL line will not function properly.

    Regards,
    Ryan
  • Thanks Ryan, I do have the p1.6  LED jumper removed.

    I don't think the Wire.requestFrom includes the register ID, and that is why you have to do a Wire.write to the register....at least that is how I interpret the minimal explanation at energia.nu/.../

    I'll try the oscilloscope next week.

    Again, thank you for helping me.

  • I am simply referencing what I know from Energia's master_reader example. Let me know when you have oscilloscope results.

    Regards,
    Ryan
  • Malcolm,

    Have you resolved your issue or obtained oscilloscope results?

    Regards,
    Ryan
  • Hello Ryan,

    I try to configure the FDC1004.

    void setup()
    
    {
    
     Wire.begin(); // Starts the I2C Connection
    
     Serial.begin(9600); // Starts the Serial Communication
    
     delay(500); // Wait for setup to complete before running program
    
    
     Wire.beginTransmission(FDC);//FDC address (RW bit already set?)
    
     Wire.write(FDC_CONF);//Register pointer (where written)
    
     Wire.write(FDC_VAL);//Data to write into register (what is written)
    
     Wire.endTransmission();//Sends the above
    
     delay(100);
    
    
    }
    
    void loop()
    
    {
    
    "do measurement"

    }

    Now I used EVM GUI tool to have a look at realtime to the registers. Especially for FDC_Conf I'm not able to set the right pins?! my data struct is uint16_t and I send the HEX value I got from the GUI while manipulating the right registers with the mouse. For the meas_conf 1:4 everything works fine.

**Attention** This is a public forum