Revision 663
it is having problems after the first charge where it gets stuck and stops sending anything
stop.c | ||
---|---|---|
18 | 18 |
#define I2C_MSG_ENTERING_SLEEP 'Z' |
19 | 19 |
#define I2C_MSG_HOMING 'H' |
20 | 20 |
|
21 |
#define DETECT_12V PB6 |
|
21 | 22 |
|
23 |
|
|
22 | 24 |
#define SW0 PA6 |
23 | 25 |
#define HOMING_PIN PA7 |
24 | 26 |
|
... | ... | |
66 | 68 |
|
67 | 69 |
int main( void ) |
68 | 70 |
{ |
71 |
int count; |
|
72 |
|
|
69 | 73 |
DDRB = _BV(PB0) | _BV(PB5) | _BV(PB4); |
70 | 74 |
i2c_init(); |
71 | 75 |
|
... | ... | |
76 | 80 |
|
77 | 81 |
char data[2]; |
78 | 82 |
data[0]=I2C_MSG_DATA; |
79 |
|
|
83 |
|
|
84 |
|
|
80 | 85 |
while(1) |
81 | 86 |
{ |
82 | 87 |
PORTB=_BV(LED2); |
83 | 88 |
while(1) |
84 | 89 |
{ |
85 |
if(PINB & _BV(PB6))
|
|
90 |
if(PINB & _BV(DETECT_12V))
|
|
86 | 91 |
{ |
87 | 92 |
PORTB = _BV(LED1); |
88 | 93 |
//This is a junk byte. For some reason the first packet is always ignored???? |
... | ... | |
94 | 99 |
} |
95 | 100 |
else |
96 | 101 |
{ |
97 |
data[0]=I2C_MSG_NO_CONTACT;
|
|
102 |
data[1]=I2C_MSG_NO_CONTACT;
|
|
98 | 103 |
|
99 | 104 |
get_delay(); //reject the first reading //homing import stuff, uncomment this!!!!!! |
100 |
data[1]=I2C_MSG_HOMING; |
|
101 |
data[2]=get_delay(); |
|
102 |
i2c_putpacket(0x01, data, 3); |
|
105 |
count = get_delay(); |
|
106 |
if(count>2){ |
|
107 |
data[2]=I2C_MSG_HOMING; |
|
108 |
data[3]=count; |
|
109 |
i2c_putpacket(0x01, data, 4); |
|
110 |
} |
|
111 |
else{ |
|
112 |
i2c_putpacket(0x01, data, 2); |
|
113 |
} |
|
103 | 114 |
} |
104 | 115 |
} |
105 | 116 |
|
106 |
for(int i=0;i<5000;i++) |
|
117 |
count = 0; |
|
118 |
|
|
119 |
for(int i=0;i<60000;i++) |
|
107 | 120 |
{ |
108 | 121 |
delay_ms(1); |
109 |
if(! PINB & _BV(PB6))
|
|
122 |
if(! (PINB & _BV(DETECT_12V)))
|
|
110 | 123 |
{ |
111 | 124 |
PORTB = _BV(LED2); |
112 | 125 |
data[1]=I2C_MSG_CONTACT_ERROR; |
113 | 126 |
i2c_putpacket(0x01, data, 2); |
114 | 127 |
|
115 |
while(! PINB & _BV(PB6));
|
|
128 |
if((++count)>=500)
|
|
116 | 129 |
break; |
117 | 130 |
} |
131 |
else |
|
132 |
count = 0; |
|
118 | 133 |
|
119 | 134 |
} |
120 | 135 |
|
Also available in: Unified diff