Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: msp430F5438 I2C function testing

$
0
0
Hi All, I am trying to test the function of I2C on msp430f5438 experimental board. what i did was that there are two I2C bus available on the experimental board UCB1 which is available on P3.7 and P5.4 and UCB3 which is available on P10.1 and P10.2. and i want to send data through UCB3 (master) and receive it at UCB1 (slave) and i am sure the bus connection has no error. the source code is shown as follow #include /* * main.c */ /* transfer data from UCB3 to UCB1; UCB3 is master transmitter and UCB1 is slave receiver */ unsigned char *PTxData; unsigned char TXByteCtr; unsigned char *PRxData; unsigned char RXByteCtr; const unsigned char TxData[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; volatile unsigned char RxBuffer[128]; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer /* initialize UCB3 */ P10SEL |= BIT1 + BIT2; UCB3CTL1 |= UCSWRST; UCB3CTL0 = UCMST + UCMODE_3 + UCSYNC; UCB3CTL1 = UCSSEL_2 + UCSWRST; UCB3BR0 = 12; UCB3BR1 = 0; UCB3I2CSA = 0x48; UCB3CTL1 &= ~UCSWRST; UCB3IE |= UCTXIE; /* initialize UCB1 */ P3SEL |= BIT7; P5SEL |= BIT4; UCB1CTL1 |= UCSWRST; UCB1CTL0 = UCMODE_3 + UCSYNC; UCB1I2COA = 0x48; UCB1CTL1 &= ~UCSWRST; UCB1IE = UCSTPIE + UCSTTIE + UCRXIE; while(1){ __delay_cycles(50); PTxData = (unsigned char *)TxData; PRxData = (unsigned char *)RxBuffer; TXByteCtr = sizeof TxData; RXByteCtr = 0; UCB3CTL1 = UCTR + UCTXSTT; __bis_SR_register(LPM0_bits + GIE); __no_operation(); while(UCB3CTL1&UCTXSTP); } } #pragma vector = USCI_B3_VECTOR __interrupt void USCI_B3_ISR(void){ switch(UCB3IV){ case 12: if(TXByteCtr){ UCB3TXBUF = *PTxData++; TXByteCtr--; }else{ UCB3CTL1 |= UCTXSTP; UCB3IFG &= ~UCTXIFG; __bic_SR_register_on_exit(LPM0_bits); } default: break; } } #pragma vector = USCI_B1_VECTOR __interrupt void USCI_B1_ISR(void){ switch(UCB1IV){ case 6: UCB1IFG &= ~UCSTTIFG; break; case 8: UCB1IFG &= ~UCSTPIFG; if(RXByteCtr){ __bic_SR_register_on_exit(LPM0_bits); } break; case 10: *PRxData = UCB1RXBUF; RXByteCtr++; break; default: break; } } i observed through breakpoints that transmitting is working properly (the program halts at transmit interrupt). but it looks like the receiver doesn't work (the program didn't halt at receiver interrupt) i couldn't find any reason behind it. can someone suggest how to fix it? really appreciate it. Jensen

Viewing all articles
Browse latest Browse all 62309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>