-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLegendI2C.h
77 lines (59 loc) · 1.68 KB
/
LegendI2C.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* LegendI2C.h
*
* Created on: Dec 20, 2018
* Author: AQaut
*/
#ifndef LEGENDI2C_H_
#define LEGENDI2C_H_
#include <msp430.h>
#include "MDtypes.h"
#define SELF_I2C_ADDRESS 0x48
#define I2C_CHECKSUM 'A'
#define PARITY 0x1
#define MD_OK 0x2
#define MD_NOK 0x4
#define SHUTDOWN 0x8
#define STARTUP 0x10
typedef struct I2Cmessage {
unsigned char checksum;
unsigned char data;
unsigned char flags;
} message_t;
/**** I2C Message Specification ****
*
* An I2C message sent to or from the motor driver (hereafter "a message")
* shall be three bytes long.
*
* The first byte will serve as a checksum.
* The checksum will always be the ASCII character 'A'. Messages without
* a correct checksum may be disregarded.
*
* The second byte will contain speed data.
* Motor speed will be encoded as an unsigned 8 bit integer. Messages
* sent by the motor driver will contain the actual speed. Messages sent
* to the motor driver should contain the desired speed.
*
* The bits of the third byte will be flags with the following meanings:
* bit 0 - parity
* bit 1 - MD_OK (Asserted by Motor Driver if OK)
* bit 2 - MD_NOK (Asserted by Motor Driver if in error state)
* bit 3 - Request Motor Shutdown
* bit 4 - Request Motor Startup
* bit 5 - Unused
* bit 6 - Unused
* bit 7 - Unused
*
********
*/
volatile unsigned char RXData;
volatile unsigned char TXData;
volatile unsigned char RXCounter;
volatile unsigned char TXCounter;
volatile message_t incoming;
volatile message_t outgoing;
volatile static MDstate_t* boardState;
void setupI2C(MDstate_t* state);
void processIncomingByte(unsigned char byte);
unsigned char generateOutgoingByte();
#endif /* LEGENDI2C_H_ */