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.

Implementing USCI I2C in MPSF21x2 Microcontrollers

I have been trying to develop some simple code that writes 3 bytes to a digital volume control using the I2C interface.  I am using the 'B' side of the USCI module.  (The 'A' side is being used as a UART.  The code for the 'A' side works great!  I developed some code using the 'B' side in SPI mode and that works great too!.)

The environment is as follows: MPSF2132 and DCO=1.000MHz

The processor initialization code is:

// Initialize the watchdog timer:

WDTCTL = WDTPW + WDTHOLD;

// stop the watchdog timer

 

// Initialize the i/o ports:

 

P1DIR |= 0x0f;

// set P1 [3..0] for output

P1OUT |= 0x07;

// deselect the peripheral devices

P2DIR |= 0x07;

// set P1 [2..0] for output

P2OUT |= 0x07;

// turn the LED's off

P3DIR |= 0x40;

// set P3 [6] for output

P3SEL = 0x3e;

// set P3 [5..1] for peripheral fun

 

// Set to use the DCO clock @ 1.000 mhz:

 

BCSCTL1=CALBC1_1MHZ;

// set internal DCO for 1.000 mhz

DCOCTL=CALDCO_1MHZ;

BCSCTL2=

// set to use DCO for MCLK

SELM_0+

// MCLK source select (0=DCOCLK)

DIVM_0+

// MCLK divider select (0=1)

DIVS_0;

// SMCLK divider select (0=1)

 

 

 With the code below, I cannot get the USCI to do anything!  (It doesn't even send the slave address.) 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

// WriteRegsDVC

// Routine to write a byte of configuration data and the two wiper control

// settings in the DVC registers.

 

// Calling Sequence:

// WriteRegsDVC (uWiper1, uWiper2);

 

void  

 

 

{

// Initialize/configure UART B for I2C mode:

// Configuration settings

// ---------------------------------

// I2C mode enabled

// Transmitter mode selected

// Master mode selected

// Synchronous mode enabled

// 25,000 bps rate

// Slave address = 0x50

 

   SLECT_DVC;                          

// select the device

   UCB0CTL1=

         UCSSEL1+                     

// clock source select (10=SMCLK)

        UCSWRST;                       

// software reset enabled

   UCB0CTL0=

      UCMST+                                     

// master mode

      UCMODE1+                                

// I2C mode

     UCMODE0+               

      UCSYNC;                                   

// synchronous mode

   UCB0BR0=40;

   UCB0BR1=0;                                 

// set the clock for 25,000 bps

   UCB0CTL1 &= ~(UCSWRST);        

// enable the I2C

 

   UCB0CTL1 |= (UCTR+UCTXSTT);   

// generate start and send address

 

 

 

   while (!(IFG2 & UCB0TXIFG))        // wait for start to be sent

   {

   }

 

   UCB0TXBUF=0x80;                    

// write the configuration byte

 

 

   while (!(IFG2 & UCB0TXIFG))      // wait for tx buffer to be empty

   {

   }

 

   UCB0TXBUF=(uWiper1 + 0x00); 

// write the wiper #1 setting

 

 

   while (!(IFG2 & UCB0TXIFG))     // wait for tx buffer to be empty

   {

   }

 

   UCB0TXBUF=(uWiper2 + 0x40);  

// write the wiper #2 setting

   UCB0CTL1 |= UCTXSTP;            

// set to generate stop condition

 

 

   while (!(IFG2 & UCB0TXIFG))      // wait for tx buffer to be empty

   {

   }

   DESLECT_DVC;                       

// deselect the device

}

I would be very grateful to anyone that can provide some insight into this problem.  It really is driving me crazy. 

I am assuming that the P3SEL bits should be set to reassign P3.5 -> P3.1 to the peripheral functions.  (I had to do this to get the SPI code to work.)

Most of the examples for I2C communications that I have found are not for the USCI and so they are not much help.    

WriteRegsDVC  (UCHAR uWiper1,   UCHAR uWiper2)

**Attention** This is a public forum