Rev 1639 | Rev 1643 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1639 | Rev 1642 | ||
---|---|---|---|
Line 200... | Line 200... | ||
200 | 200 | ||
201 | //############################################################################ |
201 | //############################################################################ |
202 | SIGNAL (TWI_vect) |
202 | SIGNAL (TWI_vect) |
203 | //############################################################################ |
203 | //############################################################################ |
204 | { // 2 3 4 5 6 7 8 9 |
204 | { // 2 3 4 5 6 7 8 9 |
205 | unsigned char test[] = {0,0,'#',0x1F,255,30,100,64,0x00,7,8,9,10}; |
205 | unsigned char test[] = {0,0,'#',0x1F,255,30,100,64,0x00,7,8,9,10}; |
Line 206... | Line 206... | ||
206 | static unsigned char missing_motor,send = 0,crc = 0, read_temperature = 0; |
206 | static unsigned char missing_motor,send = 0,crc = 0; |
207 | 207 | ||
208 | switch(twi_state++) |
208 | switch(twi_state++) |
209 | { |
209 | { |
Line 221... | Line 221... | ||
221 | else i2c_write_byte(0x52+(motor*2)); |
221 | else i2c_write_byte(0x52+(motor*2)); |
222 | send = 0; |
222 | send = 0; |
223 | break; |
223 | break; |
224 | case 1: |
224 | case 1: |
225 | i2c_write_byte(Motor[motor].SetPoint); |
225 | i2c_write_byte(Motor[motor].SetPoint); |
226 | if(!(Motor[motor].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)/* || !Motor[motor].SetPointLowerBits*/) |
226 | if(!(Motor[motor].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)/* || !Motor[motor].SetPointLowerBits*/) |
227 | twi_state++; |
227 | twi_state++; |
228 | break; |
228 | break; |
229 | case 2: |
229 | case 2: |
230 | if(!send++) |
230 | if(!send++) |
231 | { |
231 | { |
232 | i2c_write_byte((Motor[motor].SetPointLowerBits << 1));// + (7 << 0)); |
232 | i2c_write_byte((Motor[motor].SetPointLowerBits << 1));// + (7 << 0)); |
233 | crc = 0xAA; |
233 | crc = 0xAA; |
234 | } |
234 | } |
235 | else |
235 | else |
236 | if(send == 9) i2c_write_byte(crc) |
236 | if(send == 9) i2c_write_byte(crc) |
237 | else |
237 | else |
238 | { |
238 | { |
239 | crc += test[send]; |
239 | crc += test[send]; |
240 | i2c_write_byte(test[send]); |
240 | i2c_write_byte(test[send]); |
241 | } |
241 | } |
242 | if(TransmitBlConfig && !MotorenEin && motor == motorread && (Motor[motorread].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)) |
242 | if(TransmitBlConfig && !MotorenEin && motor == motorread && (Motor[motorread].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)) |
243 | { |
243 | { |
244 | if(send <= 10) twi_state--; |
244 | if(send <= 10) twi_state--; |
245 | } |
245 | } |
Line 246... | Line 246... | ||
246 | 246 | ||
247 | break; |
247 | break; |
248 | case 3: |
248 | case 3: |
249 | motor++; |
249 | motor++; |
250 | if(TWSR == 0x30) |
250 | if(TWSR == 0x30) |
251 | { |
251 | { |
252 | if(!missing_motor) missing_motor = motor; |
252 | if(!missing_motor) missing_motor = motor; |
253 | if((Motor[motor-1].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK) Motor[motor-1].State++; // increment error counter and handle overflow |
253 | if((Motor[motor-1].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK) Motor[motor-1].State++; // increment error counter and handle overflow |
Line 280... | Line 280... | ||
280 | break; |
280 | break; |
281 | case 5: //Read 1st byte and transmit 2nd Byte |
281 | case 5: //Read 1st byte and transmit 2nd Byte |
282 | Motor[motorread].Current = TWDR; |
282 | Motor[motorread].Current = TWDR; |
283 | I2C_ReceiveByte(); //nack |
283 | I2C_ReceiveByte(); //nack |
284 | break; |
284 | break; |
285 | case 6: |
285 | case 6: |
286 | //Read 2nd byte and transmit 3rd Byte |
286 | //Read 2nd byte and transmit 3rd Byte |
287 | Motor[motorread].MaxPWM = TWDR; |
287 | Motor[motorread].MaxPWM = TWDR; |
288 | if(TWDR == 250) |
288 | if(TWDR == 250) |
289 | { |
289 | { |
290 | Motor[motorread].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK; |
290 | Motor[motorread].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK; |
291 | } |
291 | } |
292 | else if(TransmitBlConfig) Motor[motorread].Version = 0; |
292 | else if(TransmitBlConfig) Motor[motorread].Version = 0; |
293 | I2C_ReceiveLastByte(); //nack |
293 | I2C_ReceiveLastByte(); //nack |
294 | break; |
294 | break; |
295 | case 7: // read next |
295 | case 7: // read next |
296 | Motor[motorread].Temperature = TWDR; |
296 | Motor[motorread].Temperature = TWDR; |
297 | motorread++; // next motor |
297 | motorread++; // next motor |
298 | if(motorread >= MAX_MOTORS) { TransmitBlConfig = 0; motorread = 0; } |
298 | if(motorread >= MAX_MOTORS) { TransmitBlConfig = 0; motorread = 0; } |
299 | I2C_Stop(); |
299 | I2C_Stop(); |
300 | twi_state = 0; |
300 | twi_state = 0; |