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.

cc3200 can't setup i2c communication

Other Parts Discussed in Thread: CC3200, MSP430G2553

Hi,

I'm trying to setup i2c, but with no success. I'll be grateful if somebody can point me to what I'm doing wrong.

Here is my code:

PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK);

// Configure PIN_01 for I2C0 I2C_SCL
PinTypeI2C(PIN_01, PIN_MODE_1);

// Configure PIN_02 for I2C0 I2C_SDA
PinTypeI2C(PIN_02, PIN_MODE_1);



MAP_PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK);
MAP_PRCMPeripheralReset(PRCM_I2CA0);

MAP_I2CMasterInitExpClk (PRCM_I2CA0, 80000000, false);


// send 0x01 byte - this part works fine on a tiva launchpad, but not here
I2CMasterSlaveAddrSet(PRCM_I2CA0, 0x42 >> 1, false);
I2CMasterDataPut (PRCM_I2CA0, 0x01);
I2CMasterControl (PRCM_I2CA0, I2C_MASTER_CMD_SINGLE_SEND);

while(I2CMasterBusy(PRCM_I2CA0));  // <-- it hangs here

So it always hangs in the while loop and looking with the LA - no data is sent - both lines remain dead.

My wirings are SCL -> p01, SDA -> p02

Both lines have pull up resistors and I've removed the J2, J3, J4 jumpers.

Any idea what I may be doing wrong?

