Rev 726 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 726 | Rev 898 | ||
---|---|---|---|
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[12]; |
14 | 14 | ||
15 | /**************************************************/ |
15 | /**************************************************/ |
16 | /* Initialize I2C (TWI) */ |
16 | /* Initialize I2C (TWI) */ |
Line 137... | Line 137... | ||
137 | break; |
137 | break; |
138 | case 1: // Send Data to Salve |
138 | case 1: // Send Data to Salve |
139 | switch(motor++) |
139 | switch(motor++) |
140 | { |
140 | { |
141 | case 0: |
141 | case 0: |
142 | I2C_WriteByte(Motor_Front); |
142 | I2C_WriteByte(Motor_FrontLeft); |
143 | break; |
143 | break; |
144 | case 1: |
144 | case 1: |
145 | I2C_WriteByte(Motor_Rear); |
145 | I2C_WriteByte(Motor_RearRight); |
146 | break; |
146 | break; |
147 | case 2: |
147 | case 2: |
148 | I2C_WriteByte(Motor_Right); |
148 | I2C_WriteByte(Motor_FrontRight); |
149 | break; |
149 | break; |
150 | case 3: |
150 | case 3: |
- | 151 | I2C_WriteByte(Motor_RearLeft); |
|
- | 152 | break; |
|
- | 153 | case 4: |
|
- | 154 | I2C_WriteByte(Motor_Right); |
|
- | 155 | break; |
|
- | 156 | case 5: |
|
151 | I2C_WriteByte(Motor_Left); |
157 | I2C_WriteByte(Motor_Left); |
152 | break; |
158 | break; |
153 | } |
159 | } |
154 | break; |
160 | break; |
155 | case 2: // repeat case 0+1 for all Slaves |
161 | case 2: // repeat case 0+1 for all Slaves |
156 | if (motor<4) twi_state = 0; |
162 | if (motor<6) twi_state = 0; |
157 | I2C_Start(); // Repeated start -> switch salve or switch Master Transmit -> Master Receive |
163 | I2C_Start(); // Repeated start -> switch salve or switch Master Transmit -> Master Receive |
158 | break; |
164 | break; |
Line 159... | Line 165... | ||
159 | 165 | ||
160 | // Master Receive |
166 | // Master Receive |
Line 169... | Line 175... | ||
169 | motor_rx[motorread] = TWDR; |
175 | motor_rx[motorread] = TWDR; |
170 | I2C_ReceiveLastByte(); |
176 | I2C_ReceiveLastByte(); |
171 | break; |
177 | break; |
172 | case 6: |
178 | case 6: |
173 | //Read 2nd byte |
179 | //Read 2nd byte |
174 | motor_rx[motorread+4] = TWDR; |
180 | motor_rx[motorread+6] = TWDR; |
175 | motorread++; |
181 | motorread++; |
176 | if (motorread > 3) motorread=0; |
182 | if (motorread > 5) motorread=0; |
Line 177... | Line 183... | ||
177 | 183 | ||
178 | default: |
184 | default: |
179 | I2C_Stop(); |
185 | I2C_Stop(); |
180 | twi_state = 0; |
186 | twi_state = 0; |