fixed z1 i2c bug where 2 extra bytes were read with every i2c-receive

This commit is contained in:
Jelmer Tiete 2013-01-30 14:15:16 +01:00
parent 2b9a1c60d2
commit 12dd138915

View file

@ -214,6 +214,7 @@ ISR(USCIAB1TX, i2c_tx_interrupt)
{ {
// TX Part // TX Part
if (UC1IFG & UCB1TXIFG) { // TX int. condition if (UC1IFG & UCB1TXIFG) { // TX int. condition
PRINTFDEBUG("!!! TX int\n");
if (tx_byte_ctr == 0) { if (tx_byte_ctr == 0) {
UCB1CTL1 |= UCTXSTP; // I2C stop condition UCB1CTL1 |= UCTXSTP; // I2C stop condition
UC1IFG &= ~UCB1TXIFG; // Clear USCI_B1 TX int flag UC1IFG &= ~UCB1TXIFG; // Clear USCI_B1 TX int flag
@ -226,17 +227,14 @@ ISR(USCIAB1TX, i2c_tx_interrupt)
// RX Part // RX Part
#if I2C_RX_WITH_INTERRUPT #if I2C_RX_WITH_INTERRUPT
else if (UC1IFG & UCB1RXIFG){ // RX int. condition else if (UC1IFG & UCB1RXIFG){ // RX int. condition
if (rx_byte_ctr == 0){ rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF;
rx_byte_ctr--;
if (rx_byte_ctr == 1){ //stop condition should be set before receiving last byte
// Only for 1-byte transmissions, STOP is handled in receive_n_int // Only for 1-byte transmissions, STOP is handled in receive_n_int
if (rx_byte_tot != 1) if (rx_byte_tot != 1)
UCB1CTL1 |= UCTXSTP; // I2C stop condition UCB1CTL1 |= UCTXSTP; // I2C stop condition
UC1IFG &= ~UCB1RXIFG; // Clear USCI_B1 RX int flag. XXX Just in case, check if necessary UC1IFG &= ~UCB1RXIFG; // Clear USCI_B1 RX int flag. XXX Just in case, check if necessary
} }
else {
rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF;
rx_byte_ctr--;
}
} }
#endif #endif
} }