Project

General

Profile

Revision 5f7a1707

ID5f7a1707e50d0cf0a974c9c34688dd58f477d57f
Parent e4d78d85
Child a75b176a

Added by Thomas Mullins about 10 years ago

Debugging BOM

View differences:

scout_avr/bom/bom.c
1 1
#include <stdint.h>
2 2
#include <avr/io.h>
3 3
#include <avr/interrupt.h>
4
#include <util/delay.h>
4 5
#include "tiny-twi.h"
5 6
#include "bomi2c.h"
6 7

  
......
29 30
#endif
30 31

  
31 32
static void bom_init(void) {
33

  
34
  SET_BIT(DDRB, EMIT);
35

  
32 36
  init_detect();
33 37

  
34 38
  init_timer1();
......
41 45
static void init_detect(void) {
42 46
  TCCR0A |= _BV(WGM01);    // enable reset on compare A
43 47
  TIMSK  |= _BV(OCIE0A);   // enable timer0 compare match A
48
  OCR0A   = TIME_US(1000); // trigger every 1ms
44 49

  
50
  GIFR   |= _BV(PCIF);   // Clear any previous detections
45 51
  GIMSK  |= _BV(PCIE);   // Enable pin change interrupt for detection
46 52
  PCMSK  |= _BV(PCINT_DETECT); // Enable interrupt on detect pin
47 53
}
......
61 67
  data = 0;
62 68
  count = 0;
63 69
  last_bit = 1;
70
  _delay_us(160);
64 71
  start_timer0();
65 72
}
66 73

  
......
76 83
ISR(TIMER0_COMPA_vect) {
77 84

  
78 85
  char this_bit = READ_BIT(PINB, DETECT);
86
  smb_send_data((uint8_t*)&this_bit, 1);
79 87

  
80
  if (this_bit == 0) {
81
    if (last_bit == 0) {
88
  if (this_bit == 1) {
89
    if (last_bit == 1) {
82 90
      restart_detect();
83 91
    }
84 92
  } else {
85
    data = data << 1 | (~last_bit & 1);
93
    data = data << 1 | (last_bit & 1);
86 94
    count++;
87 95
  }
88 96

  
scout_avr/bom/tiny-twi.c
81 81
static void twi_send_data() {
82 82
  twi_set_ctr(0);
83 83
  if (send_queue.start == send_queue.end && !send_queue.full) {
84
    USIDR = 0;
84
    USIDR = 0xFF;
85 85
  } else {
86 86
    USIDR = send_queue.data[send_queue.start++];
87 87
    if (send_queue.start == SEND_BUF_SIZE)

Also available in: Unified diff