Subversion Repositories FlightCtrl

Rev

Rev 464 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 464 Rev 465
Line 45... Line 45...
45
//############################################################################
45
//############################################################################
46
//Start I2C
46
//Start I2C
47
SIGNAL (TWI_vect)
47
SIGNAL (TWI_vect)
48
//############################################################################
48
//############################################################################
49
{
49
{
50
    switch (twi_state++)
50
    switch (twi_state++)        // First i2c_start from SendMotorData()
51
        {
51
        {
-
 
52
                // Master Transmit
52
        case 0:
53
        case 0: // Address Slave SL+W
53
                i2c_write_byte(0x52+(motor*2));
54
                i2c_write_byte(0x52+(motor*2));
54
                break;
55
                break;
55
        case 1:
56
        case 1: // Send Data
56
                switch(motor++)
57
                switch(motor++)
57
                    {
58
                    {
58
                    case 0:
59
                    case 0:
59
                            i2c_write_byte(Motor_Vorne);
60
                            i2c_write_byte(Motor_Vorne);
60
                            break;
61
                            break;
Line 67... Line 68...
67
                    case 3:
68
                    case 3:
68
                            i2c_write_byte(Motor_Links);
69
                            i2c_write_byte(Motor_Links);
69
                            break;
70
                            break;
70
                    }
71
                    }
71
                break;
72
                break;
72
        case 2:
73
        case 2: // Repeat case 0+1 for all Slaves
73
                if (motor<4) twi_state = 0;
74
                if (motor < 4) twi_state = 0;
74
                i2c_start();  
-
 
75
                break;
-
 
76
                   
-
 
77
        //Liest Daten von Motor
-
 
78
        case 3:
-
 
79
                i2c_write_byte(0x53+(motorread*2));
75
                i2c_start();    // Repeated start -> switch salve and switch Master Transmit <-> Master Receive respectively
80
                break;
76
                break;
-
 
77
                 
81
        case 4:
78
        // Master Receive
-
 
79
        case 3: // Address Slave SL+R
82
                i2c_write_byte(0xFF);
80
                i2c_write_byte(0x53+(motorread*2));
83
                break;
81
                break;
84
        case 5: //1. Byte vom Motor lesen       
82
        case 4: //1. Byte vom Motor lesen       
85
                motor_rx[motorread] = TWDR;
83
                motor_rx[motorread] = TWDR;
86
                                i2c_write_byte(0xFF);
84
                                TWCR |= (1<<TWINT);
87
                                break;
85
                                break;
88
        case 6: //2. Byte vom Motor lesen       
86
        case 5: //2. Byte vom Motor lesen       
89
                motor_rx[motorread+4] = TWDR;
87
                motor_rx[motorread+4] = TWDR;
90
                motorread++;
88
                motorread++;
91
                                if (motorread>3) motorread=0;
89
                                if (motorread > 3) motorread=0;
92
                default:
90
                default:
93
                i2c_stop();
91
                i2c_stop();
94
                twi_state = 0;
92
                twi_state = 0;
95
                                motor = 0;
93
                                motor = 0;
96
        }
94
        }