-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm_bus.h
59 lines (51 loc) · 1.48 KB
/
m_bus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// -----------------------------------------------------------------------------
// M2 data bus subsystem
// version: 2.0
// date: June 30, 2011
// author: J. Fiene
// -----------------------------------------------------------------------------
#ifndef m_bus__
#define m_bus__
#include "m_general.h"
#include <util/twi.h>
#define MAX_WAIT 1000
#define INTERPACKET 10
#define READ 1
#define WRITE 0
// -----------------------------------------------------------------------------
// Public functions:
// -----------------------------------------------------------------------------
void m_bus_init(void);
// FUNCTIONALITY:
// initialize the M2 data bus, which uses pins D0-D2 and is available through the
// 5-pin end header. When new data is available from a slave, the INT2_vect interrupt
// will be triggered, and you must act accordingly!
//
// TAKES:
// nothing
//
// RETURNS:
// nothing
unsigned char m_read_register(unsigned char addr, unsigned char reg);
// FUNCTIONALITY:
// sends [START + W] [register address] [STOP] [START + R]
//
// TAKES:
// addr - I2C slave address
// reg - register address
//
// RETURNS:
// register value
unsigned char m_write_register(unsigned char addr, unsigned char reg, unsigned char value);
// FUNCTIONALITY:
// sends [START + W] [register address] [value] [STOP]
//
// TAKES:
// addr - I2C slave address
// reg - register address
// value - value to place in register
//
// RETURNS:
// 1 - success
// 0 - communication error
#endif