Hi,
I am trying to develop the communication between two MSP430F2272. I followed the code example of I2C provide (no 6 and 7). But didn't get the success. Then i followed the user guide and tried to built the code the communication as under
Master Code
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
wait();
wait();
P3SEL |= 0x06; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST + UCTR; // Use SMCLK, keep SW reset,Transmitter
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x48; // Slave Address is 048h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0TXIE; // Enable TX interrupt
TXData = 0x00; // Holds TX data
while (1)
{
TXByteCtr = 1; // Load TX byte counter
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
UCB0TXBUF = TXData; // Load TX buffer
IE2 |= UCB0TXIE; // Disable USCI_A0 TX interrupt // Remain in LPM0 until all data
wait(); // is TX'd
wait();
TXData++; // Increment data byte
}
}
//------------------------------------------------------------------------------
// The USCIAB0TX_ISR is structured such that it can be used to transmit any
// number of bytes by pre-loading TXByteCtr with the byte count.
//------------------------------------------------------------------------------
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIB0TX_ISR(void)
{
if (TXByteCtr) // Check TX byte counter
{
TXByteCtr--; // Decrement TX byte counter
}
else
{
}
}
Slave Code
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode
UCB0I2COA = 0x48; // Own Address is 048h
INIT_PORTS();
P3SEL |= 0x06;
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE; // Enable RX interrupt
Rx_ptr = 0;
while (Rx_ptr <10)
{
strcpy(DisplayStr,"INITIAL "); //wait till the master is attached to device
display_str(0,10,10);
}
Rx_ptr = 0;
Time_Change = 0;
while(1)
{
display_unsigned_Integer(0 ,(unsigned int)Received_data[Rx_ptr] , 10, LEADING_BLANK,10);
secTimer = 10;
while(!Time_Change);
Time_Change = 0;
Rx_ptr ++;
if (Rx_ptr >10)
Rx_ptr=0;
}
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
strcpy(DisplayStr,"DATA "); //wait till the master is attached to device
display_str(0,10,10);
RXData = UCB0RXBUF; // Get RX data
Received_data[Rx_ptr] = RXData;
Rx_ptr++;
}
Where i am stuck is, I can see the data through debugger on the UCB0RXBUF which are coming from Master. But i at the receiver end i have kept a code to displaying "DATA" on the 7 segment LED which is not been displayed anytime. All i am getting the "INITIAL" message which i have displayed in the main loop.
So first thing is that the MSP430 is not getting the Receive interrupt. But as the datasheet and userguide says that the SDA line will be get hold till the UCB0RXBUF has not been read. Hence the next data will not be transmitted. But i can see the data are been incremented and been transmitted !!!! The signal i have seen on the CRO and on the RXBUF also.
Need the help to find where i am missing. Or can anybody can share the running code for the communication between two MSP though I2C.
Thanks and Regards
Vikas