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.

Problem with USCB I2C and no acknowledge

Other Parts Discussed in Thread: MSP430F5419A

Hi,

on my board I use a MSP430F5419A with UCB0 for I2C interface. With the following init:

void iic_init(void)
{
	UCB0CTL1 = UCSWRST;							// Enable SW Reset
	UCB0CTL0 = 0x0f;							// I2C Master, synchronous mode
	UCB0CTL1 |= 0x80;							// use SMClk
	UCB0BR0 = 10;								// fSCL = SMCLK/12 = ~100kHz
	UCB0BR1 = 0;
	UCB0IE = 0;
	UCB0CTL1 &= ~UCSWRST;						// Clear SW reset
}

My byte write function looks like this:

bool iic_byte_write(uchar sladr, ushort adr, uchar data, uchar adrlen)
{
	UCB0CTL1 |= UCTR;							// Transmitter

	UCB0I2CSA = sladr >> 1;						// Adresse ohne R/W Bit
	UCB0CTL1 |= UCTXSTT;						// Start Condition

	while (!(UCB0IFG & UCTXIFG));				// Dev Adr gesendet

	if (!(UCB0IFG & UCNACKIFG))					// Ack empfangen
	{
		if (adrlen == 8)
			UCB0TXBUF = adr & 0xff;
		else
			UCB0TXBUF = (adr >> 8) & 0xff;
		while (!(UCB0IFG & UCTXIFG));				// Reg Adr gesendet
		if (!(UCB0IFG & UCNACKIFG))					// Ack empfangen
		{
			if (adrlen == 16)
			{
				UCB0TXBUF = adr & 0xff;
				while (!(UCB0IFG & UCTXIFG));		// Reg Adr gesendet
				if (UCB0IFG & UCNACKIFG)			// Ack nicht empfangen
				{
					UCB0CTL1 |= UCTXSTP;
					return(FALSE);
				}
			}
			UCB0TXBUF = data;						// Datum senden
			while (!(UCB0IFG & UCTXIFG));			// Datum gesendet
			if (!(UCB0IFG & UCNACKIFG))				// Ack empfangen
			{
				UCB0CTL1 |= UCTXSTP;
				return(TRUE);
			}
		}
	}

	UCB0CTL1 |= UCTXSTP;
	return(FALSE);
}

My problem is If I write to a device which is not on the bus the program will hang up. How can I break the function if I don't receive the acknowledge after the device adress?

Thank you for your help.


br

martin sauer

**Attention** This is a public forum