Subversion Repositories FlightCtrl

Rev

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

Rev 1455 Rev 1456
Line 4... Line 4...
4
#include <util/twi.h>
4
#include <util/twi.h>
5
#include <avr/interrupt.h>
5
#include <avr/interrupt.h>
6
#include "servoboard.h"
6
#include "servoboard.h"
7
#include "twislave.h"
7
#include "twislave.h"
Line 8... Line 8...
8
 
8
 
9
unsigned char I2C_RXBuffer[32];
9
uint8_t I2C_RXBuffer[32];
10
unsigned char Byte_Counter = 0;
-
 
Line 11... Line 10...
11
unsigned char I2C_Timeout = 0;
10
uint8_t Byte_Counter = 0;
12
 
11
 
13
void InitIC2_Slave(uint8_t adr)
12
void InitIC2_Slave(uint8_t adr)
14
{
13
{
Line 25... Line 24...
25
        return crc;
24
        return crc;
26
}
25
}
Line 27... Line 26...
27
 
26
 
Line 28... Line -...
28
ISR (TWI_vect) {
-
 
29
 
27
ISR (TWI_vect) {
30
#if 1
28
 
31
        static char cnt=0;
29
        static char cnt = 0;
32
        if (pwm_neutral_programming_mode == 0 && cnt++ == 0) {
30
        if (pwm_neutral_programming_mode == 0 && cnt++ == 0) {
33
                if (PORTD&0x80) PORTD&=~0x80; else PORTD|=0x80;
-
 
Line 34... Line 31...
34
        }
31
                if (PORTD & 0x80) PORTD &= ~0x80; else PORTD |= 0x80;
35
#endif
-
 
36
 
32
        }
37
    switch (TWSR & 0xF8)
33
 
38
        {  
34
    switch (TWSR & 0xF8) {  
39
        case SR_SLA_ACK:  
35
        case SR_SLA_ACK:  
40
            TWCR |= (1<<TWINT);
36
            TWCR |= (1<<TWINT);
41
            Byte_Counter = 0;
-
 
42
            return;
37
            Byte_Counter = 0;
43
        case SR_PREV_ACK:
38
            return;
44
            I2C_Timeout = 250;
39
        case SR_PREV_ACK:
45
                        if (Byte_Counter < 32) {
40
                        if (Byte_Counter < 32) {
46
                                I2C_RXBuffer[Byte_Counter++] = TWDR;
41
                                I2C_RXBuffer[Byte_Counter++] = TWDR;
Line 54... Line 49...
54
            return;
49
            return;
55
        case TWI_BUS_ERR_2:
50
        case TWI_BUS_ERR_2:
56
            TWCR |=(1<<TWSTO) | (1<<TWINT);
51
            TWCR |=(1<<TWSTO) | (1<<TWINT);
57
        case TWI_BUS_ERR_1:
52
        case TWI_BUS_ERR_1:
58
            TWCR |=(1<<TWSTO) | (1<<TWINT);
53
            TWCR |=(1<<TWSTO) | (1<<TWINT);
59
        }
54
    }
60
    TWCR =(1<<TWEA) | (1<<TWINT) | (1<<TWEN) | (1<<TWIE); // TWI Reset
55
    TWCR =(1<<TWEA) | (1<<TWINT) | (1<<TWEN) | (1<<TWIE);
-
 
56
 
61
}
57
}