Unable to generate a I2C start condition!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to generate a I2C start condition!

777 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jose_peeterson on Sat Oct 13 10:22:22 MST 2012
Hi all,

        I am using I2C to communicate with a slave. The code gets stuck and does not ocntinue. the problem is in the start command.



my transfer setup inside write funciton.


static int I2CWrite(uint8_t addr, uint8_t* buf, uint32_t len)
{
I2C_M_SETUP_Type txsetup;

txsetup.sl_addr7bit = addr;
txsetup.tx_data = buf;
txsetup.tx_length = len;
txsetup.rx_data = NULL;
txsetup.rx_length = 0;
txsetup.retransmissions_max = 3;



the code goes in here [B]start command[/B]. it gets stuck in the i2c_start function.


Status I2C_MasterTransferData(LPC_I2C_TypeDef *I2Cx, I2C_M_SETUP_Type *TransferCfg, \
I2C_TRANSFER_OPT_Type Opt)
{
uint8_t *txdat;
uint8_t *rxdat;
uint32_t CodeStatus;
uint8_t tmp;

// reset all default state
txdat = (uint8_t *) TransferCfg->tx_data;
rxdat = (uint8_t *) TransferCfg->rx_data;
// Reset I2C setup value to default state
TransferCfg->tx_count = 0;
TransferCfg->rx_count = 0;
TransferCfg->status = 0;

if (Opt == I2C_TRANSFER_POLLING){

/* First Start condition -------------------------------------------------------------- */
TransferCfg->retransmissions_count = 0;
retry:
// reset all default state
txdat = (uint8_t *) TransferCfg->tx_data;
rxdat = (uint8_t *) TransferCfg->rx_data;
// Reset I2C setup value to default state
TransferCfg->tx_count = 0;
TransferCfg->rx_count = 0;
CodeStatus = 0;

// Start command
CodeStatus = I2C_Start(I2Cx);
if ((CodeStatus != I2C_I2STAT_M_TX_START) \
&& (CodeStatus != I2C_I2STAT_M_TX_RESTART)){
TransferCfg->retransmissions_count++;
if (TransferCfg->retransmissions_count > TransferCfg->retransmissions_max){
// save status
TransferCfg->status = CodeStatus;
goto error;
} else {
goto retry;
}
}





it gets stuck here in the [B]while[/B] .
/***********************************************************************
 * Function: I2C_Start
 * Purpose: Generate a start condition on I2C bus (in master mode only)
 * Parameters:
 *     i2cdev: Pointer to I2C register
 *     blocking: blocking or none blocking mode
 * Returns: value of I2C status register after generate a start condition
 **********************************************************************/
static uint32_t I2C_Start (LPC_I2C_TypeDef *I2Cx)
{
I2Cx->I2CONCLR = I2C_I2CONCLR_SIC;
I2Cx->I2CONSET = I2C_I2CONSET_STA;

// Wait for complete
while (!(I2Cx->I2CONSET & I2C_I2CONSET_SI));
I2Cx->I2CONCLR = I2C_I2CONCLR_STAC;
return (I2Cx->I2STAT & I2C_STAT_CODE_BITMASK);
}



VALUES of
/*******************************************************************//**
* I2C Control Set register description
*********************************************************************/
#define I2C_I2CONSET_AA((0x04)) /*!< Assert acknowledge flag */
#define I2C_I2CONSET_SI((0x08)) /*!< I2C interrupt flag */
#define I2C_I2CONSET_STO((0x10)) /*!< STOP flag */
#define I2C_I2CONSET_STA((0x20)) /*!< START flag */
#define I2C_I2CONSET_I2EN((0x40)) /*!< I2C interface enable */


/*******************************************************************//**
* I2C Control Clear register description
*********************************************************************/
/** Assert acknowledge Clear bit */
#define I2C_I2CONCLR_AAC((1<<2))
/** I2C interrupt Clear bit */
#define I2C_I2CONCLR_SIC((1<<3))
/** START flag Clear bit */
#define I2C_I2CONCLR_STAC((1<<5))
/** I2C interface Disable bit */
#define I2C_I2CONCLR_I2ENC((1<<6))
0 Kudos
2 Replies

642 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Sun Oct 14 09:10:38 MST 2012
Maybe the i2c slave is in an undefined state, because of some startup event. A common method to deal with this is to redeclare the i2c pins as output (SCL) and input (SDA), and sending clock impulses until the slave releases SDA.
0 Kudos

642 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Sat Oct 13 10:51:01 MST 2012
May be I2C clock disabled?

LPC_SYSCON->SYSAHBCLKCTRL|=(1<<LPC_AHBCLK_I2C);
0 Kudos