Part Number: MSP430F2013 Hi, I'm using one MSP430F2013 as an I2C slave. Based on the TI code example I did some tests and I can send multiple bytes from slave to master. The code is this: uint16_t I2C_RW_Bit = 0; if (USICTL1 & USISTTIFG) // Start entry? { P1OUT |= 0x01; // LED on: sequence start I2C_State = 2; // Enter 1st state on start Bytecount = 0; // Reset counter for next TX/RX tx_counter = 0; } switch( __even_in_range(I2C_State, 18) ) { case 0: // Idle, should not get here break; ... ... case 10: // Send Data byte - master reading from slave if (1) { if (tx_counter < TX_MAX_BYTES) { TX_Data(SLV_Data++); } else { } } I2C_State = 12; // Go to next state: receive (N)Ack break; case 12: // Receive Data (N)Ack - melhorar descrição USICTL0 &= ~USIOE; // SDA = input USICNT |= 0x01; // Bit counter = 1, receive (N)Ack I2C_State = 14; // Go to next state: check (N)Ack break; case 14:// Process Data Ack/NAck if( USISRL & I2C_NACK ) // If Nack received... stop transmission { USICTL0 &= ~USIOE; // SDA = input I2C_State = 0; // Reset state machine Bytecount = 0; } else // Ack received { P1OUT &= ~0x01; // LED off TX_Data(SLV_Data++); // TX next byte I2C_State = 12; // Go to next state: receive (N)Ack } break; The sequence: go to case 10 Send a byte change I2C_State to 12 go to case 12 read (N)ACK bit change I2C_State to 14 go to case 14 if NACK received reset the machine else (if ACK received) send another byte change I2C_State to 12 I tried to re-arrange the code to maintain the usage of TX_data( ) just on the "case 10". uint16_t I2C_RW_Bit = 0; if (USICTL1 & USISTTIFG) // Start entry? { P1OUT |= 0x01; // LED on: sequence start I2C_State = 2; // Enter 1st state on start Bytecount = 0; // Reset counter for next TX/RX tx_counter = 0; } switch( __even_in_range(I2C_State, 18) ) { case 0: // Idle, should not get here break; ... ... case 10: // Send Data byte - master reading from slave if (1) { if (tx_counter < TX_MAX_BYTES) { TX_Data(SLV_Data++); } else { } } I2C_State = 12; // Go to next state: receive (N)Ack break; case 12: // Receive Data (N)Ack - melhorar descrição USICTL0 &= ~USIOE; // SDA = input USICNT |= 0x01; // Bit counter = 1, receive (N)Ack I2C_State = 14; // Go to next state: check (N)Ack break; case 14:// Process Data Ack/NAck if( USISRL & I2C_NACK ) // If Nack received... stop transmission { USICTL0 &= ~USIOE; // SDA = input I2C_State = 0; // Reset state machine Bytecount = 0; // LPM0_EXIT; // Exit active for next transfer } else // Ack received { P1OUT &= ~0x01; // LED off I2C_State = 10; // Go to next state: receive (N)Ack } break; The chronological sequence theoretically is the same, but in this way, the first byte is correctly sent, but the second byte always is 0xFF. go to case 10 Send a byte change I2C_State to 12 go to case 12 read (N)ACK bit change I2C_State to 14 go to case 14 if NACK received reset the machine else (if ACK received) change I2C_State to 10 (to send another byte) Where is the problem in this second version? Thanks.
↧