Subversion Repositories MK3Mag

Rev

Rev 3 | Rev 13 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 7
1
#ifndef _TWI_SLAVE_H_
1
#ifndef _TWI_SLAVE_H_
2
#define _TWI_SLAVE_H_
2
#define _TWI_SLAVE_H_
3
 
3
 
4
#define I2C_SLAVE_ADDRESS 0x50
4
#define I2C_SLAVE_ADDRESS 0x50
5
 
5
 
6
#define I2C_CMD_VERSION   0x01
6
#define I2C_CMD_VERSION   0x01
7
struct str_I2C_Version
7
struct str_I2C_Version
8
{
8
{
9
  unsigned char Hauptversion;
9
  unsigned char Hauptversion;
10
  unsigned char Nebenversion;
10
  unsigned char Nebenversion;
11
  unsigned char Comp;
11
  unsigned char Comp;
12
} ;
12
} ;
13
 
13
 
14
#define I2C_CMD_WRITE_EEPROM   0x0A
14
#define I2C_CMD_WRITE_EEPROM   0x0A
15
#define I2C_CMD_READ_EEPROM    0x0B
15
#define I2C_CMD_READ_EEPROM    0x0B
16
struct str_I2C_EEPROM
16
struct str_I2C_EEPROM
17
{
17
{
18
  unsigned char Adresse;
18
  unsigned char Adresse;
19
  unsigned int Inhalt;
19
  unsigned int Inhalt;
20
} ;
20
} ;
21
 
21
 
22
#define I2C_CMD_READ_MAG     0x02
22
#define I2C_CMD_READ_MAG     0x02
23
struct str_I2C_Mag
23
struct str_I2C_Mag
24
{
24
{
25
  int MagX;
25
  int MagX;
26
  int MagY;
26
  int MagY;
27
  int MagZ;
27
  int MagZ;
28
} ;
28
} ;
29
 
29
 
30
#define I2C_CMD_READ_HEADING     0x03
30
#define I2C_CMD_READ_HEADING     0x03
31
struct str_I2C_WriteNickRoll
31
struct str_I2C_WriteNickRoll
32
{
32
{
33
  int Nick;
33
  int Nick;
34
  int Roll;
34
  int Roll;
35
} ;
35
} ;
-
 
36
 
-
 
37
#define I2C_CMD_WRITE_CAL     0x04
-
 
38
struct str_I2C_WriteCal
-
 
39
{
-
 
40
  unsigned char CalByte;
-
 
41
  unsigned char Dummy1;
-
 
42
  unsigned char Dummy2;
-
 
43
} ;
36
 
44
 
37
struct str_I2C_Heading
45
struct str_I2C_Heading
38
{
46
{
39
  unsigned int Heading;
47
  unsigned int Heading;
40
} ;
48
} ;
41
 
49
 
42
 
50
 
43
extern unsigned char Tx_Idx, Rx_Idx, I2C_Direction;
51
extern unsigned char Tx_Idx, Rx_Idx, I2C_Direction;
44
 
52
 
45
extern struct str_I2C_Heading       I2C_Heading;
53
extern struct str_I2C_Heading       I2C_Heading;
46
extern struct str_I2C_WriteNickRoll I2C_WriteNickRoll;
54
extern struct str_I2C_WriteNickRoll I2C_WriteNickRoll;
47
extern struct str_I2C_Mag           I2C_Mag;
55
extern struct str_I2C_Mag           I2C_Mag;
48
extern struct str_I2C_EEPROM        I2C_ReadEEPROM, I2C_WriteEEPROM;
56
extern struct str_I2C_EEPROM        I2C_ReadEEPROM, I2C_WriteEEPROM;
49
extern struct str_I2C_Version       I2C_Version;
57
extern struct str_I2C_Version       I2C_Version;
-
 
58
extern struct str_I2C_WriteCal      I2C_WriteCal;
50
 
59
 
51
 
60
 
52
extern void InitIC2_Slave (void);
61
extern void InitIC2_Slave (void);
53
 
62
 
54
#define TWI_BUS_ERR_1   0x00
63
#define TWI_BUS_ERR_1   0x00
55
#define TWI_BUS_ERR_2   0xF8
64
#define TWI_BUS_ERR_2   0xF8
56
 
65
 
57
// Status Slave RX Mode
66
// Status Slave RX Mode
58
#define SR_SLA_ACK      0x60
67
#define SR_SLA_ACK      0x60
59
#define SR_LOST_ACK     0x68
68
#define SR_LOST_ACK     0x68
60
#define SR_GEN_CALL_ACK 0x70
69
#define SR_GEN_CALL_ACK 0x70
61
#define GEN_LOST_ACK    0x78
70
#define GEN_LOST_ACK    0x78
62
#define SR_PREV_ACK     0x80
71
#define SR_PREV_ACK     0x80
63
#define SR_PREV_NACK    0x88
72
#define SR_PREV_NACK    0x88
64
#define GEN_PREV_ACK    0x90
73
#define GEN_PREV_ACK    0x90
65
#define GEN_PREV_NACK   0x98
74
#define GEN_PREV_NACK   0x98
66
#define STOP_CONDITION  0xA0
75
#define STOP_CONDITION  0xA0
67
#define REPEATED_START  0xA0
76
#define REPEATED_START  0xA0
68
 
77
 
69
// Status Slave TX mode
78
// Status Slave TX mode
70
#define SW_SLA_ACK      0xA8
79
#define SW_SLA_ACK      0xA8
71
#define SW_LOST_ACK     0xB0
80
#define SW_LOST_ACK     0xB0
72
#define SW_DATA_ACK     0xB8
81
#define SW_DATA_ACK     0xB8
73
#define SW_DATA_NACK    0xC0
82
#define SW_DATA_NACK    0xC0
74
#define SW_LAST_ACK     0xC8
83
#define SW_LAST_ACK     0xC8
75
 
84
 
76
#endif
85
#endif
77
 
86
 
78
 
87