Rev 1651 | Rev 1662 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*############################################################################ |
2 | ############################################################################*/ |
||
3 | |||
4 | #ifndef _I2C_MASTER_H |
||
5 | #define _I2C_MASTER_H |
||
6 | |||
7 | //############################################################################ |
||
8 | |||
9 | // I2C Konstanten |
||
10 | #define SCL_CLOCK 200000L |
||
11 | #define I2C_TIMEOUT 30000 |
||
12 | #define I2C_START 0x08 |
||
13 | #define I2C_REPEATED_START 0x10 |
||
14 | #define I2C_TX_SLA_ACK 0x18 |
||
15 | #define I2C_TX_DATA_ACK 0x28 |
||
16 | #define I2C_RX_SLA_ACK 0x40 |
||
17 | #define I2C_RX_DATA_ACK 0x50 |
||
18 | |||
19 | //############################################################################ |
||
20 | |||
918 | hbuss | 21 | extern volatile unsigned char twi_state; |
1650 | killagreg | 22 | extern volatile unsigned char motor,MissingMotor; |
23 | extern volatile unsigned char motorread; |
||
1 | ingob | 24 | |
1479 | killagreg | 25 | #define MAX_MOTORS 12 |
1638 | holgerb | 26 | #define MOTOR_STATE_PRESENT_MASK 0x80 |
27 | #define MOTOR_STATE_ERROR_MASK 0x7F |
||
1479 | killagreg | 28 | |
1638 | holgerb | 29 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
30 | |||
1648 | killagreg | 31 | #define BLFLAG_READ_VERSION 0x01 |
32 | #define BLFLAG_SEND_CONFIG 0x02 |
||
33 | #define BLFLAG_TX_COMPLETE 0x04 |
||
34 | |||
1650 | killagreg | 35 | extern volatile unsigned char BLFlags; |
1648 | killagreg | 36 | |
1479 | killagreg | 37 | typedef struct |
38 | { |
||
1486 | killagreg | 39 | unsigned char SetPoint; // written by attitude controller |
40 | unsigned char State; // 7 bit for I2C error counter, highest bit indicates if motor is present |
||
41 | unsigned char Current; // in 0.1 A steps, read back from BL |
||
42 | unsigned char MaxPWM; // read back from BL is less than 255 if BL is in current limit |
||
1648 | killagreg | 43 | unsigned char Temperature; // old BL-Ctrl will return a 255 here |
1638 | holgerb | 44 | unsigned char SetPointLowerBits; // for higher Resolution |
45 | unsigned char Version; |
||
1479 | killagreg | 46 | } __attribute__((packed)) MotorData_t; |
47 | |||
48 | extern MotorData_t Motor[MAX_MOTORS]; |
||
49 | |||
304 | ingob | 50 | void i2c_reset(void); |
395 | hbuss | 51 | extern void i2c_init (void); // I2C initialisieren |
1209 | hbuss | 52 | extern void i2c_write_byte (char byte); // 1 Byte schreiben |
395 | hbuss | 53 | extern void i2c_reset(void); |
1648 | killagreg | 54 | extern void I2C_SendBLConfig(void); |
1 | ingob | 55 | |
1651 | killagreg | 56 | #define I2C_Start() {BLFlags &= ~BLFLAG_TX_COMPLETE; TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE);} |
1639 | holgerb | 57 | #define I2C_Stop() {TWCR = (1<<TWEN) | (1<<TWSTO) | (1<<TWINT);} |
58 | #define I2C_ReceiveByte() {TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA);} |
||
59 | #define I2C_ReceiveLastByte() {TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);} |
||
60 | #define i2c_write_byte(byte) {TWSR = 0x00; TWDR = byte; TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);} |
||
61 | |||
1 | ingob | 62 | #endif |