I just started playing with TI’s MSP430 LaunchPad (MSP-EXP430G2) a few weeks ago and have found it surprisingly capable so far. But having to remember all those register names is not an easy task, especially if you do not use it often. So, inspired by this article (Header file brings Arduino sketches to the TI Launchpad) on Hack A Day, I decided to write a few functions that can simplify some of the more mundane tasks.
Here are some of the most used functions I have come up so far. Even though these functions were written specifically for the MSP430G2231 chip I have at hand, they can work with any MSP430G2 value line chips that support the specified functionality.
Here is the code listing for MSP430G2231Library.h (compiled using TI’s Code Composer Studio 5.1):
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165 |
|
The code above includes DCO/Crystal initialization routines. It also includes a few Arduino like functions (pinMode, digitalRead and digitalWrite). But I decided to go with the Port.Bit format instead of just a pin number since the Port.Bit information is printed on the launchpad itself and it is easier to reference that way. Finally, I included a couple of ADC routines that work with both the internal and external voltage references. The ADC routines shown above handles only one channel at a time for the time being.
I am planning on expanding this code to include more features in the near future.