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.

Problem with I2C module to write into slave device

Other Parts Discussed in Thread: TM4C123GH6PM

Hello,

I have a Tiva C Series Launchpad with TM4C123GH6PM microcontroller and I use CCS v6.0

I want to program a MCP4451-103 DPOT (datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/MCP4451.pdf).

I want to write in DPOT a single resistor value and stop.

At page 59 of MCP4451 datasheet there is a "I2C write sequence" figure.

RESET pin is always settled in high state, "1".

In my code with the string:

#define SLAVE_ADDRESS 0x2E       // (with A1="1", and A0="0")

I2CSlaveEnable(I2C0_BASE);

I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);

I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

IntMasterEnable();

ui32DataTx = 0x10;

I2CMasterDataPut(I2C0_BASE, ui32DataTx);

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

I think that, with this code, I don't specify the "write command" which is indicate in the  "I2C write sequence" figure at page 59 of MCP4451 datasheet.

With this code I measure always the mid value (5 kohm) between the A or B terminal and the wiper terminal.

The data doesn't arrives in the slave devices.

I hope that you can help me.

Thanks,

Ivan

  • Hello Ivan,

    Looking at the code snippet, first of all the Slave device is MCP4451. However you have configured the I2C Slave Module as well using

    I2CSlaveEnable(I2C0_BASE);

    I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);

    which will cause the I2C0 to respond as a Slave as well and since data is not read from the I2C0-Slave it will hold the bus. So please remove the Slave code from the I2C Initialization.

    Also next time around (if the suggestion does not work), attach the code so that we can check if Pins are well configured, clock is well configured, etc.

    Regards

    Amit

  • Thanks for the rapidity.

    I have eliminated the the strings "I2CsLAVEeNABLE(I2C0_BASE)" e "I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS)", but I don't resolv the proble

    I have attached the file. In the file there are more commented strings becouse the file is a full project, but now I just try to run the module i2c.

    To program the interrupt handler I have modify the tm2c123gh6pm_startup_ccs.c file how is shown in the TM4C123G_workshop_workbook pdf file at page 102.

    Thanks,

    Ivan

    8004.I2C Module to write into MCP4451.doc

  • Hello Ivan,

    Please replace the line below

    I2CSlaveIntEnableEx(I2C0_BASE, I2C_MASTER_INT_DATA);

    with

    I2CMasterIntEnableEx(I2C0_BASE, I2C_MASTER_INT_DATA);

    since you have to get an interrupt from the. Similarly all operation for the Interrupt Handler like Status and Clear have to have Master and not Slave.

    Is there an external pull up on the board.

    Regards

    Amit

  • I have modify the lines but the result is the same.

    In my board there is the 10 kohm external pull-up resistor between the SDA/SCL lines and Vdd.

    With this code, I read with the tester, at the all four output, the resistor value that is 10 kohm between pin A and pin B, and 5 kohm between pin A or B and the Wiper pin.

    Thanks,

    Antonino 

  • Hello Ivan,

    I had to go through the MCP4451 data sheet and it seems that way it works is as follows

    Start-Slave Address-Write Command-Write Data-Stop

    The sequence that you have will do

    Start-Slave Address-Write Command-Stop

    So the code needs to be modified as

    I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

    ui32DataTx = 0x10; // Write Command

    I2CMasterDataPut(I2C0_BASE, ui32DataTx);

    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    while(I2CMasterBusy(I2C0_BASE));

    ui32DataTx = 0x??; // Write Data

    I2CMasterDataPut(I2C0_BASE, ui32DataTx);

    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

    while(I2CMasterBusy(I2C0_BASE));

    Regards

    Amit

  • Hello Amit,

    Thank you very much. On monday morning, I'll try.

    Best regards,

    Ivan

  • Hello Amit,

    I have try but I don't resolve the problem.

    I have try to modify the code but the result is the same. I attached the file with the code and I hope that you can try the error.

    5153.code_Tiva_MCP4451.doc

    Thanks.

    Best regards,

    Ivan

  • Hello Ivan,

    Please check the data sheet. It mentions that the two bits after AD3 to AD0 have to be 0, while you are putting the work 0x38. Instead it should be 0x70.

    Also this has to be done before the below command and not after it.

    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    If it still does not help, it would be good to have a scope plot.

    Regards

    Amit

  • Hello,

    I decided to try the TPL0102 digital potentiometer.

    Thanks,

    Ivan

  • Hello,

    TPL0102 run!!!

    The correct write sequence is:


    /* enable the master module an set the rate of communication at 100 kHz */
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
    I2CMasterEnable(I2C0_BASE);
    while(I2CMasterBusy(I2C0_BASE));

    /* set the slave address and the W/R bit --> “write bit” (“0”) and send the first byte */
    I2CMasterSlaveAddrSet(I2C0_BASE, 0x50, false);
    while(I2CMasterBusy(I2C0_BASE));
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    /* set the bits value of IVRA register */
    ui32DataTx = 0x00;
    /* send the second byte */
    I2CMasterDataPut(I2C0_BASE, ui32DataTx);
    while(I2CMasterBusy(I2C0_BASE));
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);

    /* set the write data bits */
    ui32DataTx = 0xFF;
    /* send the third byte */
    I2CMasterDataPut(I2C0_BASE, ui32DataTx);
    while(I2CMasterBusy(I2C0_BASE));
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

    Thanks Amit for the help!

    Ivan