Other Parts Discussed in Thread: CC3220SF,
Tool/software: Code Composer Studio
Good day,
I am attempting to use the TCA6424A IO Expander when interfacing with the CC3220SF MCU as the master. Both devices are Texus Instruments ICs.
the issue I am facing is that after the first write trancaction on the I2C bus, I am able to further communicate with the TCA6424A.
Steps to reproduce are as follows:
- Initialise I2C bus using pins 9 & 10 on the CC3220SF as the SCl & SDA lines.
- setting up the I2C transaction using 100KHz
- specifying the tx buffer which has two bytes tx[0] = device register address tx[1] = data to be written to the register
- initiating the I2C transfer using I2C_transfer(). And testing if the I2C transfer returns true or false.
- the first write returns true, indicating the first write was a success.
- attempt to do a second I2C write transaction using the I2C_transfer function, which now returns false. Indicating the transaction failed.
After putting the SCL & SDA lines on the oscilliscope, I noticed the following:
- The first write transfer is successful, after 300ms the sda line goes low and then pulses up for 300ms at 12.5s intervals
- trying to write to the TCA6424A after that fails
- Reseting the TCA6424A in code and then attempting to do another write transaction , is succesful
- resenting the mcu releases the sda line, and then I can write to the TCA6424A again.
- Immediately after the first write I hold the TCA6424A in reset, in this case the SDA line is not pulled low.
- I have also tried to recover the SDA line by manually toggling the SCL pins. but with no success.
void i2c_init(void)
{
I2C_Params i2cParams;
I2C_init();
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
strak_i2c = I2C_open(neroSTRAKv1_I2C0, &i2cParams);
if (strak_i2c == NULL) {
//while (1);
UART_PRINT("I2C Failed to initialize !\r\n");
} else
{
UART_PRINT("I2C initialized\r\n");
}
}
#################################################################
uint32_t iox_write_axsem_cs_pin_config(void)
{
uint8_t txBuffer[2];
// uint8_t rxBuffer[1];
I2C_Transaction i2cTransaction;
txBuffer[0] = IOX_CMD_CONFIG_P0;
txBuffer[1] = PORT0_DIR_MASK;
i2cTransaction.slaveAddress = I2C_IOExpander_Addr >> 1; //read
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
//i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 0;
if (I2C_transfer(strak_i2c, &i2cTransaction))
{
UART_PRINT("IOX AXSEM pin output config complete\r\n");
return 1;
}else
{
iox_reset();
UART_PRINT("IOX AXSEM pin output config failed\r\n");
return 0;
}
###########################################################33}
void twi_recover(uint8_t pulses)
{
GPIO_PinConfig pinConfig_sda;
GPIO_PinConfig pinConfig_scl;
GPIO_setConfig(pinI2C_SDA, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
GPIO_setConfig(pinI2C_SCL, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
uint8_t i = 0;
uint8_t j = 10;
for (i = 0; i < pulses ; i++)
//while(1)
{
// GPIO_write(pinI2C_SDA, 0);
// //usleep(j);
// __delay_cycles(67);;
GPIO_write(pinI2C_SCL, 0);
//usleep(j);
__delay_cycles(67);
// GPIO_write(pinI2C_SDA, 1);
// //usleep(j);
// __delay_cycles(67);;
GPIO_write(pinI2C_SCL, 1);
// //usleep(j);
__delay_cycles(67);
}
I2C_close(strak_i2c);
i2c_init();
usleep(500000);
}
########################################
main()
{
GPIO_init();
iox_init_pins(); //Once taken out of reset all lines are inputs with pull up
SPI_init();
UART_init();
I2C_init();
iox_write_axsem_cs_pin_config();
sleep(1);
twi_recover(9);
sleep(1);
iox_write_axsem_cs_pin_config();
sleep(1);
while(1);
}