Subversion Repositories FlightCtrl

Rev

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

Rev 1650 Rev 1651
Line 97... Line 97...
97
                        }
97
                        }
98
                        break;
98
                        break;
99
                case 2: // lower bits of setpoint (higher resolution)
99
                case 2: // lower bits of setpoint (higher resolution)
100
                        i2c_write_byte((Motor[motor].SetPointLowerBits << 1) & 0x07); // send the lower bits of setpoint
100
                        i2c_write_byte((Motor[motor].SetPointLowerBits << 1) & 0x07); // send the lower bits of setpoint
101
                        // transmit config only on demand and the motors are not running and only for one motor per round trip
101
                        // transmit config only on demand and the motors are not running and only for one motor per round trip
102
                        if( (BLFlags & BLFLAG_SEND_CONFIG) && !MotorenEin && (motor == motorread))
102
                        if( (BLFlags & BLFLAG_SEND_CONFIG) && (motor == motorread))
103
                        {       // prepare sending of configuration
103
                        {       // prepare sending of configuration
104
                                byte_counter = 0;       // reset send byte counter
104
                                byte_counter = 0;       // reset send byte counter
105
                                crc = 0xAA; // init checksum
105
                                crc = 0xAA; // init checksum
106
                        }
106
                        }
107
                        else
107
                        else
Line 113... Line 113...
113
                        if(!byte_counter) // first byte?
113
                        if(!byte_counter) // first byte?
114
                        {
114
                        {
115
                                i2c_write_byte(BL_CONF_SYNC_BYTE);
115
                                i2c_write_byte(BL_CONF_SYNC_BYTE);
116
                                crc += BL_CONF_SYNC_BYTE; // update crc
116
                                crc += BL_CONF_SYNC_BYTE; // update crc
117
                                pTxBuff = (uint8_t*)&BLConfig[motor]; // select configuration for motor
117
                                pTxBuff = (uint8_t*)&BLConfig[motor]; // select configuration for motor
-
 
118
                                twi_state = 3; // keep state 3
118
                        }
119
                        }
119
                        else if(byte_counter >= sizeof(BLConfig_t)+1) // last byte?
120
                        else if(byte_counter == sizeof(BLConfig_t) + 1)
120
                        {       // send crc byte at the end
121
                        {       // send crc byte at the end
121
                                i2c_write_byte(crc);
122
                                i2c_write_byte(crc);
-
 
123
                                twi_state = 3; // keep state 3
-
 
124
                        }
-
 
125
                        else if(byte_counter > sizeof(BLConfig_t) + 1)
-
 
126
                        {
-
 
127
                                i2c_write_byte(0);
-
 
128
                                // jump to case 4
122
                        }
129
                        }
123
            else // transmit configuration to BLs
130
            else // transmit configuration to BLs
124
                        {
131
                        {
125
                                i2c_write_byte(pTxBuff[byte_counter-1]);                // submit next byte
132
                                i2c_write_byte(pTxBuff[byte_counter-1]);        // submit next byte
126
                                crc += pTxBuff[byte_counter-1];                         // update crc
133
                                crc += pTxBuff[byte_counter-1];                         // update crc
127
                                twi_state = 3;                                                          // stay in this state
134
                                twi_state = 3;// keep state 3
128
                        }
135
                        }
129
                        byte_counter++; // next byte
136
                        byte_counter++; // next byte
130
                        break;
137
                        break;
131
        case 4:
138
        case 4:
Line 298... Line 305...
298
}
305
}
Line 299... Line 306...
299
 
306
 
300
void I2C_SendBLConfig(void)
307
void I2C_SendBLConfig(void)
301
{
308
{
-
 
309
        unsigned char i;
302
        unsigned char i;
310
        if(MotorenEin) return;
303
        while(!(BLFlags & BLFLAG_TX_COMPLETE)); //wait for complete transfer
311
        while(!(BLFlags & BLFLAG_TX_COMPLETE)); //wait for complete transfer
-
 
312
        BLFlags |= BLFLAG_SEND_CONFIG; // enable sending of BL config
304
        BLFlags |= BLFLAG_SEND_CONFIG; // enable sending of BL config
313
        // setpoints should be zero
305
        for(i = 0; i < MAX_MOTORS; i++)
314
        for(i = 0; i < MAX_MOTORS; i++)
306
        {
315
        {
307
                Motor[i].SetPoint = 0;
316
                Motor[i].SetPoint = 0;
308
                Motor[i].SetPointLowerBits = 0;
317
                Motor[i].SetPointLowerBits = 0;