Rev 2109 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2109 | Rev 2133 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | 7 | ||
8 | uint8_t twiState; |
8 | uint8_t twiState; |
9 | uint8_t twiTroubleSpot; |
9 | uint8_t twiTroubleSpot; |
Line 10... | Line 10... | ||
10 | uint8_t twiGotStatus; |
10 | uint8_t twiGotStatus; |
Line 11... | Line 11... | ||
11 | 11 | ||
12 | volatile uint16_t IMU3200SensorInputs[4]; |
12 | volatile int16_t ITG3200SensorInputs[4]; |
13 | 13 | ||
14 | void twimaster_init(void) { |
14 | void twimaster_init(void) { |
15 | // Set pullups |
15 | // Set pullups OFF |
16 | uint8_t sreg = SREG; |
16 | uint8_t sreg = SREG; |
17 | cli(); |
17 | cli(); |
18 | DDRC = 0; |
18 | DDRC = 0; |
19 | PORTC = ((1 << 4) | (1 << 5)); |
19 | PORTC &= ~((1<<4) | (1<<5)); |
20 | TWBR = ((F_CPU / SCL_CLOCK) - 16) / 2; |
20 | TWBR = ((F_CPU / SCL_CLOCK) - 16) / 2; |
Line 138... | Line 138... | ||
138 | break; |
138 | break; |
139 | case TWI_STATE_LOOP_0 + 4: |
139 | case TWI_STATE_LOOP_0 + 4: |
140 | I2CReceiveByte(); |
140 | I2CReceiveByte(); |
141 | break; |
141 | break; |
142 | default: // data bytes |
142 | default: // data bytes |
143 | ((uint8_t*) IMU3200SensorInputs)[dataIndex] = TWDR; |
143 | ((uint8_t*) ITG3200SensorInputs)[dataIndex] = TWDR; |
144 | if (twiState < TWI_STATE_LOOP_0 + 5 + sizeof(IMU3200SensorInputs) - 1) |
144 | if (twiState < TWI_STATE_LOOP_0 + 5 + sizeof(ITG3200SensorInputs) - 1) |
145 | I2CReceiveByte(); |
145 | I2CReceiveByte(); |
146 | else |
146 | else |
147 | I2CReceiveLastByte(); |
147 | I2CReceiveLastByte(); |
148 | break; |
148 | break; |
149 | case TWI_STATE_LOOP_0 + 5 + sizeof(IMU3200SensorInputs) - 1: // last data byte |
149 | case TWI_STATE_LOOP_0 + 5 + sizeof(ITG3200SensorInputs) - 1: // last data byte |
150 | ((uint8_t*) IMU3200SensorInputs)[dataIndex] = TWDR; |
150 | ((uint8_t*) ITG3200SensorInputs)[dataIndex] = TWDR; |
151 | // Dont re-init the gyro but just restart the loop. |
151 | // Dont re-init the gyro but just restart the loop. |
152 | I2CStop(); |
152 | I2CStop(); |
153 | sensorDataReady |= TWI_DATA_READY; |
153 | sensorDataReady |= TWI_DATA_READY; |
154 | debugOut.analog[28]++; |
154 | debugOut.analog[28]++; |
155 | break; |
155 | break; |