Project

General

Profile

Revision 0167b233

ID0167b2335dde3148a8bf7a8927dbcd42212f77e3
Parent 47a7eeb7
Child 4032e635

Added by Aaron Perley over 10 years ago

Twi receiving testing code

View differences:

scout_avr/bom/tiny-twi.c
1 1
#include <avr/io.h>
2 2
#include <avr/interrupt.h>
3
#include <util/delay.h>
3 4

  
4 5
#define RECV_BUF_SIZE 2
5 6

  
......
17 18

  
18 19
uint8_t recv_idx;
19 20
uint8_t recv_data[RECV_BUF_SIZE];
21
slave_rx_t onDataRecieved;
20 22

  
21 23
static void twi_set_ctr(char n) {
22 24
  USISR &= ~0x0F;
......
93 95
      recv_idx++;
94 96
      if (recv_idx == RECV_BUF_SIZE) {
95 97
        twi_ready();
96
        // TODO callback
98
        onDataRecieved(recv_data, RECV_BUF_SIZE);
97 99
      }
98 100
      break;
99 101

  
......
110 112
  }
111 113
}
112 114

  
113
void smb_init() {
115
void smb_init(slave_rx_t callback) {
114 116
  state = START;
115 117

  
116 118
  // TODO do we want USICS0 (3)?
117 119
  USICR = _BV(USIWM1) | _BV(USIWM0) | _BV(USICS1);
118 120
  twi_ready();
121
  onDataRecieved = callback;
119 122
}
120 123

  
121 124
void smb_set_address(uint8_t addr) {
122 125
  address = addr;
123 126
}
127

  
128
void testCB(uint8_t* data, int length) {
129
  PORTB |= _BV(PB4);
130
  if (data[0])
131
    _delay_ms(1000);
132
  else
133
    _delay_ms(500);
134
  PORTB &= ~_BV(PB4);
135
}
136

  
137

  
138
int main() {
139
  smb_set_address(5);
140
  DDRB |= _BV(DDB4);
141
  smb_init(testCB);
142
}

Also available in: Unified diff