Other Parts Discussed in Thread: MSP430F5438
Hi,
I am trying to test the I2C communication on the msp430f5438 experiment board
I noticed there are 4 I2C module, USCI_B0 to USCI_B3. and it looks like only USCI_B1 and USCI_B3 are available on general pins. (USCI_B1 is available on pin3.7 and pin5.4; USCI_B3 is available on pin10.1 and pin10.2)
what i did is configure B3 as master transmitter to transmit a single byte that will be received on USCI_B1 as a slave receiver.
I set 2 breakpoints respectively at transmitter interrupt and receiver interrupt to observe if the data is transmitted and received successfully.
the following is the source code
#include <msp430.h>
/*
* main.c
*/
unsigned char TXData;
unsigned char TXByteCtr;
volatile unsigned char RXData;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0;
P1OUT &= ~BIT0;
/* initialize UCB3 */
P10SEL |= BIT1 + BIT2;
P10DIR |= BIT1 + BIT2;
UCB3CTL1 |= UCSWRST;
UCB3CTL0 |= UCMST + UCMODE_3 + UCSYNC;
UCB3CTL1 |= UCSSEL_2 + UCSWRST;
UCB3BR0 = 12;
UCB3BR1 = 0;
UCB3I2CSA = 0x48;
UCB3CTL1 &= ~UCSWRST;
UCB3IE |= UCTXIE;
TXData = 0x01;
/* initialize UCB1 */
P3DIR &= ~BIT7;
P3SEL |= BIT7;
P5OUT &= ~BIT4;
P5SEL |= BIT4;
UCB1CTL1 |= UCSWRST;
UCB1CTL0 |= UCMODE_3 + UCSYNC;
UCB1I2COA = 0x48;
UCB1CTL1 &= ~UCSWRST;
UCB1IE |= UCRXIE;
while(1){
TXByteCtr = 1;
while(UCB3CTL1 & UCTXSTP);
UCB3CTL1 |= UCTR + UCTXSTT;
__bis_SR_register(LPM0_bits + GIE);
__no_operation();
TXData++;
}
}
#pragma vector = USCI_B3_VECTOR
__interrupt void USCI_B3_ISR(void){
switch(UCB3IV){
case 12:
if(TXByteCtr){
UCB3TXBUF = TXData;
TXByteCtr--;
}
else{
UCB3CTL1 |= UCTXSTP;
UCB3IFG &= ~UCTXIFG;
__bic_SR_register_on_exit(LPM0_bits);
}
break;
default: break;
}
}
#pragma vector = USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void){
switch(UCB1IV){
case 10:
RXData = UCB1RXBUF;
P1OUT = RXData;
break;
default: break;
}
}
when the program halts at transmitter interrupt, i observed the transmitter NACKIFG is set. it looks like the slave doesn't acknowledge the address transmission.
and both transmitter and receive busy flag is set as well.
when i resume the program, it would not halt at receiver interrupt breakpoint and nothing happens.
can somebody find the error in the code? or is it a mistake to test 2 I2C bus on the same board?
any suggestion will be appreciated
Jensen