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.

I2C without interrupts, simplest Tx

Hi Folks

(F28027 ControlSTICK)

I am trying to implement a very simple I2C transmit via I2C, currently with the following code execution hangs forever waiting for I2CSTR.bit.XSMT to become 0.

The spec says I2CSTR.bit.XSMT should become 0 after the byte in the I2CDXR has been sent, is this correct usage to pass data to I2CDXR and wait for I2CSTR.bit.XSMT after each byte in a 2-byte message??

Thanks

void main(void)
{
	DeviceInit();				// Device Life support & GPIO mux settings 
	i2caInit();				// I2C settings
	data1 = foo;
	data2 = bar;
	i2cTx(data1);
	i2cTx(data2);
}

void i2cTx(Uint16 txData) 
{
	I2caRegs.I2CMDR.bit.TRX = 1;		// Turn on Tx mode
	I2caRegs.I2CDXR = txData;		// Copy data to Tx buffer
	while (I2caRegs.I2CSTR.bit.XSMT != 0) {}// Wait until Tx buffer is empty again
}

void i2caInit(void)
{
	I2caRegs.I2CMDR.all = 0x6E00;		// Reset on, master transmitter S-A(7)&W-D(8)-P
	I2caRegs.I2CIER.all = 0;		// Disable all I2C interrupt sources
	I2caRegs.I2CPSC.all = 5;		// Prescalar - Module clock must be 7-12 MHz
						// Module clk = SYSCLKOUT/(5+1) = 10MHz
	I2caRegs.I2CCLKL = 0x0037;		// SCL runs at 83.333 kHz 50% duty
	I2caRegs.I2CCLKH = 0x0037;		// SCL runs at 83.333 kHz 50% duty
	I2caRegs.I2CSAR = 0x0017;		// LTC6904 address is 0000010111
	I2caRegs.I2COAR = 0x007F;		// This device address is 1111111
	I2caRegs.I2CCNT = 2;			// LTC6904 sends 2 bytes of info after the address + WR byte
	I2caRegs.I2CFFTX.all = 0;		// Disable Tx FIFO
	I2caRegs.I2CFFRX.all = 0;		// Disable Rx FIFO
	I2caRegs.I2CMDR.bit.IRS = 1;		// Reliquish I2C from reset
}
  • OK have changed line 

     

    while (I2caRegs.I2CSTR.bit.XSMT != 0) {}// Wait until Tx buffer is empty again

     

    to

    while (I2caRegs.I2CSTR.bit.XRDY != 1) {}// Wait until Tx buffer is empty again

    But I'm only getting the first, "addressing + Wr-bit", byte, when I run the I2C initialisation, but no actual message data appears to be sent... Im not sure if my slave device is correctly producing an ACK, is it possible to set the I2C module not to expect an ACK?

    Ta

     

  • Hi Toby,

    No its not possible to drop the ACK its part of the I2C spec and so this is built into the hardware state machine.