Subversion Repositories FlightCtrl

Rev

Rev 2386 | Rev 2418 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2386 Rev 2407
Line 64... Line 64...
64
volatile uint8_t twi_state      = TWI_STATE_MOTOR_TX;
64
volatile uint8_t twi_state      = TWI_STATE_MOTOR_TX;
65
volatile uint8_t dac_channel    = 0;
65
volatile uint8_t dac_channel    = 0;
66
volatile uint8_t motor_write    = 0;
66
volatile uint8_t motor_write    = 0;
67
volatile uint8_t motor_read     = 0;
67
volatile uint8_t motor_read     = 0;
68
volatile uint8_t I2C_TransferActive = 0;
68
volatile uint8_t I2C_TransferActive = 0;
-
 
69
uint8_t Max_I2C_Packets = 12;
Line 69... Line 70...
69
 
70
 
Line 70... Line 71...
70
volatile uint16_t I2CTimeout = 100;
71
volatile uint16_t I2CTimeout = 100;
Line 155... Line 156...
155
ISR (TWI_vect)
156
ISR (TWI_vect)
156
{
157
{
157
        static uint8_t missing_motor = 0, motor_read_temperature = 0;
158
        static uint8_t missing_motor = 0, motor_read_temperature = 0;
158
        static uint8_t *pBuff = 0;
159
        static uint8_t *pBuff = 0;
159
        static uint8_t BuffLen = 0;
160
        static uint8_t BuffLen = 0;
160
 
-
 
-
 
161
        static uint8_t max_packets = 0;
161
    switch (twi_state++)
162
    switch (twi_state++)
162
        {
163
        {
163
                // Master Transmit
164
                // Master Transmit
164
        case 0: // TWI_STATE_MOTOR_TX
165
        case 0: // TWI_STATE_MOTOR_TX
165
            I2C_TransferActive = 1;
166
            I2C_TransferActive = 1;
166
                        // skip motor if not used in mixer
167
                        // skip motor if not used in mixer
167
                        while((Mixer.Motor[motor_write][MIX_GAS] <= 0) && (motor_write < MAX_MOTORS)) motor_write++;
168
                        while((Mixer.Motor[motor_write][MIX_GAS] <= 0) && (motor_write < MAX_MOTORS)) motor_write++;
-
 
169
                        motor_write %= MAX_MOTORS;
168
                        if(motor_write >= MAX_MOTORS) // writing finished, read now
170
                        if(++max_packets > Max_I2C_Packets) // writing finished, read now
169
                        {
171
                        {
-
 
172
                                max_packets = 0;
170
                                BLConfig_WriteMask = 0; // reset configuration bitmask
173
                                BLConfig_WriteMask = 0; // reset configuration bitmask
171
                                motor_write = 0; // reset motor write counter for next cycle
174
//motor_write = 0; // reset motor write counter for next cycle
172
                                twi_state = TWI_STATE_MOTOR_RX;
175
                                twi_state = TWI_STATE_MOTOR_RX;
173
                                I2C_WriteByte(TWI_BASE_ADDRESS + TW_READ + (motor_read<<1) ); // select slave address in rx mode
176
                                I2C_WriteByte(TWI_BASE_ADDRESS + TW_READ + (motor_read<<1) ); // select slave address in rx mode
174
                        }
177
                        }
175
                        else I2C_WriteByte(TWI_BASE_ADDRESS + TW_WRITE + (motor_write<<1) ); // select slave address in tx mode
178
                        else I2C_WriteByte(TWI_BASE_ADDRESS + TW_WRITE + (motor_write<<1) ); // select slave address in tx mode
176
                        break;
179
                        break;