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.

MSP432P401R: read data from TCA9535

Part Number: MSP432P401R
Other Parts Discussed in Thread: TCA9535, MSP430G2553

I try to use the demo boostxl_edumkII_lightSensor_msp432p401r to read data from TCA9535,like this 

const eUSCI_I2C_MasterConfig i2cConfig =
{
        EUSCI_B_I2C_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
        24000000,                               // SMCLK = 48MHz
        EUSCI_B_I2C_SET_DATA_RATE_100KBPS,      // Desired I2C Clock of 100khz
        0,                                      // No byte counter threshold
        EUSCI_B_I2C_NO_AUTO_STOP                // No Autostop
};

static void TCA9535_Write(ST_TCA9535* a_pstTCA9535, C_U8 a_u8RegAddr, C_U8 a_u8RegData)
{

/* Specify slave address for I2C */
I2C_setSlaveAddress(EUSCI_B3_BASE,
	(a_pstTCA9535->m_DevAddr));
  
/* Enable and clear the interrupt flag */
I2C_clearInterruptFlag(EUSCI_B3_BASE,
	EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_RECEIVE_INTERRUPT0);

/* Set master to transmit mode PL */
   I2C_setMode(EUSCI_B3_BASE,
	   EUSCI_B_I2C_TRANSMIT_MODE);
 
   /* Clear any existing interrupt flag PL */
   I2C_clearInterruptFlag(EUSCI_B3_BASE,
	   EUSCI_B_I2C_TRANSMIT_INTERRUPT0);

   /* Wait until ready to write PL */
   while (I2C_isBusBusy(EUSCI_B3_BASE));
 

   /* Initiate start and send first character */
   I2C_masterSendMultiByteStart(EUSCI_B3_BASE,
	   a_u8RegAddr);

	 
   I2C_masterSendMultiByteFinish(EUSCI_B3_BASE,
	  a_u8RegData);
 }

static void TCA9535_Read(ST_TCA9535* a_pstTCA9535, C_U8 a_u8RegAddr, C_U8* a_u8RegData)
{
	
	/* Specify slave address for I2C */
	I2C_setSlaveAddress(EUSCI_B3_BASE,
		(a_pstTCA9535->m_DevAddr));
	
	/* Enable and clear the interrupt flag */
	I2C_clearInterruptFlag(EUSCI_B3_BASE,
		EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_RECEIVE_INTERRUPT0);


    /* Set master to transmit mode PL */
    I2C_setMode(EUSCI_B3_BASE,
        EUSCI_B_I2C_TRANSMIT_MODE);
 
    /* Clear any existing interrupt flag PL */
    I2C_clearInterruptFlag(EUSCI_B3_BASE,
        EUSCI_B_I2C_TRANSMIT_INTERRUPT0);

    /* Wait until ready to write PL */
    while (I2C_isBusBusy(EUSCI_B3_BASE));

    /* Initiate start and send first character */
    I2C_masterSendMultiByteStart(EUSCI_B3_BASE, a_u8RegAddr);

    /* Wait for TX to finish */
    while(!(I2C_getInterruptStatus(EUSCI_B3_BASE,
        EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));

    /* Initiate stop only */
    I2C_masterSendMultiByteStop(EUSCI_B3_BASE);



    /*
     * Generate Start condition and set it to receive mode.
     * This sends out the slave address and continues to read
     * until you issue a STOP
     */
		*a_u8RegData = I2C_masterReceiveSingleByte(EUSCI_B3_BASE);
    //I2C_masterReceiveStart(EUSCI_B3_BASE);

    /* Wait for RX buffer to fill */
  //  while(!(I2C_getInterruptStatus(EUSCI_B3_BASE,
       // EUSCI_B_I2C_RECEIVE_INTERRUPT0)));

    /* Receive second byte then send STOP condition */
   // *a_u8RegData = I2C_masterReceiveMultiByteFinish(EUSCI_B3_BASE);
	
}

void TCA9535_Init(ST_TCA9535* a_pstTCA9535, C_U8 a_u8DevAddr)
{
    a_pstTCA9535->m_DevAddrW = (a_u8DevAddr << 1) | 0; // Addr + Write
    a_pstTCA9535->m_DevAddrR = (a_u8DevAddr << 1) | 1; // Addr + Read
    a_pstTCA9535->m_DevAddr = a_u8DevAddr;
	
    GPIO_setAsPeripheralModuleFunctionOutputPin(
            SCL_PORT,
            SCL_PIN,
            GPIO_SECONDARY_MODULE_FUNCTION);

    GPIO_setAsPeripheralModuleFunctionOutputPin(
            SDA_PORT,
            SDA_PIN,
            GPIO_SECONDARY_MODULE_FUNCTION);

			/* Initialize USCI_B0 and I2C Master to communicate with slave devices*/
	  I2C_initMaster(EUSCI_B3_BASE, &i2cConfig);
	
	  /* Disable I2C module to make changes */
	  I2C_disableModule(EUSCI_B3_BASE);
	
	  /* Enable I2C Module to start operations */ 
	 I2C_enableModule(EUSCI_B3_BASE);
	  /* Select I2C function for I2C_SCL(P6.5) & I2C_SDA(P6.4) */
}

 but it will stuck in

while (I2C_isBusBusy(EUSCI_B3_BASE));

because the UCBBUSY is alwasy set.
And i found that UCBBUSY is set right after i do I2C_enableModule(EUSCI_B3_BASE);
and never reset, but i haven't begun to send a byte.

or i will stuck in 

I2C_masterSendMultiByteFinish(EUSCI_B3_BASE,
a_u8RegData);

do you know why?

  • I haven't been able to find a TCA9535 in the edumkii schematics. Is this an offboard I2C circuit?

    The first thing I would check (particularly for this symptom) is the SCL/SDA pullups.
  • hello Bruce, I found that when i used debug step by step, it will not stuck,but if i run directly, it will stuck in while (I2C_isBusBusy(EUSCI_B3_BASE)); or I2C_masterSendMultiByteFinish(EUSCI_B3_BASE,
    a_u8RegData);

  • What are your SDA/SCL Pull-up resistor values? Typically we recommend between 4k and 10kohm.
  • it's 4.7kohm
  • User,

    Have you seen the code that the TCA9535 Team provides with their device? It's written on a MSP430G2553 16-bit device but I would suggest consulting how they have set up their TCA device to ensure that your code follows their recommendation in code and documentation and then looking at the I2C of the MSP432 accordingly.

    I would also maybe see about increasing your I2C Pull-ups just in case. The datasheet for the TC9535 device goes through a decent amount of steps for calculating the appropriate pull-up resistors. Have you gone through this process? www.ti.com/.../tca9535.pdf

    As you walk through their code/documentation, you can reference the many I2C examples we have both in driverlib and as demo's as you've pointed out. I believe this example would be a really helpful place to start. We ensure that these examples are tested with each release and work. dev.ti.com/.../

    Another good place for solving common I2C issues with the USCI peripheral, if all else fails is this app note: www.ti.com/.../slaa734.pdf

    Feel free to ask any follow up questions.

**Attention** This is a public forum