Rev 130 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 130 | Rev 243 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | //############################################################################ |
32 | //############################################################################ |
33 | { |
33 | { |
34 | TWCR = (1<<TWEN) | (1<<TWSTO) | (1<<TWINT); |
34 | TWCR = (1<<TWEN) | (1<<TWSTO) | (1<<TWINT); |
35 | } |
35 | } |
Line -... | Line 36... | ||
- | 36 | ||
- | 37 | void i2c_reset(void) |
|
- | 38 | //############################################################################ |
|
- | 39 | { |
|
- | 40 | i2c_stop(); |
|
- | 41 | twi_state = 0; |
|
- | 42 | motor = TWDR; |
|
- | 43 | motor = 0; |
|
- | 44 | TWCR = 0x80; |
|
- | 45 | TWAMR = 0; |
|
- | 46 | TWAR = 0; |
|
- | 47 | TWDR = 0; |
|
- | 48 | TWSR = 0; |
|
- | 49 | TWBR = 0; |
|
- | 50 | i2c_init(); |
|
- | 51 | i2c_start(); |
|
- | 52 | i2c_write_byte(0); |
|
- | 53 | } |
|
36 | 54 | ||
37 | //############################################################################ |
55 | //############################################################################ |
38 | //Start I2C |
56 | //Start I2C |
39 | char i2c_write_byte(char byte) |
57 | char i2c_write_byte(char byte) |
40 | //############################################################################ |
58 | //############################################################################ |
Line 102... | Line 120... | ||
102 | break; |
120 | break; |
103 | } |
121 | } |
104 | break; |
122 | break; |
105 | case 5: //1 Byte vom Motor lesen |
123 | case 5: //1 Byte vom Motor lesen |
106 | motor_rx[motorread] = TWDR; |
124 | motor_rx[motorread] = TWDR; |
- | 125 | ||
107 | case 6: |
126 | case 6: |
108 | switch(motorread) |
127 | switch(motorread) |
109 | { |
128 | { |
110 | case 0: |
129 | case 0: |
111 | i2c_write_byte(Motor_Vorne); |
130 | i2c_write_byte(Motor_Vorne); |
Line 124... | Line 143... | ||
124 | case 7: //2 Byte vom Motor lesen |
143 | case 7: //2 Byte vom Motor lesen |
125 | motor_rx[motorread+4] = TWDR; |
144 | motor_rx[motorread+4] = TWDR; |
126 | motorread++; |
145 | motorread++; |
127 | if (motorread>3) motorread=0; |
146 | if (motorread>3) motorread=0; |
128 | i2c_stop(); |
147 | i2c_stop(); |
- | 148 | I2CTimeout = 10; |
|
129 | twi_state = 0; |
149 | twi_state = 0; |
130 | } |
150 | } |
- | 151 | TWCR |= 0x80; |
|
131 | } |
152 | } |