Thanks in advance!

  • I managed to get i2c communication, but using the i2c_demo program and using the p01, p02 pins.

    I put back the j2, j3 jumpers - looks like this way no pull ups are needed.

    So I get communication now, but problem is I2C works only on p01 and p02.

    If I change the pinmux to this (taken from the camera demo):

    // Configure PIN_16 for I2C0 I2C_SCL
    PinTypeI2C(PIN_16, PIN_MODE_9);
    
    // Configure PIN_17 for I2C0 I2C_SDA
    PinTypeI2C(PIN_17, PIN_MODE_9);

    i2c still keeps working on p01 and p02... And doesn't work on 16 and 17.

    I had a similar problem with UART (http://e2e.ti.com/support/wireless_connectivity/f/968/p/370679/1303668.aspx#1303668) and problem there was that the breakout board routes only certain pins to the uart and not all that are shown in the pinmux tool. So they had to be routed manually... 

    Is it the same here? Is this how the camera booster pack manages to use the 16 and 17 pins - by some additional routing? How can I figure out what needs to be routed where?

  • Hi Lacho,

    Thats right! On the launchpad, only certain lines are routed from the chip to the on-board sensors to work using I2C. Similarly, to work with the camera BP, pin 16 and 17 are used and the I2C lines on the Camera BP are connected accordingly.

    Best regards,

    Naveen

     

  • Thanks Naveen, yet I can't figure out what connections I need to make in order to make an external i2c device work on pins 16 and 17.

    I understand that in order to read the onboard sensors - only p01 and p02 can be used - 16 and 17 are simply not connected to these sensors.

    But I don't see what's the problem with reading an external i2c device using pins 16 and 17. 

    Looking at the launchpad schematic it seems like the 16 and 17 pins from the cc3200 chip are connected to the same launchpad pins (if I'm reading it right)... So my understanding is that I only need to put some pull-up resistors, do the pinmux and perhaps disconnect j2 and j3 (or maybe not)... but nope - doesn't work :)

    Is there by any chance a schematic already available for the camera booster pack? :) It will be helpful to see how exactly the wiring goes there.

  • Hi Lacho,

    That should have worked.

    Alternately, you could connect J2 and J3 and use p01 and p02 that are also available at the header (P1.9 and P1.10) and connect them to the external i2c device. So you would have one more i2c device on the bus and could use the i2c_demo example to test your device.

    Best regards,

    Naveen

  • Naveen Narayanan said:
    That should have worked.

    That's good to know, so my problem is somewhere else. I'll keep digging to see if I can find it.

    The thing is that pins 01 and 02 are used by the camera interface, so I need to use something else.

    Thanks for the tips!

  • Hi Lacho,

    I hope you are also configuring the SOP pins to be working in SWD mode for debug.

    Quoting from the CC32xx Camera Application.pdf

    Configuring the target device

    1. Ensure SOP 0 is mounted on the CC3200 launchpad. Make sure to remove the same and mount SOP 2 while

    flashing the binary application. Since, TDI and TDO are used for I2C interface, the JTAG is operational in SWD

    mode.

    2. Since SWD mode is used, make sure to un-mount J10 and J11 jumpers so that TDI and TDO lines are not being

    used.

    Best regards,

    Naveen

  • Hi Naveen,

    Unfortunately when I set the jumpers like that I can no longer upload the code with CCS. I tried all kinds of combinations SOP0, SOP2, resetting, replugging the board before upload... whenever I remove the j10 and j11 jumpers - upload stops working.

    But indeed this should be my problem - pins 16 and 17 are used for JTAG, which explains why i2c doesn't work for them.

    I'll play with this a bit more to see if I can get it to work.

  • Hi Lacho,

    Please refer to section on "Executing a Project" in the CC3200-Programmers_Guide document to configure CCS to work in SWD mode. This could resolve the issue you are facing with CCS.

    Best regards,

    Naveen

  • Hi Naveen,

    I'm trying out the camera application on CC3200. I do not have the camera BP in hand, so I connect the MT9D111 module to the lunch pad directly. I found that the I2C just issue the start signal and then stay in the while loop polling the byte transmitted flag. I have added the pull up resisters on P16 and P17, removed J10and J11, connected J6 and J7 to BP, removed J2 and J3, mounted SOP0, removed SOP2. Have I missed something? 

    I also tried the i2c_demo application. when I2C is mapped to P01 and P02, it works well, but when mapped to P16 and P17, it didn't work. When mapped to P16 and P17, I also removed J10 and J11, mounted SOP0 and added pull up resisters.

    Is there anything special when using P16 and P17 as I2C?

    Thanks in advance.

    Best regards,

    Guohui

  • Hi Guohui,

    Can you use the I2CMasterLineStateGet() API to to read out the status of the I2C lines before issuing any  I2C command. This should return 0x3, meaning both SDA and SCL lines are pulled up.

    What is the value of the pull up resistors you are using ?

    Thanks and Regards,

    Praveen

  • Hi Praveen,

    Thanks for your quick reply.

    I called the I2CMasterLineStateGet() API before issuing the I2C send command and the return value is indeed 0x03, but there is still the problem. The pull up resisters is 4.7KΩ.

    Best regards,

    Guohui

  • Hi Guohui,

    If you want to use PIN_16 and PIN_17 for I2C you will need to do the following two additional pinmux configurations. By default  the I2C is muxed on to PIN_01 and PIN_02, the following will make sure that the I2C lines are disconnected from PIN_01 and PIN_02.

        //
        // Configure PIN_01 for GPIO
        //
        MAP_PinTypeI2C(PIN_01, PIN_MODE_0);

        //
        // Configure PIN_02 for GPIO
        //
        MAP_PinTypeI2C(PIN_02, PIN_MODE_0);

    PIN16 and P17 are not by default routed to on-board I2C slaves. If you want to test I2C_demo on PIN_16 and PIN_17 you can do the following changes:

    1. Configure Pin mux

        //
        // Configure PIN_01 for GPIO
        //
        MAP_PinTypeI2C(PIN_01, PIN_MODE_0);

        //
        // Configure PIN_02 for GPIO
        //
        MAP_PinTypeI2C(PIN_02, PIN_MODE_0);

        //
        // Configure PIN_16 for I2C0 I2C_SCL
        //
        MAP_PinTypeI2C(PIN_16, PIN_MODE_9);

        //
        // Configure PIN_17 for I2C0 I2C_SDA
        //
        MAP_PinTypeI2C(PIN_17, PIN_MODE_9);

    2. Remove J2, J3, J10 and J11 ans SOP2 jumpers. Mount SOP0 jumper

    3. Wire P16 and P17 to SCL and SDL respectively.

    4. Run the application. Type in the command.

    Setup Snapshot

    Pls post here if you were able to run I2C_demo with P16 and P17.

    Thanks and Regards,

    Praveen

  • Hi Praveen,

    I feel really exciting and appreciate your help. I followed what you said and it worked well!

    Thanks very much!

    Best regards,

    Guohui

  • Mine also worked, big thanks for all the help!

  • Great!.

    Please mark this thread as answered to close it.

    Thanks and Regards,

    Praveen

  • Just to summarize for my initial problem from the first comment:

    PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK);
    
    // Configure PIN_01 for I2C0 I2C_SCL
    PinTypeI2C(PIN_01, PIN_MODE_1);
    
    // Configure PIN_02 for I2C0 I2C_SDA
    PinTypeI2C(PIN_02, PIN_MODE_1);
    
    
    
    MAP_PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK);
    MAP_PRCMPeripheralReset(PRCM_I2CA0);
    
    MAP_I2CMasterInitExpClk (PRCM_I2CA0, 80000000, false);
    
    
    // send 0x01 byte - this part works fine on a tiva launchpad, but not here
    I2CMasterSlaveAddrSet(PRCM_I2CA0, 0x42 >> 1, false);
    I2CMasterDataPut (PRCM_I2CA0, 0x01);
    I2CMasterControl (PRCM_I2CA0, I2C_MASTER_CMD_SINGLE_SEND);
    
    while(I2CMasterBusy(PRCM_I2CA0));  // <-- it hangs here

    So I couldn't make this code work - it always hangs in the while loop. It works on the tiva launchpads, so I'm not sure what's wrong here.

    The way I did it was with the i2c helper functions from the cc3200 api - I2C_IF_Write(), I2C_IF_Read() - which use interrupts.

    However I also had a problem with them - in the i2c_demo program, the readreg command does not work for me.

    It does I2C_IF_Write() and then I2C_IF_Read() -> the read always hangs. And it hangs if it happens quickly after the read.

    I had to put a small delay in I2CTransact():

    while((MAP_I2CMasterIntStatusEx(I2C_BASE, false) 
                    & (I2C_INT_MASTER | I2C_MRIS_CLKTOUT)) == 0)
    {
    }
    
    UtilsDelay(80000);  // <-- I put this
    

    With that delay it works fine now. I always had to put delays for i2c, perhaps this is similar: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/368493.aspx

    So it works now, but the solution is a bit ugly, if anybody knows of a more elegant one, please share :)

  • Hi Lacho,

    Is this issue there with on-board I2C slaves also? If yes which one.

    If no, can you post the details of I2C slave you are using.

    Thanks and Regards,

    Praveen

  • Hi Lacho,
    Just noticed that  the parameters are wrong for the following APIs
    MAP_I2CMasterInitExpClk (PRCM_I2CA0, 80000000, false);
    // send 0x01 byte - this part works fine on a tiva launchpad, but not here
    I2CMasterSlaveAddrSet(PRCM_I2CA0, 0x42 >> 1, false);
    I2CMasterDataPut (PRCM_I2CA0, 0x01);
    I2CMasterControl (PRCM_I2CA0, I2C_MASTER_CMD_SINGLE_SEND);
    while(I2CMasterBusy(PRCM_I2CA0));  // <-- it hangs here
     
    Please replace PRCM_I2CA0 with I2CA0_BASE

    Thanks and Regards,
    Praveen
  • Hi Praveen.

    You had told us that we will need to do the following two additional pinmux configurations.

        //
        // Configure PIN_01 for GPIO
        //
        MAP_PinTypeI2C(PIN_01, PIN_MODE_0);

        //
        // Configure PIN_02 for GPIO
        //
        MAP_PinTypeI2C(PIN_02, PIN_MODE_0);

    for using other pins for i2c.

    is default status of Pin1,2 i2c? why we need to change pin configuration to GPIO for using other pins for i2c. ?

  • hii , i want to know the jumper connection if m interfacing cc3200 with msp430g2553 ??
  • Hi Naveen

    I have some problem with my cc3200 and i2c peripherals.I am using p01 and p02.I have provided the details of my code below.


    I2C_IF_Open(I2C_MASTER_MODE_STD);

    I2C_IF_Write((0x80>>1),0xe5,1,1);

    while(I2CMasterBusy(PRCM_I2CA0));//Hangs here

    I2C_IF_Open(I2C_MASTER_MODE_STD);
    I2C_IF_Read((0x80>>1),&data[0],2);

    My code is hanging at the third line.I have proper pin mux config.I am putting it down.

    PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK);

    //
    // Configure PIN_01 for I2C0 I2C_SCL
    //
    PinTypeI2C(PIN_01, PIN_MODE_1);

    //
    // Configure PIN_02 for I2C0 I2C_SDA
    //
    PinTypeI2C(PIN_02, PIN_MODE_1);

    I dnt know the reason of its hanging.IO am using sht21 which have a device address of 0x40.If I skip this 3rd line then the code is not hanging anywhere but I am not reading any values also.Please help me.

  • Hi,

    I also cant reconfigure I2C on CC3200 to pin 3, 4. I change the pin configuration in pinmux.c but the I2C module still used pin 1, 2. Have you solved this problem?

     //
     // Configure PIN_03 for I2C0 I2C_SCL
     //
        MAP_PinTypeI2C(PIN_03, PIN_MODE_5);
    
     //
     // Configure PIN_04 for I2C0 I2C_SDA
     //
        MAP_PinTypeI2C(PIN_04, PIN_MODE_5);