Rev 1486 | Rev 1639 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1486 | Rev 1638 | ||
---|---|---|---|
1 | /*############################################################################ |
1 | /*############################################################################ |
2 | ############################################################################*/ |
2 | ############################################################################*/ |
3 | 3 | ||
4 | #ifndef _I2C_MASTER_H |
4 | #ifndef _I2C_MASTER_H |
5 | #define _I2C_MASTER_H |
5 | #define _I2C_MASTER_H |
6 | 6 | ||
7 | //############################################################################ |
7 | //############################################################################ |
8 | 8 | ||
9 | // I2C Konstanten |
9 | // I2C Konstanten |
10 | #define SCL_CLOCK 200000L |
10 | #define SCL_CLOCK 200000L |
11 | #define I2C_TIMEOUT 30000 |
11 | #define I2C_TIMEOUT 30000 |
12 | #define I2C_START 0x08 |
12 | #define I2C_START 0x08 |
13 | #define I2C_REPEATED_START 0x10 |
13 | #define I2C_REPEATED_START 0x10 |
14 | #define I2C_TX_SLA_ACK 0x18 |
14 | #define I2C_TX_SLA_ACK 0x18 |
15 | #define I2C_TX_DATA_ACK 0x28 |
15 | #define I2C_TX_DATA_ACK 0x28 |
16 | #define I2C_RX_SLA_ACK 0x40 |
16 | #define I2C_RX_SLA_ACK 0x40 |
17 | #define I2C_RX_DATA_ACK 0x50 |
17 | #define I2C_RX_DATA_ACK 0x50 |
18 | 18 | ||
19 | //############################################################################ |
19 | //############################################################################ |
20 | 20 | ||
21 | extern volatile unsigned char twi_state; |
21 | extern volatile unsigned char twi_state; |
22 | extern unsigned char motor,MissingMotor; |
22 | extern unsigned char motor,MissingMotor; |
23 | extern unsigned char motorread; |
23 | extern unsigned char motorread; |
24 | 24 | ||
25 | #define MAX_MOTORS 12 |
25 | #define MAX_MOTORS 12 |
26 | #define MOTOR_STATE_PRESENT_MASK 0x80 |
26 | #define MOTOR_STATE_PRESENT_MASK 0x80 |
27 | #define MOTOR_STATE_ERROR_MASK 0x7F |
27 | #define MOTOR_STATE_ERROR_MASK 0x7F |
- | 28 | ||
- | 29 | ||
- | 30 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
|
28 | 31 | ||
29 | typedef struct |
32 | typedef struct |
30 | { |
33 | { |
31 | unsigned char SetPoint; // written by attitude controller |
34 | unsigned char SetPoint; // written by attitude controller |
32 | unsigned char State; // 7 bit for I2C error counter, highest bit indicates if motor is present |
35 | unsigned char State; // 7 bit for I2C error counter, highest bit indicates if motor is present |
33 | unsigned char Current; // in 0.1 A steps, read back from BL |
36 | unsigned char Current; // in 0.1 A steps, read back from BL |
34 | unsigned char MaxPWM; // read back from BL is less than 255 if BL is in current limit |
37 | unsigned char MaxPWM; // read back from BL is less than 255 if BL is in current limit |
- | 38 | signed char Temperature; // old BL-Ctrl will return a 255 here |
|
- | 39 | unsigned char SetPointLowerBits; // for higher Resolution |
|
- | 40 | unsigned char Version; |
|
35 | } __attribute__((packed)) MotorData_t; |
41 | } __attribute__((packed)) MotorData_t; |
36 | 42 | ||
37 | extern MotorData_t Motor[MAX_MOTORS]; |
43 | extern MotorData_t Motor[MAX_MOTORS]; |
38 | 44 | ||
39 | void i2c_reset(void); |
45 | void i2c_reset(void); |
40 | extern void i2c_init (void); // I2C initialisieren |
46 | extern void i2c_init (void); // I2C initialisieren |
41 | extern void i2c_start (void); // Start I2C |
47 | extern void i2c_start (void); // Start I2C |
42 | extern void i2c_stop (void); // Stop I2C |
48 | extern void i2c_stop (void); // Stop I2C |
43 | extern void i2c_write_byte (char byte); // 1 Byte schreiben |
49 | extern void i2c_write_byte (char byte); // 1 Byte schreiben |
44 | extern void i2c_reset(void); |
50 | extern void i2c_reset(void); |
45 | 51 | ||
46 | #endif |
52 | #endif |
47 | 53 |