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.

MCT8329A: i2c write sequence

Part Number: MCT8329A

Hi, I am working on my own script to be able to write to the registers of MCT8329A using i2c.

In the datasheet everything feels a bit contradictive. I for example don't understand these examples. Look at the marked areas. These values does not seem to correspond?

So my question is if there is any additional information hidden somewhere on how these bits and bytes are constructed?

If one could get a real example on how to write 4 data bytes into a register, that would be awesome.

As an example coult be writing to a device with address 0x60 to register 0x00000080 with 4 empty(0x00) bytes, without crc.

What are the exact bytes I will send for that?

What I have now i something like this;

  i2c.beginTransmission(0x60);
  i2c.write(uint8_t(0x20)); 
  i2c.write(uint8_t(0x80)); 
  i2c.write(uint8_t(register)); 
  i2c.write(uint8_t(byte1)); 
  i2c.write(uint8_t(byte2)); 
  i2c.write(uint8_t(byte3)); 
  i2c.write(uint8_t(byte4)); 
  i2c.endTransmission();

But that is obviously wrong. 

So how would I do?

  • Hi Mikael,

    In the datasheet everything feels a bit contradictive. I for example don't understand these examples. Look at the marked areas. These values does not seem to correspond?

    These value in the final row is the summation of the bits in the row above it which is still in its same column. Some of the hex values in row 4 are the combination of multiple bits. DLEN for example is the combination of CW21 and CW20. Breaking down the columns for Control Word 0 for the l2nd example table the bits are CW23 = 0, CW22 = 1, CW21 = 1, CW20 = 0, CW19 = 0, CW18 = 0, CW17 = 0, CW16 = 0. All these Control Word 0 bits combined is 0110 0000 = 0x20.

    Hope this helps explain how the last row values are determined. 

    If one could get a real example on how to write 4 data bytes into a register, that would be awesome.

    You can look at our example code for programming with the MSP430 for an example for writing to a register here: https://e2e.ti.com/support/motor-drivers-group/motor-drivers/f/motor-drivers-forum/1246892/faq-program-mcx-bldc-motor-driver-through-i2c-using-msp430-launchpad

    In general the structure would be:

    addr = 0x80;
    i2c.beginTransmission(0x60); //start transmission and send target ID
    i2c.write(uint8_t(0x10)); //send Control Word 0 (CW23-CW16) for 32-bit write opperation (4 data bytes) no CRC
    i2c.write(uint8_t((addr&0x00000F00)>>8)); //send Control Word 1 (CW15-CW8) bits CW15-CW12 will always be 0, addr==0x80
    i2c.write(uint8_t((addr&0x000000FF)>>8)); //send Control Word 2 (CW7-CW0) bits for the rest of the register address, addr==0x80
    i2c.write(uint8_t(byte1)); //byte1 = 0x00
    i2c.write(uint8_t(byte2)); //byte2 = 0x00
    i2c.write(uint8_t(byte3)); //byte3 = 0x00
    i2c.write(uint8_t(byte4)); //byte4 = 0x00
    i2c.endTransmission();

    For the specific example of Target ID = 0x60 to register 0x80 with 0x00 for all data bytes, no CRC, I will change the Data to be equal to 0x1234ABCD to show the order the data bits should be sent:

    i2c.beginTransmission(0x60); //start transmission and send target ID
    i2c.write(uint8_t(0x10)); //send Control Word 0 (CW23-CW16) for 32-bit write opperation (4 data bytes), no CRC
    i2c.write(uint8_t(0x00); //send Control Word 1 (CW15-CW8) bits CW15-CW12 will always be 0
    i2c.write(uint8_t(0x80); //send Control Word 2 (CW7-CW0) bits for the rest of the register address
    i2c.write(uint8_t(0xCD));
    i2c.write(uint8_t(0xAB));
    i2c.write(uint8_t(0x34));
    i2c.write(uint8_t(0x12));
    i2c.endTransmission();

    Regards,

    Joshua

  • Thanks, I will be looking into it and report back.

    /Mikael

  • Ok. I think i got it. But it ends up being 0x60, like the datasheet, right?

    With a small change I can now write to a register and then successfully read it back. Thanks!

  • Hi Mikael,

    But it ends up being 0x60, like the datasheet, right?

    I assume that you are referring to the Control Word 0 correct? In case you are referring to the Target ID, this value is, by default, 0x60 and can be changed by changing the value in the bit field I2C_TARGET_ADDR in register PIN_CONFIG2.

    For the Control Word 0, if you are writing to a register and do not need CRC then the Control Word 0 value we recommend using is 0x10, this sets the length of the written data to be 32-bit (which is the full size of a single MCT8329 register) and does not enable CRC. If CRC is needed then using 0x60 for Control Word 0 will write 32-bits of data and enable CRC. For more information about what each bit field in the whole control word does, please refer to Table 7-5 in the datasheet and the descriptions below the table.

    Regards,

    Joshua