Part Number: MSP-EXP430FR2355
Other Parts Discussed in Thread: MSP430FR2355
Hello,
I can't seem to read more than one complete byte in an I2C transmission. I'm using one master and one slave. The MSP430FR2355 is the master and Maxim's DS1307 real-time clock is the slave.
How can I correctly read multiple bytes? Is there anything I'm doing wrong?
Datasheet for the DS1307: cdn.sparkfun.com/.../DS1307.pdf
Reading 1 byte
This is what happens when reading one byte (which looks correct):
Fig 1:
These are the memory dumps after reading the data:
(mspdebug) md 0x0540 00540: c0 0f 08 00 00 00 08 00 00 01 01 00 00 00 00 00 |................| 00550: 00 00 00 00 00 00 00 00 00 00 00 00 68 00 ff 03 |............h...| 00560: 68 00 00 00 00 00 00 00 00 00 61 00 08 40 00 00 |h.........a..@..| 00570: ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f |.?.?.?.?.?.?.?.?| (mspdebug) md 0x056C 0056c: 08 40 00 00 ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f |.@...?.?.?.?.?.?| 0057c: ff 3f ff 3f 01 00 03 00 00 00 00 00 00 00 00 00 |.?.?............| 0058c: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0059c: 02 00 00 00 ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f |.....?.?.?.?.?.?|
Reading 2 bytes
When I reading two bytes, the data line hangs low after the 7th byte of the third frame (second byte to be read):
Fig 2:
It stays low for about 15ms:
Fig 3:
These are the memory dumps after attempting to read two bytes:
(mspdebug) md 0x0540
00540: c0 0f 08 00 00 00 08 00 00 02 02 00 10 00 00 00 |................|
00550: 00 00 00 00 00 00 00 00 00 00 00 00 68 00 ff 03 |............h...|
00560: 68 00 00 00 00 00 00 00 00 00 61 00 08 40 00 00 |h.........a..@..|
00570: ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f |.?.?.?.?.?.?.?.?|
(mspdebug) md 0x056C
0056c: 08 40 00 00 ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f |.@...?.?.?.?.?.?|
0057c: ff 3f ff 3f 01 00 03 00 00 00 00 00 00 00 00 00 |.?.?............|
0058c: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0059c: 02 00 00 00 ff 3f ff 3f ff 3f ff 3f ff 3f ff 3f |.....?.?.?.?.?.?|
Reading 5 bytes
When trying to read five bytes, the SDA line hangs low similar to when reading 2 bytes:
Fig 4:
But there seems to be some attempts to start transmission again in a 130ms time frame before SDA and SCL are released again:
Fig 5:
Code
Here is my code for reading 1 byte. Reading 2 bytes and reading 5 bytes are only different in that NNBytes = 2 and NNBytes = 5.
#include <msp430.h>
#include <stdint.h>
void Init_GPIO();
const int NNBytes = 1;
volatile uint8_t RXData;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
/* Configure GPIO */
Init_GPIO();
PM5CTL0 &= ~LOCKLPM5;
/* Configure P2.3 as input switch to send I2C START command */
P2DIR &= ~BIT3;
P2OUT |= BIT3;
P2REN |= BIT3;
P2IES |= BIT3;
P2IFG = 0;
P2IE |= BIT3;
/* Configure I2C */
P1OUT &= ~BIT0; // Clear P1.0 output latch
P6OUT &= ~BIT6; // Clear P6.6 output latch
P1DIR |= BIT0; // For LED
P6DIR |= BIT6; // For LED
P1SEL0 |= BIT2 | BIT3; // I2C pins: SDA | SCL
// Configure USCI_B0 for I2C mode
UCB0CTLW0 |= UCSWRST; // Software reset enabled
UCB0CTLW0 |= UCMODE_3 | UCMST | UCSYNC; // I2C mode, Master mode, sync
UCB0CTLW1 |= UCASTP_2; // Automatic stop generated
// after UCB0TBCNT is reached
UCB0BRW = 0x0008; // baudrate = SMCLK / 8
UCB0TBCNT = NNBytes; // number of bytes to be received
UCB0I2CSA = 0x0068; // Slave address
UCB0CTL1 &= ~UCSWRST;
UCB0IE |= UCRXIE | UCNACKIE | UCBCNTIE;
__bis_SR_register(LPM0_bits|GIE); // Enter LPM0 w/ interrupt
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = PORT2_VECTOR
__interrupt void Port_2(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT2_VECTOR))) Port_2 (void)
#else
#error Compiler not supported!
#endif
{
//__delay_cycles(2000);
if (P2IFG & BIT3) {
P1OUT |= BIT0; // Toggle LED on P1.0
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
//if (UCB0BCNT != NNBytes)
UCB0CTL1 |= UCTXSTT; // I2C start condition
Uart_puts("START");
uart_putc(0x0A); // new line
P2IFG &= ~BIT3;
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCIB0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
{
case USCI_NONE: break; // Vector 0: No interrupts
case USCI_I2C_UCALIFG: break; // Vector 2: ALIFG
case USCI_I2C_UCNACKIFG: // Vector 4: NACKIFG
UCB0CTL1 |= UCTXSTT; // I2C start condition
break;
case USCI_I2C_UCSTTIFG: break; // Vector 6: STTIFG
case USCI_I2C_UCSTPIFG: break; // Vector 8: STPIFG
case USCI_I2C_UCRXIFG3: break; // Vector 10: RXIFG3
case USCI_I2C_UCTXIFG3: break; // Vector 14: TXIFG3
case USCI_I2C_UCRXIFG2: break; // Vector 16: RXIFG2
case USCI_I2C_UCTXIFG2: break; // Vector 18: TXIFG2
case USCI_I2C_UCRXIFG1: break; // Vector 20: RXIFG1
case USCI_I2C_UCTXIFG1: break; // Vector 22: TXIFG1
case USCI_I2C_UCRXIFG0: // Vector 24: RXIFG0
RXData = UCB0RXBUF; // Get RX data
//__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
break;
case USCI_I2C_UCTXIFG0: break; // Vector 26: TXIFG0
case USCI_I2C_UCBCNTIFG: // Vector 28: BCNTIFG
P1OUT ^= BIT0; // Toggle LED on P1.0
break;
case USCI_I2C_UCCLTOIFG: break; // Vector 30: clock low timeout
case USCI_I2C_UCBIT9IFG: break; // Vector 32: 9th bit
default: break;
}
}
void Init_GPIO()
{
P1DIR = 0xFF; P2DIR = 0xFF;
P1REN = 0xFF; P2REN = 0xFF;
P1OUT = 0x00; P2OUT = 0x00;
}






