Revision 168:bfc84ee2839b analog_exp/analog_exp.c

b/analog_exp/analog_exp.c
1 1
#include <avr/io.h>
2 2
#include <avr/interrupt.h>
3
#include <util/delay.h>
3 4

  
4 5
#include "board.h"
6
#include "debug.h"
7
#include "onewire.h"
8
#include "excitation.h"
5 9
#include "analog_exp.h"
6 10

  
11
onewire_id onewire_devices[4];
12

  
7 13
static inline void setup(void) {
14
    debug_setup();
15
    exc_setup();
8 16

  
17
    exc_enable(0, 0xFF);
9 18
}
10 19

  
11 20
static inline void loop(void) {
21
    ds18b20_scratchpad_t scratchpad;
12 22

  
23
    _delay_ms(1000);
24
    uint8_t n_devices = 4;
25
    onewire_searchrom(onewire_devices, &n_devices);
26

  
27
    onewire_skiprom();
28
    onewire_convert_t();
29
    _delay_ms(750);
30

  
31
    debugf("%d devices\n", n_devices);
32
    for(uint8_t i=0; i<n_devices; i++) {
33
        debugf("  0x");
34
        for(uint8_t j=0; j<sizeof(onewire_id); j++) {
35
            debugf("%02X", onewire_devices[i][j]);
36
        }
37
        uint8_t crc = onewire_crc_rom(onewire_devices[i]);
38
        debugf(" crc: %d\n", crc);
39

  
40
        onewire_matchrom(onewire_devices[i]);
41
        crc = onewire_read_scratchpad(&scratchpad);
42
        debugf("    scratchpad crc: %d\n", crc);
43
        debugf("    temperature: %d.%04d\n", scratchpad.temperature >> 4, 
44
            (scratchpad.temperature & 0xF) * 625 );
45
    }
13 46
}
14 47

  
15 48
int main(void) {

Also available in: Unified diff