bengreen.eu Circle Device

 

Quick Reference

MSP430 I2C

MSP430 I2C

The MSP430 I2C hardware on the MSP430G2553 is simple really but caused me some headaches. Anyway, this is to take you through interrupt driven and non-interrupt driven I2C comms.

Simple sequential version

Waiting for flags with a while loop is very bad... but it can sometimes be useful for debugging.

	// Initialise UCB0
	P1SEL |= BIT6 | BIT7;
	P1SEL2 |= BIT6 | BIT7;
	UCB0CTL1 |= UCSWRST;
	UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC;
	UCB0CTL1 = UCSSEL_2 | UCSWRST;
	UCB0BR0 = 12;
	UCB0BR1 = 0;
	// MCP3422: 1  1  0  1 A0 A1 A2 RW (RW Bit not in UCB0I2CSA)
	UCB0I2CSA = 0x68;
	UCB0CTL1 &= ~UCSWRST;

	// Send a single byte of data
	UCB0CTL1 |= UCTR | UCTXSTT;
	while (!(IFG2 & UCB0TXIFG)); // Wait for I2C Send to Complete
	UCB0TXBUF = 0x90;
	while (!(IFG2 & UCB0TXIFG));
	UCB0CTL1 |= UCTXSTP;
	IFG2 &= ~UCB0TXIFG;

Quick Links: Techie Stuff | General | Personal | Quick Reference