# I2C issue

Status
Not open for further replies.

#### Salgat

##### New Member
Currently trying to setup I2C on an ARM (LM3S8962) and running into some issues. I'm pretty confident in my code, but for some reason when I reach the receive part I get completely random information from a source that should always be sending a constant value. Hooking it up to the oscilloscope shows that it does recognize my transmit, as it only responds to its address and also replies with an acknowledge after its address is output. However, when it responds to a receive request it is somewhat random (although sometimes repeats values). In addition, the Acknowledge goes to about 2.5V although since it's between a clock cycle I don't think that is an issue. What also bothers me is that even though it even acknowledges my micro, an error will still be flagged even on a single transmit with no receive, even though on the oscilloscope there seems to be no issue.

Code:
    uint32_t status = I2C0_MASTER_MCS_R;

if ( txpos < txlen )
{
I2C0_MASTER_MDR_R = txbuf[txpos++];
I2C0_MASTER_MCS_R = (1<<1) | (1<<0);
}
else if ( rxpos < rxlen )
{
I2C0_MASTER_MSA_R |= (1<<0);
I2C0_MASTER_MCS_R = (1<<2) | (1<<1) | (1<<0);
++rxpos;
}
else if ( rxpos == rxlen)
rxbuf[(rxpos++-1)] = I2C0_MASTER_MDR_R;

#### Salgat

##### New Member
The issue ended up being that I was enabling the master after setting the clock. After enabling the Master first everything was fixed.

Status
Not open for further replies.