Rev 1644 | Rev 1650 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1644 | Rev 1648 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | ############################################################################*/ |
2 | ############################################################################*/ |
Line 3... | Line 3... | ||
3 | 3 | ||
Line 4... | Line 4... | ||
4 | #include "main.h" |
4 | #include "main.h" |
5 | 5 | ||
6 | volatile unsigned char twi_state = 0; |
6 | volatile unsigned char twi_state = 0; |
7 | unsigned char motor = 0,TransmitBlConfig = 1; |
7 | unsigned char motor = 0; |
Line 8... | Line 8... | ||
8 | unsigned char motorread = 0,MissingMotor = 0; |
8 | unsigned char motorread = 0,MissingMotor = 0; |
- | 9 | unsigned char BLFlags = 0; |
|
- | 10 | ||
- | 11 | MotorData_t Motor[MAX_MOTORS]; |
|
Line 9... | Line 12... | ||
9 | unsigned char ReadTemperature = 0; |
12 | BLConfig_t BLConfig[MAX_MOTORS]; |
Line -... | Line 13... | ||
- | 13 | ||
- | 14 | unsigned char *pTxBuff = (uint8_t*)&BLConfig[0]; |
|
10 | 15 | ||
11 | MotorData_t Motor[MAX_MOTORS]; |
16 | unsigned int I2CError = 0; |
12 | 17 | ||
13 | unsigned int I2CError = 0; |
18 | #define BL_CONF_SYNC_BYTE '#' |
14 | 19 | ||
- | 20 | //############################################################################ |
|
- | 21 | //Initzialisieren der I2C (TWI) Schnittstelle |
|
15 | //############################################################################ |
22 | void i2c_init(void) |
16 | //Initzialisieren der I2C (TWI) Schnittstelle |
23 | //############################################################################ |
- | 24 | { |
|
- | 25 | unsigned char i; |
|
- | 26 | ||
- | 27 | TWSR = 0; |
|
- | 28 | TWBR = ((SYSCLK/SCL_CLOCK)-16)/2; |
|
- | 29 | ||
- | 30 | for(i=0; i < MAX_MOTORS; i++) |
|
- | 31 | { |
|
- | 32 | Motor[i].Version = 0; |
|
- | 33 | Motor[i].SetPoint = 0; |
|
- | 34 | Motor[i].SetPointLowerBits = 0; |
|
- | 35 | Motor[i].State = 0; |
|
- | 36 | Motor[i].Current = 0; |
|
- | 37 | Motor[i].MaxPWM = 0; |
|
- | 38 | BLConfig[i].SetMask = MASK_SET_PWM_SCALING|MASK_SET_CURRENT_LIMIT|MASK_SET_TEMP_LIMIT|MASK_SET_CURRENT_SCALING|MASK_SET_BITCONFIG; |
|
- | 39 | BLConfig[i].PwmScaling = 255; // MaxPWM |
|
17 | void i2c_init(void) |
40 | BLConfig[i].CurrentLimit = 30; // Current Limit in A |
Line 18... | Line 41... | ||
18 | //############################################################################ |
41 | BLConfig[i].TempLimit = 99; // Temperature Limit in °C |
19 | { |
42 | BLConfig[i].CurrentScaling = 64; // Current Scaling |
20 | TWSR = 0; |
43 | BLConfig[i].BitConfig = 0; // BitConfig |
21 | TWBR = ((SYSCLK/SCL_CLOCK)-16)/2; |
44 | } |
22 | } |
45 | } |
23 | 46 | ||
24 | void i2c_reset(void) |
47 | void i2c_reset(void) |
25 | //############################################################################ |
48 | //############################################################################ |
26 | { |
49 | { |
27 | I2C_Stop(); |
50 | I2C_Stop(); |
28 | twi_state = 0; |
51 | twi_state = 0; |
29 | motor = TWDR; |
52 | motor = TWDR; |
30 | motor = 0; |
53 | motor = 0; |
31 | TWCR = 0x80; |
54 | TWCR = 0x80; |
32 | TWAMR = 0; |
55 | TWAMR = 0; |
33 | TWAR = 0; |
56 | TWAR = 0; |
34 | TWDR = 0; |
57 | TWDR = 0; |
Line 35... | Line 58... | ||
35 | TWSR = 0; |
58 | TWSR = 0; |
36 | TWBR = 0; |
59 | TWBR = 0; |
37 | i2c_init(); |
60 | i2c_init(); |
38 | I2C_Start(); |
61 | I2C_Start(); |
39 | i2c_write_byte(0); |
62 | i2c_write_byte(0); |
40 | } |
63 | } |
- | 64 | ||
41 | 65 | ||
42 | /* |
66 | //############################################################################ |
43 | //############################################################################ |
67 | SIGNAL (TWI_vect) |
44 | SIGNAL (TWI_vect) |
68 | //############################################################################ |
45 | //############################################################################ |
69 | { |
46 | { |
70 | static unsigned char missing_motor = 0, byte_counter = 0, crc = 0, read_more = 0, motorread_temperature = 0; |
47 | static unsigned char missing_motor; |
71 | J4High; |
48 | switch(twi_state++) |
72 | switch(twi_state++) |
49 | { |
73 | { |
50 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
74 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // Writing the Data |
75 | // Writing the Data |
52 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
76 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | case 0: |
77 | case 0: |
54 | while(Mixer.Motor[motor][0] <= 0 && motor < MAX_MOTORS) motor++; // skip if not used |
78 | while(Mixer.Motor[motor][MIX_GAS] <= 0 && motor < MAX_MOTORS) motor++; // skip if not used |
55 | if(motor == MAX_MOTORS) // writing finished -> now read |
79 | if(motor == MAX_MOTORS) // writing finished -> now read |
56 | { |
80 | { |
57 | motor = 0; |
81 | motor = 0; |
- | 82 | twi_state = 5; |
|
- | 83 | i2c_write_byte(0x53+(motorread*2)); |
|
- | 84 | } |
|
- | 85 | else i2c_write_byte(0x52+(motor*2)); |
|
- | 86 | break; |
|
- | 87 | case 1: |
|
- | 88 | i2c_write_byte(Motor[motor].SetPoint); |
|
- | 89 | if(!(Motor[motor].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) ) |
|
- | 90 | { |
|
- | 91 | twi_state = 4; //jump over sending more data |
|
- | 92 | } |
|
- | 93 | else if(!(Motor[motor].SetPointLowerBits || (BLFlags & BLFLAG_SEND_CONFIG))) |
|
- | 94 | { |
|
- | 95 | twi_state = 4; // skip state |
|
- | 96 | } |
|
58 | twi_state = 3; |
97 | break; |
- | 98 | case 2: // lower bits of setpoint (higher resolution) |
|
- | 99 | i2c_write_byte((Motor[motor].SetPointLowerBits << 1) & 0x07); // send the lower bits of setpoint |
|
- | 100 | // transmit config only on demand and the motors are not running and only for one motor per round trip |
|
- | 101 | if( (BLFlags & BLFLAG_SEND_CONFIG) && !MotorenEin && (motor == motorread)) |
|
- | 102 | { // prepare sending of configuration |
|
- | 103 | byte_counter = 0; // reset send byte counter |
|
- | 104 | crc = 0xAA; // init checksum |
|
- | 105 | } |
|
- | 106 | else |
|
- | 107 | { // jump to state for end of transmission for that motor |
|
- | 108 | twi_state = 4; |
|
- | 109 | } |
|
- | 110 | break; |
|
- | 111 | case 3: |
|
- | 112 | if(!byte_counter) // first byte? |
|
- | 113 | { |
|
- | 114 | i2c_write_byte(BL_CONF_SYNC_BYTE); |
|
- | 115 | crc += BL_CONF_SYNC_BYTE; // update crc |
|
- | 116 | pTxBuff = (uint8_t*)&BLConfig[motor]; // select configuration for motor |
|
- | 117 | } |
|
- | 118 | else if(byte_counter >= sizeof(BLConfig_t)+1) // last byte? |
|
- | 119 | { // send crc byte at the end |
|
- | 120 | i2c_write_byte(crc); |
|
- | 121 | } |
|
- | 122 | else // transmit configuration to BLs |
|
59 | i2c_write_byte(0x53+(motorread*2)); |
123 | { |
- | 124 | i2c_write_byte(pTxBuff[byte_counter-1]); // submit next byte |
|
60 | } |
125 | crc += pTxBuff[byte_counter-1]; // update crc |
61 | else i2c_write_byte(0x52+(motor*2)); |
126 | twi_state = 3; // stay in this state |
62 | break; |
127 | } |
63 | case 1: |
128 | byte_counter++; // next byte |
64 | i2c_write_byte(Motor[motor++].SetPoint); |
129 | break; |
65 | break; |
130 | case 4: |
66 | case 2: |
131 | |
- | 132 | if(TWSR == 0x30) |
|
67 | if(TWSR == 0x30) |
133 | { |
68 | { |
134 | if(!missing_motor) missing_motor = motor + 1; |
69 | if(!missing_motor) missing_motor = motor; |
135 | if((Motor[motor].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK) Motor[motor].State++; // increment error counter and handle overflow |
70 | if((Motor[motor-1].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK) Motor[motor-1].State++; // increment error counter and handle overflow |
136 | } |
71 | } |
137 | I2C_Stop(); |
72 | I2C_Stop(); |
138 | I2CTimeout = 10; |
73 | I2CTimeout = 10; |
- | |
74 | twi_state = 0; |
- | |
75 | I2C_Start(); |
- | |
76 | break; |
- | |
77 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
78 | // Reading Data |
- | |
79 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
80 | case 3: |
- | |
81 | //Transmit 1st byte for reading |
- | |
82 | if(TWSR != 0x40) // Error? |
- | |
83 | { |
- | |
84 | Motor[motorread].State &= ~MOTOR_STATE_PRESENT_MASK; // clear present bit |
- | |
85 | motorread++; |
- | |
86 | if(motorread >= MAX_MOTORS) motorread = 0; |
- | |
87 | I2C_Stop(); |
- | |
88 | twi_state = 0; |
- | |
89 | } |
- | |
90 | else |
- | |
91 | { |
- | |
92 | Motor[motorread].State |= MOTOR_STATE_PRESENT_MASK; // set present bit |
- | |
93 | I2C_ReceiveByte(); |
- | |
94 | } |
- | |
95 | MissingMotor = missing_motor; |
139 | motor++; |
96 | missing_motor = 0; |
140 | twi_state = 0; |
97 | break; |
- | |
98 | case 4: //Read 1st byte and transmit 2nd Byte |
141 | I2C_Start(); |
99 | Motor[motorread].Current = TWDR; |
- | |
100 | I2C_ReceiveLastByte(); //nack |
- | |
101 | break; |
- | |
102 | case 5: |
- | |
103 | //Read 2nd byte |
- | |
104 | Motor[motorread].MaxPWM = TWDR; |
- | |
105 | motorread++; // next motor |
- | |
106 | if(motorread >= MAX_MOTORS) motorread = 0; |
- | |
107 | I2C_Stop(); |
- | |
108 | twi_state = 0; |
- | |
109 | break; |
- | |
110 | - | ||
111 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
112 | // writing Gyro-Offset |
- | |
113 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
114 | case 8: |
- | |
115 | i2c_write_byte(0x98); // Address of the DAC |
- | |
116 | break; |
- | |
117 | case 9: |
- | |
118 | i2c_write_byte(0x10); // Update Channel A |
- | |
119 | break; |
- | |
120 | case 10: |
- | |
121 | i2c_write_byte(AnalogOffsetNick); // Value |
- | |
122 | break; |
- | |
123 | case 11: |
- | |
124 | i2c_write_byte(0x80); // Value |
- | |
125 | break; |
- | |
126 | case 12: |
- | |
127 | I2C_Stop(); |
- | |
128 | I2CTimeout = 10; |
- | |
129 | I2C_Start(); |
- | |
130 | break; |
- | |
131 | case 13: |
- | |
132 | i2c_write_byte(0x98); // Address of the DAC |
- | |
133 | break; |
- | |
134 | case 14: |
- | |
135 | i2c_write_byte(0x12); // Update Channel B |
- | |
136 | break; |
- | |
137 | case 15: |
- | |
138 | i2c_write_byte(AnalogOffsetRoll); // Value |
- | |
139 | break; |
- | |
140 | case 16: |
- | |
141 | i2c_write_byte(0x80); // Value |
- | |
142 | break; |
- | |
143 | case 17: |
- | |
144 | I2C_Stop(); |
- | |
145 | I2CTimeout = 10; |
- | |
146 | I2C_Start(); |
- | |
147 | break; |
- | |
148 | case 18: |
- | |
149 | i2c_write_byte(0x98); // Address of the DAC |
- | |
150 | break; |
- | |
151 | case 19: |
- | |
152 | i2c_write_byte(0x14); // Update Channel C |
- | |
153 | break; |
- | |
154 | case 20: |
- | |
155 | i2c_write_byte(AnalogOffsetGier); // Value |
- | |
156 | break; |
- | |
157 | case 21: |
- | |
158 | i2c_write_byte(0x80); // Value |
- | |
159 | break; |
- | |
160 | case 22: |
142 | break; |
161 | I2C_Stop(); |
- | |
162 | I2CTimeout = 10; |
- | |
163 | twi_state = 0; |
- | |
164 | break; |
- | |
165 | default: twi_state = 0; |
- | |
166 | break; |
- | |
167 | } |
- | |
168 | TWCR |= 0x80; |
- | |
169 | } |
- | |
170 | */ |
- | |
171 | - | ||
172 | /* |
- | |
173 | if(DataArray[3] & 0x01) Parameter.PwmScaling = DataArray[4]; |
- | |
174 | if(DataArray[3] & 0x02) Parameter.MaxStrom = DataArray[5]; |
- | |
175 | if(DataArray[3] & 0x04) Parameter.TemperaturLimiter = DataArray[6]; |
- | |
176 | if(DataArray[3] & 0x08) Parameter.SkaliereStrom = DataArray[7]; |
- | |
177 | if(DataArray[3] & 0x10) Parameter.Bitconfig = DataArray[8]; |
- | |
178 | */ |
- | |
179 | - | ||
180 | //############################################################################ |
- | |
181 | SIGNAL (TWI_vect) |
- | |
182 | //############################################################################ |
- | |
183 | { // 2 3 4 5 6 7 8 9 |
- | |
184 | unsigned char test[] = {0,0,'#',0x1F,255,30,99,64,0x00,7,8,9,10}; |
- | |
185 | static unsigned char missing_motor,send = 0,crc = 0,read_more = 0; |
- | |
186 | J4High; |
143 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
187 | switch(twi_state++) |
144 | // Reading Data |
188 | { |
145 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
189 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
190 | // Writing the Data |
- | |
191 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
192 | case 0: |
- | |
193 | while(Mixer.Motor[motor][0] <= 0 && motor < MAX_MOTORS) motor++; // skip if not used |
146 | case 5: |
194 | if(motor == MAX_MOTORS) // writing finished -> now read |
147 | //Transmit 1st byte for reading |
195 | { |
- | |
196 | motor = 0; |
- | |
197 | twi_state = 4; |
148 | if(TWSR != 0x40) // Error? |
198 | i2c_write_byte(0x53+(motorread*2)); |
- | |
199 | } |
- | |
200 | else i2c_write_byte(0x52+(motor*2)); |
- | |
201 | send = 0; |
- | |
202 | break; |
- | |
203 | case 1: |
- | |
204 | i2c_write_byte(Motor[motor].SetPoint); |
149 | { |
205 | // if(!(Motor[motor].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) /*|| !Motor[motor].SetPointLowerBits*/) |
150 | Motor[motorread].State &= ~MOTOR_STATE_PRESENT_MASK; // clear present bit |
206 | if((!(Motor[motor].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) || !Motor[motor].SetPointLowerBits) && !TransmitBlConfig) |
151 | if(++motorread >= MAX_MOTORS) |
207 | twi_state++; // skip |
152 | { |
208 | break; |
- | |
209 | case 2: |
- | |
210 | if(!send++) |
- | |
211 | { |
- | |
212 | i2c_write_byte((Motor[motor].SetPointLowerBits << 1) & 0x07); |
- | |
213 | crc = 0xAA; |
- | |
214 | } |
153 | BLFlags &= ~BLFLAG_SEND_CONFIG; |
215 | else |
- | |
216 | if(send == 9) i2c_write_byte(crc) |
154 | motorread = 0; |
- | 155 | if(++motorread_temperature >= MAX_MOTORS) |
|
217 | else |
156 | { |
218 | { |
157 | motorread_temperature = 0; |
219 | crc += test[send]; |
- | |
220 | i2c_write_byte(test[send]); |
- | |
221 | } |
- | |
222 | if(TransmitBlConfig && !MotorenEin && motor == motorread && (Motor[motorread].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)) |
- | |
223 | { |
158 | BLFlags &= ~BLFLAG_READ_VERSION; |
224 | if(send <= 10) twi_state--; |
- | |
225 | } |
- | |
226 | break; |
159 | } |
227 | case 3: |
- | |
228 | motor++; |
- | |
229 | if(TWSR == 0x30) |
- | |
230 | { |
- | |
231 | if(!missing_motor) missing_motor = motor; |
- | |
232 | if((Motor[motor-1].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK) Motor[motor-1].State++; // increment error counter and handle overflow |
- | |
233 | } |
- | |
234 | I2C_Stop(); |
- | |
235 | I2CTimeout = 10; |
- | |
236 | twi_state = 0; |
- | |
237 | I2C_Start(); |
- | |
238 | break; |
- | |
239 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
240 | // Reading Data |
- | |
241 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
242 | case 4: |
- | |
243 | //Transmit 1st byte for reading |
- | |
244 | if(TWSR != 0x40) // Error? |
- | |
245 | { |
- | |
246 | Motor[motorread].State &= ~MOTOR_STATE_PRESENT_MASK; // clear present bit |
- | |
247 | motorread++; |
160 | } |
248 | if(motorread >= MAX_MOTORS) { TransmitBlConfig = 0; motorread = 0; ReadTemperature = ++ReadTemperature & 0x0f;} |
161 | I2C_Stop(); |
249 | I2C_Stop(); |
162 | twi_state = 0; |
250 | twi_state = 0; |
163 | BLFlags |= BLFLAG_TX_COMPLETE; |
251 | } |
164 | } |
252 | else |
165 | else |
253 | { |
166 | { |
254 | Motor[motorread].State |= MOTOR_STATE_PRESENT_MASK; // set present bit |
167 | Motor[motorread].State |= MOTOR_STATE_PRESENT_MASK; // set present bit |
255 | if(motorread == ReadTemperature || TransmitBlConfig) |
- | |
256 | { |
168 | if(motorread == motorread_temperature) |
- | 169 | { |
|
257 | read_more = 1; |
170 | read_more = 1; |
258 | I2C_ReceiveByte(); |
171 | I2C_ReceiveByte(); |
259 | } |
172 | } |
260 | else |
173 | else |
261 | { |
174 | { |
262 | I2C_ReceiveLastByte(); |
175 | read_more = 0; |
263 | read_more = 0; |
176 | I2C_ReceiveLastByte(); |
264 | } |
177 | } |
- | 178 | } |
|
- | 179 | MissingMotor = missing_motor; |
|
- | 180 | missing_motor = 0; |
|
- | 181 | break; |
|
265 | } |
182 | case 6: //Read 1st byte and transmit 2nd Byte |
- | 183 | Motor[motorread].Current = TWDR; |
|
- | 184 | if(read_more) |
|
266 | MissingMotor = missing_motor; |
185 | { |
267 | missing_motor = 0; |
186 | I2C_ReceiveByte() //ack |
- | 187 | ||
268 | break; |
188 | } |
- | 189 | else |
|
- | 190 | { |
|
- | 191 | if(++motorread >= MAX_MOTORS) |
|
- | 192 | { |
|
- | 193 | motorread = 0; // restart from beginning |
|
269 | case 5: //Read 1st byte and transmit 2nd Byte |
194 | BLFlags &= ~BLFLAG_SEND_CONFIG; |
270 | Motor[motorread].Current = TWDR; |
195 | if(++motorread_temperature >= MAX_MOTORS) |
- | 196 | { |
|
271 | if(read_more) I2C_ReceiveByte() //nack |
197 | motorread_temperature = 0; |
272 | else |
198 | BLFlags &= ~BLFLAG_READ_VERSION; |
273 | { |
199 | } |
274 | motorread++; // next motor |
200 | } |
275 | if(motorread >= MAX_MOTORS) { TransmitBlConfig = 0; motorread = 0; ReadTemperature = ++ReadTemperature & 0x0f;} |
201 | I2C_Stop(); |
- | 202 | twi_state = 0; |
|
- | 203 | BLFlags |= BLFLAG_TX_COMPLETE; |
|
276 | I2C_Stop(); |
204 | } |
277 | twi_state = 0; |
205 | break; |
278 | } |
206 | case 7: |
279 | break; |
207 | //Read 2nd byte and transmit 3rd Byte |
- | 208 | Motor[motorread].MaxPWM = TWDR; |
|
- | 209 | if(BLFlags & BLFLAG_READ_VERSION) |
|
280 | case 6: |
210 | { |
- | 211 | if(TWDR == 250) |
|
- | 212 | { |
|
281 | //Read 2nd byte and transmit 3rd Byte |
213 | if(!MotorenEin) Motor[motorread].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK; |
282 | Motor[motorread].MaxPWM = TWDR; |
214 | } |
283 | if(TWDR == 250) |
215 | else |
284 | { |
216 | { |
285 | if(!MotorenEin) Motor[motorread].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK; |
217 | Motor[motorread].Version = 0; |
- | 218 | } |
|
286 | } |
219 | } |
- | 220 | I2C_ReceiveLastByte(); //nack |
|
- | 221 | break; |
|
- | 222 | case 8: // read next |
|
- | 223 | Motor[motorread].Temperature = TWDR; |
|
- | 224 | if(++motorread >= MAX_MOTORS) |
|
- | 225 | { |
|
- | 226 | motorread = 0; // restart reading of first motor |
|
287 | else if(TransmitBlConfig) Motor[motorread].Version = 0; |
227 | BLFlags &= ~BLFLAG_SEND_CONFIG; |
- | 228 | if(++motorread_temperature >= MAX_MOTORS) |
|
288 | I2C_ReceiveLastByte(); //nack |
229 | { |
289 | break; |
230 | motorread_temperature = 0; |
290 | case 7: // read next |
231 | BLFlags &= ~BLFLAG_READ_VERSION; |
291 | Motor[motorread].Temperature = TWDR; |
232 | } |
292 | motorread++; // next motor |
233 | } |
Line 348... | Line 289... | ||
348 | I2CTimeout = 10; |
289 | I2CTimeout = 10; |
349 | twi_state = 0; |
290 | twi_state = 0; |
350 | break; |
291 | break; |
351 | default: twi_state = 0; |
292 | default: twi_state = 0; |
352 | break; |
293 | break; |
353 | } |
294 | } |
354 | TWCR |= 0x80; |
295 | TWCR |= 0x80; |
355 | J4Low; |
296 | J4Low; |
- | 297 | } |
|
- | 298 | ||
- | 299 | void I2C_SendBLConfig(void) |
|
- | 300 | { |
|
- | 301 | unsigned char i; |
|
- | 302 | while(!(BLFlags & BLFLAG_TX_COMPLETE)); //wait for complete transfer |
|
- | 303 | BLFlags |= BLFLAG_SEND_CONFIG; // enable sending of BL config |
|
- | 304 | for(i = 0; i < MAX_MOTORS; i++) |
|
- | 305 | { |
|
- | 306 | Motor[i].SetPoint = 0; |
|
- | 307 | Motor[i].SetPointLowerBits = 0; |
|
- | 308 | } |
|
- | 309 | motorread = 0; |
|
- | 310 | // needs at least MAX_MOTORS loops of 2 ms (12*2ms = 24ms) |
|
- | 311 | do |
|
- | 312 | { |
|
- | 313 | twi_state = 0; |
|
- | 314 | I2C_Start(); // start an i2c transmission |
|
- | 315 | while(!(BLFlags & BLFLAG_TX_COMPLETE)); //wait for complete transfer |
|
- | 316 | }while(BLFlags & BLFLAG_SEND_CONFIG); // repeat until the BL config has been send to all motors |
|
356 | } |
317 | } |
Line -... | Line 318... | ||
- | 318 | ||
- | 319 |