diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-09-25 11:13:23 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-09-25 11:13:23 +0200 |
commit | 34ec0e23e63aa2bbd4939958eeb2093f9cadd3c2 (patch) | |
tree | 32957de14410cfdc326a7919670a9da0eeea1b27 /src | |
parent | e6de130f6cec0b0a486c00807d4770e328885fe0 (diff) |
Fix MSP430FR5994 I2C driver
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/msp430fr5994lp/driver/i2c.cc | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/arch/msp430fr5994lp/driver/i2c.cc b/src/arch/msp430fr5994lp/driver/i2c.cc index fe5b37b..57b4c30 100644 --- a/src/arch/msp430fr5994lp/driver/i2c.cc +++ b/src/arch/msp430fr5994lp/driver/i2c.cc @@ -10,43 +10,43 @@ volatile unsigned short old_ifg = 0; #if (F_CPU / F_I2C) < 45 inline void await_i2c_int(unsigned int ie_flags, unsigned int ifg_flags) { - while (!(UCB0IFG & ifg_flags)) ; - if (UCB0IFG & (UCNACKIFG | UCCLTOIFG)) { - UCB0IFG &= ~(UCNACKIFG | UCCLTOIFG); + while (!(UCB1IFG & ifg_flags)) ; + if (UCB1IFG & (UCNACKIFG | UCCLTOIFG)) { + UCB1IFG &= ~(UCNACKIFG | UCCLTOIFG); } } #else inline void await_i2c_int(unsigned int ie_flags, unsigned int ifg_flags) { - UCB0IFG = 0; + UCB1IFG = 0; old_ifg = 0; - UCB0IE = ie_flags; + UCB1IE = ie_flags; do { arch.idle(); } while (!(old_ifg & ifg_flags)); - UCB0IE = 0; + UCB1IE = 0; } #endif signed char I2C::setup() { #ifdef I2C_PULLUP_FIXED_GPIO - P1DIR |= BIT4 | BIT5; - P1OUT |= BIT4 | BIT5; + P8DIR |= BIT2 | BIT3; + P8OUT |= BIT2 | BIT3; #endif - UCB0CTL1 = UCSWRST; - UCB0CTLW0 = UCMODE_3 | UCMST | UCSYNC | UCSSEL_2 | UCSWRST | UCCLTO_1; - UCB0BRW = (F_CPU / F_I2C) - 1; - P1DIR &= ~(BIT6 | BIT7); - P1SEL0 &= ~(BIT6 | BIT7); - P1SEL1 |= BIT6 | BIT7; + UCB1CTL1 = UCSWRST; + UCB1CTLW0 = UCMODE_3 | UCMST | UCSYNC | UCSSEL_2 | UCSWRST | UCCLTO_1; + UCB1BRW = (F_CPU / F_I2C) - 1; + P5DIR &= ~(BIT0 | BIT1); + P5SEL0 |= (BIT0 | BIT1); + P5SEL1 &= ~(BIT0 | BIT1); - UCB0CTL1 &= ~UCSWRST; - UCB0I2CSA = 0; + UCB1CTL1 &= ~UCSWRST; + UCB1I2CSA = 0; arch.delay_us(100); - if (UCB0STAT & UCBBUSY) + if (UCB1STAT & UCBBUSY) return -1; return 0; @@ -55,18 +55,18 @@ signed char I2C::setup() void I2C::scan(unsigned int *results) { for (unsigned char address = 0; address < 128; address++) { - UCB0I2CSA = address; - UCB0CTL1 |= UCTR | UCTXSTT | UCTXSTP; + UCB1I2CSA = address; + UCB1CTL1 |= UCTR | UCTXSTT | UCTXSTP; - while (UCB0CTL1 & UCTXSTP); + while (UCB1CTL1 & UCTXSTP); - if (UCB0IFG & UCNACKIFG) { - UCB0IFG &= ~UCNACKIFG; + if (UCB1IFG & UCNACKIFG) { + UCB1IFG &= ~UCNACKIFG; } else { results[address / (8 * sizeof(unsigned int))] |= 1 << (address % (8 * sizeof(unsigned int))); } } - UCB0IFG = 0; + UCB1IFG = 0; } signed char I2C::xmit(unsigned char address, @@ -74,55 +74,55 @@ signed char I2C::xmit(unsigned char address, unsigned char rx_len, unsigned char *rx_buf) { unsigned char i; - UCB0I2CSA = address; + UCB1I2CSA = address; if (tx_len) { - UCB0CTL1 |= UCTR | UCTXSTT; + UCB1CTL1 |= UCTR | UCTXSTT; for (i = 0; i < tx_len; i++) { await_i2c_int(UCTXIE0 | UCNACKIE | UCCLTOIE, UCTXIFG0 | UCNACKIFG | UCCLTOIFG); if (old_ifg & (UCNACKIFG | UCCLTOIFG)) { - UCB0CTL1 |= UCTXSTP; + UCB1CTL1 |= UCTXSTP; return -1; } old_ifg = 0; - UCB0TXBUF = tx_buf[i]; + UCB1TXBUF = tx_buf[i]; } await_i2c_int(UCTXIE0 | UCNACKIE | UCCLTOIE, UCTXIFG0 | UCNACKIFG | UCCLTOIFG); - //if (UCB0IFG & (UCNACKIFG | UCCLTOIFG)) { - // UCB0IFG &= ~UCNACKIFG; - // UCB0IFG &= ~UCCLTOIFG; - // UCB0CTL1 |= UCTXSTP; + //if (UCB1IFG & (UCNACKIFG | UCCLTOIFG)) { + // UCB1IFG &= ~UCNACKIFG; + // UCB1IFG &= ~UCCLTOIFG; + // UCB1CTL1 |= UCTXSTP; // return -1; //} } if (rx_len) { - UCB0I2CSA = address; - UCB0IFG = 0; - UCB0CTL1 &= ~UCTR; - UCB0CTL1 |= UCTXSTT; + UCB1I2CSA = address; + UCB1IFG = 0; + UCB1CTL1 &= ~UCTR; + UCB1CTL1 |= UCTXSTT; - while (UCB0CTL1 & UCTXSTT); - UCB0IFG &= ~UCTXIFG0; + while (UCB1CTL1 & UCTXSTT); + UCB1IFG &= ~UCTXIFG0; for (i = 0; i < rx_len; i++) { if (i == rx_len - 1) - UCB0CTL1 |= UCTXSTP; + UCB1CTL1 |= UCTXSTP; await_i2c_int(UCRXIE | UCNACKIE | UCCLTOIE, UCRXIFG0 | UCNACKIFG | UCCLTOIFG); - rx_buf[i] = UCB0RXBUF; - UCB0IFG &= ~UCRXIFG0; + rx_buf[i] = UCB1RXBUF; + UCB1IFG &= ~UCRXIFG0; } - UCB0IFG &= ~UCRXIFG0; + UCB1IFG &= ~UCRXIFG0; } - UCB0CTL1 |= UCTXSTP; + UCB1CTL1 |= UCTXSTP; - while (UCB0CTL1 & UCTXSTP); + while (UCB1CTL1 & UCTXSTP); return 0; } -__attribute__((interrupt(USCI_B0_VECTOR))) __attribute__((wakeup)) void handle_usci_b0() +__attribute__((interrupt(USCI_B1_VECTOR))) __attribute__((wakeup)) void handle_usci_b1() { - old_ifg = UCB0IFG; - UCB0IFG = 0; + old_ifg = UCB1IFG; + UCB1IFG = 0; } I2C i2c; |