19,15 → 19,14 |
|
//############################################################################ |
//Start I2C |
char i2c_start(void) |
void i2c_start(void) |
//############################################################################ |
{ |
TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE); |
return(0); |
} |
|
//############################################################################ |
//Start I2C |
//Stop I2C |
void i2c_stop(void) |
//############################################################################ |
{ |
35,16 → 34,12 |
} |
|
//############################################################################ |
//Start I2C |
char i2c_write_byte(char byte) |
//Write to I2C |
void i2c_write_byte(char byte) |
//############################################################################ |
{ |
TWSR = 0x00; |
{ |
TWDR = byte; |
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE); |
|
return(0); |
|
} |
|
//############################################################################ |
75,9 → 70,7 |
} |
break; |
case 2: |
i2c_stop(); |
if (motor<4) twi_state = 0; |
else motor = 0; |
i2c_start(); |
break; |
|
86,46 → 79,19 |
i2c_write_byte(0x53+(motorread*2)); |
break; |
case 4: |
switch(motorread) |
{ |
case 0: |
i2c_write_byte(Motor_Vorne); |
break; |
case 1: |
i2c_write_byte(Motor_Hinten); |
break; |
case 2: |
i2c_write_byte(Motor_Rechts); |
break; |
case 3: |
i2c_write_byte(Motor_Links); |
break; |
} |
i2c_write_byte(0xFF); |
break; |
case 5: //1 Byte vom Motor lesen |
case 5: //1. Byte vom Motor lesen |
motor_rx[motorread] = TWDR; |
case 6: |
switch(motorread) |
{ |
case 0: |
i2c_write_byte(Motor_Vorne); |
break; |
case 1: |
i2c_write_byte(Motor_Hinten); |
break; |
case 2: |
i2c_write_byte(Motor_Rechts); |
break; |
case 3: |
i2c_write_byte(Motor_Links); |
break; |
} |
break; |
case 7: //2 Byte vom Motor lesen |
i2c_write_byte(0xFF); |
break; |
case 6: //2. Byte vom Motor lesen |
motor_rx[motorread+4] = TWDR; |
motorread++; |
if (motorread>3) motorread=0; |
if (motorread>3) motorread=0; |
default: |
i2c_stop(); |
twi_state = 0; |
motor = 0; |
} |
} |