SAM4S TWI -NO START condition in "twi_master_write "

Moderator: nferre

paragn
Posts: 3
Joined: Tue Aug 11, 2015 6:33 am

SAM4S TWI -NO START condition in "twi_master_write "

Tue Aug 11, 2015 12:37 pm

Hello
Im using SAM4S Explained pro board to interface gyroscope using I2C ie TWI.
"twi_master_write()" is a function given in Atmel ASF. I'm not finding any line written in the code which will start the data transfer..
Can you explain me which line is showing the start condition? or If I'm thinking wrong please correct me...

the function code is attached below. (I took it from twi.c)

Code: Select all

uint32_t twi_master_write(Twi *p_twi, twi_packet_t *p_packet)
{
	uint32_t status;
	uint32_t cnt = p_packet->length;
	uint8_t *buffer = p_packet->buffer;

	/* Check argument */
	if (cnt == 0) {
		return TWI_INVALID_ARGUMENT;
	}

	/* Set write mode, slave address and 3 internal address byte lengths */
	p_twi->TWI_MMR = 0;
	p_twi->TWI_MMR = TWI_MMR_DADR(p_packet->chip) |
			((p_packet->addr_length << TWI_MMR_IADRSZ_Pos) &
			TWI_MMR_IADRSZ_Msk);

	/* Set internal address for remote chip */
	p_twi->TWI_IADR = 0;
	p_twi->TWI_IADR = twi_mk_addr(p_packet->addr, p_packet->addr_length);

	/* Send all bytes */
	while (cnt > 0) {
		status = p_twi->TWI_SR;
		if (status & TWI_SR_NACK) {
			return TWI_RECEIVE_NACK;
		}

		if (!(status & TWI_SR_TXRDY)) {
			continue;
		}
		p_twi->TWI_THR = *buffer++;

		cnt--;
	}

	while (1) {
		status = p_twi->TWI_SR;
		if (status & TWI_SR_NACK) {
			return TWI_RECEIVE_NACK;
		}

		if (status & TWI_SR_TXRDY) {
			break;
		}
	}

	p_twi->TWI_CR = TWI_CR_STOP;

	while (!(p_twi->TWI_SR & TWI_SR_TXCOMP)) {
	}

	return TWI_SUCCESS;
}

Return to “SAM9-based”

Who is online

Users browsing this forum: Google [Bot] and 1 guest