Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

MSP430G2553 and I2C

$
0
0

I have a problem with I2C and the MSP430G2553. Here is my Code:

#include <msp430g2553.h>


const unsigned char Init[] = {0xAE,0x81,0x07,0x20,0x01,0x21,0x00,0x7F,0x22,0x00,0x07,0x40,0xA0,0xA8,0x3F,0xC0,0xD3,0x00,0x8D,0x14,0xDA,0x12,0xD5,0x80,0xD9,0x22,0xDB,0x20,0xA6,0xA4,0xAF};

const unsigned char Mod[] = {0xA5};



void printC(const unsigned char* Array, unsigned int length){
	UCB0CTL1 = UCSWRST;
	UCB0CTL0 = UCMODE_3 + UCMST + UCSYNC;			// I2C master mode
	UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
	UCB0BR0 = 0x40;                          // < 100 kHz
	UCB0I2CSA = 0x3C;                       // address
	UCB0CTL1 &= ~UCSWRST;
	IE2 |= UCB0TXIE;				// Enable TX ready interrupt
	//UCB0I2CIE = UCNACKIE;
	UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition

	unsigned int c;
	for(c = 0; c < length; c++){
		__bis_SR_register(LPM3_bits + GIE);
		UCB0TXBUF = 0x80;
		__bis_SR_register(LPM3_bits + GIE);
		UCB0TXBUF = Array[c];
		//__bis_SR_register(LPM3_bits + GIE);
	}
	__bis_SR_register(LPM3_bits + GIE);

    UCB0CTL1 |= UCTXSTP;
    IE2 &= ~UCB0TXIE;
    IFG2 &= ~UCB0TXIFG;
}

void main(void){
    WDTCTL = WDTPW + WDTHOLD;

    DCOCTL = CALDCO_8MHZ;				//DCO setting = 8MHz
    BCSCTL1 = CALBC1_8MHZ;				//DCO setting = 8MHz

    // Configure Pins for I2C
    P1SEL |= BIT6 + BIT7;                  // Pin init
    P1SEL2 |= BIT6 + BIT7;                  // Pin init


    printC(Init,31);

    __delay_cycles(8000000);

    printC(Mod,1);

    while(1);

}


// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void){
	__bic_SR_register_on_exit(LPM3_bits);               // Wakeup main code
	IFG2 &= ~UCB0TXIFG;
}

The first printC works fine but in the second (printC(Mod,1);) the processor stays in the low power mode forever after entering the for loop. Any ideas?


Viewing all articles
Browse latest Browse all 2077

Trending Articles