AVR1308 TWI master to HMC6343 slave

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to use the TWI interface on an xmega 128a1 to interface to a Honeywell HMC6343 compass chip. It seems that I'm not getting the acknowledgment from the slave as I'm hitting that point in the ISR.

/*! \brief TWI master write interrupt handler.
 *
 *  Handles TWI transactions (master write) and responses to (N)ACK.
 *
 *  \param twi The TWI_Master_t struct instance.
 */
void TWI_MasterWriteHandler(TWI_Master_t *twi)
{
	/* Local variables used in if tests to avoid compiler warning. */
	uint8_t bytesToWrite  = twi->bytesToWrite;
	uint8_t bytesToRead   = twi->bytesToRead;

	/* If NOT acknowledged (NACK) by slave cancel the transaction. */
	if (twi->interface->MASTER.STATUS & TWI_MASTER_RXACK_bm) {
//hit breakpoint here
		twi->interface->MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc;
		twi->result = TWIM_RESULT_NACK_RECEIVED;
		twi->status = TWIM_STATUS_READY;
	}

	/* If more bytes to write, send data. */
	else if (twi->bytesWritten < bytesToWrite) {
		uint8_t data = twi->writeData[twi->bytesWritten];
		twi->interface->MASTER.DATA = data;
		++twi->bytesWritten;
	}

	/* If bytes to read, send repeated START condition + Address +
	 * 'R/_W = 1'
	 */
	else if (twi->bytesRead < bytesToRead) {
		uint8_t readAddress = twi->address | 0x01;
		twi->interface->MASTER.ADDR = readAddress;
	}

	/* If transaction finished, send STOP condition and set RESULT OK. */
	else {
		twi->interface->MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc;
		TWI_MasterTransactionFinished(twi, TWIM_RESULT_OK);
	}
}

On a scope I can see the clock line wiggle but not the data line. I'm using TWID, both port lines are set as inputs. What am I missing? Has anybody used this example code and got it working?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kscharf wrote:
Has anybody used this example code and got it working?

I used AVR1308 for interfacing AT24Cxx to XMEGA. There was a special tip in slave address assignment. By setting 0xA0 as slave address, eeprom did not respond. But finally I got the solution: 0x50 is the correct slave address, according to a shift to left in code.

Ozhan KD
Knowledge is POWER

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seems I fell victim to the same issue others have reported about the address being shifted to make room for the read/write bit. I thought I had accounted for that in my code. Rats.
Anyway it works now.