Rev 886 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 886 | Rev 903 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | #include "twimaster.h" |
8 | #include "twimaster.h" |
9 | #include "fc.h" |
9 | #include "fc.h" |
Line 10... | Line 10... | ||
10 | 10 | ||
11 | volatile uint8_t twi_state = 0; |
11 | volatile uint8_t twi_state = 0; |
12 | volatile uint8_t motor = 0; |
12 | volatile uint8_t motor = 0; |
Line 13... | Line 13... | ||
13 | volatile uint8_t motor_rx[8]; |
13 | volatile uint8_t motor_rx[MOTOR_COUNT*2]; |
14 | 14 | ||
15 | /**************************************************/ |
15 | /**************************************************/ |
16 | /* Initialize I2C (TWI) */ |
16 | /* Initialize I2C (TWI) */ |
Line 134... | Line 134... | ||
134 | // Master Transmit |
134 | // Master Transmit |
135 | case 0: // Send SLA-W |
135 | case 0: // Send SLA-W |
136 | I2C_WriteByte(0x52+(motor*2)); |
136 | I2C_WriteByte(0x52+(motor*2)); |
137 | break; |
137 | break; |
138 | case 1: // Send Data to Salve |
138 | case 1: // Send Data to Salve |
- | 139 | #ifdef HEXAKOPTER |
|
- | 140 | switch(motor++) |
|
- | 141 | { |
|
- | 142 | case 0: |
|
- | 143 | I2C_WriteByte(Motor_FrontLeft); |
|
- | 144 | break; |
|
- | 145 | case 1: |
|
- | 146 | I2C_WriteByte(Motor_RearRight); |
|
- | 147 | break; |
|
- | 148 | case 2: |
|
- | 149 | I2C_WriteByte(Motor_FrontRight); |
|
- | 150 | break; |
|
- | 151 | case 3: |
|
- | 152 | I2C_WriteByte(Motor_RearLeft); |
|
- | 153 | break; |
|
- | 154 | case 4: |
|
- | 155 | I2C_WriteByte(Motor_Right); |
|
- | 156 | break; |
|
- | 157 | case 5: |
|
- | 158 | I2C_WriteByte(Motor_Left); |
|
- | 159 | break; |
|
- | 160 | } |
|
- | 161 | ||
- | 162 | #else |
|
139 | switch(motor++) |
163 | switch(motor++) |
140 | { |
164 | { |
141 | case 0: |
165 | case 0: |
142 | I2C_WriteByte(Motor_Front); |
166 | I2C_WriteByte(Motor_Front); |
143 | break; |
167 | break; |
Line 149... | Line 173... | ||
149 | break; |
173 | break; |
150 | case 3: |
174 | case 3: |
151 | I2C_WriteByte(Motor_Left); |
175 | I2C_WriteByte(Motor_Left); |
152 | break; |
176 | break; |
153 | } |
177 | } |
- | 178 | #endif |
|
154 | break; |
179 | break; |
155 | case 2: // repeat case 0+1 for all Slaves |
180 | case 2: // repeat case 0+1 for all Slaves |
156 | if (motor<4) twi_state = 0; |
181 | if (motor<MOTOR_COUNT) twi_state = 0; |
157 | I2C_Start(); // Repeated start -> switch salve or switch Master Transmit -> Master Receive |
182 | I2C_Start(); // Repeated start -> switch salve or switch Master Transmit -> Master Receive |
158 | break; |
183 | break; |
Line 159... | Line 184... | ||
159 | 184 | ||
160 | // Master Receive |
185 | // Master Receive |
Line 170... | Line 195... | ||
170 | I2C_ReceiveLastByte(); |
195 | I2C_ReceiveLastByte(); |
171 | break; |
196 | break; |
172 | case 6: |
197 | case 6: |
173 | //Read 2nd byte |
198 | //Read 2nd byte |
174 | motor_rx[motorread+4] = TWDR; |
199 | motor_rx[motorread+4] = TWDR; |
175 | motorread++; |
- | |
176 | if (motorread > 3) motorread=0; |
200 | if (++motorread >= MOTOR_COUNT) motorread=0; |
Line 177... | Line 201... | ||
177 | 201 | ||
178 | default: |
202 | default: |
179 | I2C_Stop(); |
203 | I2C_Stop(); |
180 | twi_state = 0; |
204 | twi_state = 0; |