Project

General

Profile

Revision 6185434e

ID6185434e240138281ebf3829ea3f1f49a596e9b2
Parent 64b6024c
Child 240c122b

Added by Thomas Mullins over 10 years ago

A few fixes to tiny-twi. Recieving works now!

View differences:

scout_avr/bom/tiny-twi.c
74 74
}
75 75

  
76 76
ISR(USI_OVF_vect) {
77
  uint8_t input = USIDR; // WTF ASK TOM
77
  uint8_t input = USIDR; // TODO make sure this is correct
78 78
  switch (state) {
79 79

  
80 80
    case IDLE:
......
86 86
      if (input >> 1 == address) {
87 87
        // send ack
88 88
        twi_send_ack(input & 1);
89
        PORTB |= _BV(PB4); // DEBUG LED ON
90 89
      } else {
91 90
        // go back to listening for start condition
92 91
        twi_ready();
......
94 93
      break;
95 94

  
96 95
    case SEND_WRITE_ACK:
97
      DDRB &= ~_BV(SDA);
98
      state = RECV_DATA;
96
      if (recv_idx == RECV_BUF_SIZE) {
97
        twi_ready();
98
        onDataRecieved(recv_data, RECV_BUF_SIZE);
99
      } else {
100
        DDRB &= ~_BV(SDA);
101
        state = RECV_DATA;
102
      }
99 103
      break;
100 104

  
101 105
    case RECV_DATA:
102 106
      twi_send_ack(0);
103
      recv_data[recv_idx] = USIBR;
107
      recv_data[recv_idx] = input;
104 108
      recv_idx++;
105
      if (recv_idx == RECV_BUF_SIZE) {
106
        twi_ready();
107
        onDataRecieved(recv_data, RECV_BUF_SIZE);
108
      }
109 109
      break;
110 110

  
111 111
    case SEND_READ_ACK:
......
136 136
}
137 137

  
138 138
void testCB(uint8_t* data, int length) {
139
  PORTB |= _BV(PB4);
140
  if (data[0])
141
    _delay_ms(1000);
142
  else
143
    _delay_ms(500);
144
  PORTB &= ~_BV(PB4);
145 139
}
146 140

  
147 141

  
......
152 146
  smb_init(testCB);
153 147
  while(1);
154 148
}
155

  
156

  
157

  
158

  
159

  
160
/* debug code
161
USICR &= ~_BV(USISIE);
162
USICR &= ~_BV(USIOIE);
163

  
164
int i;
165
for (i=0; i<8; i++) {
166
  _delay_ms(1000);
167
	  PORTB |= _BV(PB4); // DEBUG LED ON
168
  if ((input >> i) & 1) _delay_ms(1000);
169
  else _delay_ms(500);
170
      PORTB &= ~_BV(PB4); // DEBUG LED OFF
171
}
172
*/

Also available in: Unified diff