Other Parts Discussed in Thread: MSP430F5438
Hello,
I have the MSPEXP4305438 with the MSP430F5438. I try to implement I2C communication but it doesn't work.
It is in slave mode and I simply use the example code for slave mode.
When the slave receives its address, it sends a number, but the number received is wrong.
When I look the I2C lines at the scope, I can see that the MSP send data on falling edge and not on rising edge !! So the 8th bit of data is not taken in account !
How can I resolve this problem ?
Thanks.
This is the code :
#include "msp430x54x.h"
unsigned char TXData;
unsigned char i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x06; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode
UCB0I2COA = 0x48; // Own Address is 048h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCTXIE + UCSTTIE + UCSTPIE; // Enable TX interrupt
// Enable Start condition interrupt
TXData = 0; // Used to hold TX data
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
__no_operation(); // For debugger
}
// USCI_B0 State ISR
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
switch(__even_in_range(UCB0IV,12))
{
case 0: break; // Vector 0: No interrupts
case 2: break; // Vector 2: ALIFG
case 4: break; // Vector 4: NACKIFG
case 6: // Vector 6: STTIFG
UCB0IFG &= ~UCSTTIFG; // Clear start condition int flag
break;
case 8: // Vector 8: STPIFG
TXData++; // Increment TXData
UCB0IFG &= ~UCSTPIFG; // Clear stop condition int flag
break;
case 10: break; // Vector 10: RXIFG
case 12: // Vector 12: TXIFG
UCB0TXBUF = TXData; // TX data
break;
default: break;
}
}