summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorja Martinez2016-09-10 15:44:27 -0500
committerBorja Martinez2016-09-10 15:44:27 -0500
commit7d6aef7ae1f9f7c1428a0c5a885d427e99b20189 (patch)
tree5405ee83d9dbaff8e484458e325943499962bc69
parente310e04250e6d3b0846dd3839d0113ce09d8cb9d (diff)
downloadi3-mote-7d6aef7ae1f9f7c1428a0c5a885d427e99b20189.tar.gz
i3-mote-7d6aef7ae1f9f7c1428a0c5a885d427e99b20189.tar.xz
i3-mote-7d6aef7ae1f9f7c1428a0c5a885d427e99b20189.zip
Created Test MSP432 I2C Sensors
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/i3mote.h28
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/main.c14
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_Blink_SysTick/i3mote.h46
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h46
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_DebugUART_EchoPC/i3mote.h36
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_M24xx256/i3mote.h41
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.c250
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.h50
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/i3mote.h53
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/main.c266
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/msp432p401r.cmd84
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/startup_msp432p401r_ccs.c255
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/system_msp432p401r.c434
13 files changed, 1578 insertions, 25 deletions
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/i3mote.h
index 31196c6..92b71fb 100644
--- a/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/i3mote.h
+++ b/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/i3mote.h
@@ -1,10 +1,9 @@
1/* Rev.B */ 1/* HID Rev.B */
2#define HID_PORT GPIO_PORT_P6 2#define HID_PORT GPIO_PORT_P6
3#define LEDR GPIO_PIN2 3#define LEDR GPIO_PIN2
4#define LEDG GPIO_PIN3 4#define LEDG GPIO_PIN3
5#define BUTTON GPIO_PIN1 5#define BUTTON GPIO_PIN1
6 6
7
8/* Rev.A 7/* Rev.A
9#define LED_PORT GPIO_PORT_P8 8#define LED_PORT GPIO_PORT_P8
10#define LEDR GPIO_PIN5 9#define LEDR GPIO_PIN5
@@ -13,8 +12,10 @@
13*/ 12*/
14 13
15 14
16/* On Board EEPROM 25xx256*/ 15/* Power Control */
17#define EEPROM_SLAVE_ADDRESS 0x50 16#define CTL_PWR_PORT GPIO_PORT_P2
17#define GPS_PWR_nEN_PIN GPIO_PIN4
18#define SSM_PWR_nEN_PIN GPIO_PIN5
18 19
19 20
20/* Debg UART */ 21/* Debg UART */
@@ -31,3 +32,22 @@
31#define FLASH_SPI_MOSI_PIN GPIO_PIN3 32#define FLASH_SPI_MOSI_PIN GPIO_PIN3
32 33
33 34
35/* On Board EEPROM 25xx256*/
36#define EEPROM_SLAVE_ADDRESS 0x50
37
38
39/* On Board Sensors */
40#define IN219
41#define OPT3001
42#define HDC1080
43#define BMP280
44#define MPU9250
45#define TMP007
46
47#define Board_HDC1080_ADDR 0x40
48#define Board_INA219_ADDR 0x41
49#define Board_TMP007_ADDR 0x44
50#define Board_OPT3001_ADDR 0x45
51#define Board_MPU9250_ADDR 0x68
52#define Board_BMP280_ADDR 0x77
53
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/main.c b/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/main.c
index 0743654..cbd25b1 100644
--- a/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/main.c
+++ b/Basic-Test-Package/MSP432/Test_MSP432_3wSPI_M25P40/main.c
@@ -67,16 +67,16 @@ int main(void)
67 MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); 67 MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
68 68
69 69
70 /* LEDS as output */ 70 /* LEDS as output */
71 MAP_GPIO_setAsOutputPin(HID_PORT,LEDR|LEDG); 71 MAP_GPIO_setAsOutputPin(HID_PORT,LEDR|LEDG);
72 MAP_GPIO_setOutputLowOnPin(HID_PORT,LEDR|LEDG); 72 MAP_GPIO_setOutputLowOnPin(HID_PORT,LEDR|LEDG);
73 73
74 74
75 /* CS Configuring P3.0 as output */ 75 /* CS Configuring P3.0 as output */
76 MAP_GPIO_setAsOutputPin(FLASH_SPI_PORT, FLASH_SPI_NCS_PIN); 76 MAP_GPIO_setAsOutputPin(FLASH_SPI_PORT, FLASH_SPI_NCS_PIN);
77 MAP_GPIO_setOutputHighOnPin(FLASH_SPI_PORT, FLASH_SPI_NCS_PIN); 77 MAP_GPIO_setOutputHighOnPin(FLASH_SPI_PORT, FLASH_SPI_NCS_PIN);
78 78
79 /* SPI */ 79 /* SPI */
80 GPIO_setAsPeripheralModuleFunctionInputPin(FLASH_SPI_PORT, 80 GPIO_setAsPeripheralModuleFunctionInputPin(FLASH_SPI_PORT,
81 FLASH_SPI_CLK_PIN | FLASH_SPI_MISO_PIN | FLASH_SPI_MOSI_PIN, GPIO_PRIMARY_MODULE_FUNCTION); 81 FLASH_SPI_CLK_PIN | FLASH_SPI_MISO_PIN | FLASH_SPI_MOSI_PIN, GPIO_PRIMARY_MODULE_FUNCTION);
82 82
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_Blink_SysTick/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_Blink_SysTick/i3mote.h
index fc06eaa..92b71fb 100644
--- a/Basic-Test-Package/MSP432/Test_MSP432_Blink_SysTick/i3mote.h
+++ b/Basic-Test-Package/MSP432/Test_MSP432_Blink_SysTick/i3mote.h
@@ -1,15 +1,53 @@
1 1/* HID Rev.B */
2
3/* Rev.B */
4#define HID_PORT GPIO_PORT_P6 2#define HID_PORT GPIO_PORT_P6
5#define LEDR GPIO_PIN2 3#define LEDR GPIO_PIN2
6#define LEDG GPIO_PIN3 4#define LEDG GPIO_PIN3
7#define BUTTON GPIO_PIN1 5#define BUTTON GPIO_PIN1
8 6
9
10/* Rev.A 7/* Rev.A
11#define LED_PORT GPIO_PORT_P8 8#define LED_PORT GPIO_PORT_P8
12#define LEDR GPIO_PIN5 9#define LEDR GPIO_PIN5
13#define LEDG GPIO_PIN6 10#define LEDG GPIO_PIN6
14#define BUTTON GPIO_PIN7 11#define BUTTON GPIO_PIN7
15*/ 12*/
13
14
15/* Power Control */
16#define CTL_PWR_PORT GPIO_PORT_P2
17#define GPS_PWR_nEN_PIN GPIO_PIN4
18#define SSM_PWR_nEN_PIN GPIO_PIN5
19
20
21/* Debg UART */
22#define UART_BAUD_115200
23#define UART_PORT GPIO_PORT_P1
24#define UART_TX_PIN GPIO_PIN3
25#define UART_RX_PIN GPIO_PIN2
26
27/* Flash SPI */
28#define FLASH_SPI_PORT GPIO_PORT_P3
29#define FLASH_SPI_NCS_PIN GPIO_PIN0
30#define FLASH_SPI_CLK_PIN GPIO_PIN1
31#define FLASH_SPI_MISO_PIN GPIO_PIN2
32#define FLASH_SPI_MOSI_PIN GPIO_PIN3
33
34
35/* On Board EEPROM 25xx256*/
36#define EEPROM_SLAVE_ADDRESS 0x50
37
38
39/* On Board Sensors */
40#define IN219
41#define OPT3001
42#define HDC1080
43#define BMP280
44#define MPU9250
45#define TMP007
46
47#define Board_HDC1080_ADDR 0x40
48#define Board_INA219_ADDR 0x41
49#define Board_TMP007_ADDR 0x44
50#define Board_OPT3001_ADDR 0x45
51#define Board_MPU9250_ADDR 0x68
52#define Board_BMP280_ADDR 0x77
53
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h
index fc06eaa..92b71fb 100644
--- a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h
+++ b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h
@@ -1,15 +1,53 @@
1 1/* HID Rev.B */
2
3/* Rev.B */
4#define HID_PORT GPIO_PORT_P6 2#define HID_PORT GPIO_PORT_P6
5#define LEDR GPIO_PIN2 3#define LEDR GPIO_PIN2
6#define LEDG GPIO_PIN3 4#define LEDG GPIO_PIN3
7#define BUTTON GPIO_PIN1 5#define BUTTON GPIO_PIN1
8 6
9
10/* Rev.A 7/* Rev.A
11#define LED_PORT GPIO_PORT_P8 8#define LED_PORT GPIO_PORT_P8
12#define LEDR GPIO_PIN5 9#define LEDR GPIO_PIN5
13#define LEDG GPIO_PIN6 10#define LEDG GPIO_PIN6
14#define BUTTON GPIO_PIN7 11#define BUTTON GPIO_PIN7
15*/ 12*/
13
14
15/* Power Control */
16#define CTL_PWR_PORT GPIO_PORT_P2
17#define GPS_PWR_nEN_PIN GPIO_PIN4
18#define SSM_PWR_nEN_PIN GPIO_PIN5
19
20
21/* Debg UART */
22#define UART_BAUD_115200
23#define UART_PORT GPIO_PORT_P1
24#define UART_TX_PIN GPIO_PIN3
25#define UART_RX_PIN GPIO_PIN2
26
27/* Flash SPI */
28#define FLASH_SPI_PORT GPIO_PORT_P3
29#define FLASH_SPI_NCS_PIN GPIO_PIN0
30#define FLASH_SPI_CLK_PIN GPIO_PIN1
31#define FLASH_SPI_MISO_PIN GPIO_PIN2
32#define FLASH_SPI_MOSI_PIN GPIO_PIN3
33
34
35/* On Board EEPROM 25xx256*/
36#define EEPROM_SLAVE_ADDRESS 0x50
37
38
39/* On Board Sensors */
40#define IN219
41#define OPT3001
42#define HDC1080
43#define BMP280
44#define MPU9250
45#define TMP007
46
47#define Board_HDC1080_ADDR 0x40
48#define Board_INA219_ADDR 0x41
49#define Board_TMP007_ADDR 0x44
50#define Board_OPT3001_ADDR 0x45
51#define Board_MPU9250_ADDR 0x68
52#define Board_BMP280_ADDR 0x77
53
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_DebugUART_EchoPC/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_DebugUART_EchoPC/i3mote.h
index 68dedce..92b71fb 100644
--- a/Basic-Test-Package/MSP432/Test_MSP432_DebugUART_EchoPC/i3mote.h
+++ b/Basic-Test-Package/MSP432/Test_MSP432_DebugUART_EchoPC/i3mote.h
@@ -1,10 +1,9 @@
1/* Rev.B */ 1/* HID Rev.B */
2#define HID_PORT GPIO_PORT_P6 2#define HID_PORT GPIO_PORT_P6
3#define LEDR GPIO_PIN2 3#define LEDR GPIO_PIN2
4#define LEDG GPIO_PIN3 4#define LEDG GPIO_PIN3
5#define BUTTON GPIO_PIN1 5#define BUTTON GPIO_PIN1
6 6
7
8/* Rev.A 7/* Rev.A
9#define LED_PORT GPIO_PORT_P8 8#define LED_PORT GPIO_PORT_P8
10#define LEDR GPIO_PIN5 9#define LEDR GPIO_PIN5
@@ -13,8 +12,10 @@
13*/ 12*/
14 13
15 14
16/* On Board EEPROM 25xx256*/ 15/* Power Control */
17#define EEPROM_SLAVE_ADDRESS 0x50 16#define CTL_PWR_PORT GPIO_PORT_P2
17#define GPS_PWR_nEN_PIN GPIO_PIN4
18#define SSM_PWR_nEN_PIN GPIO_PIN5
18 19
19 20
20/* Debg UART */ 21/* Debg UART */
@@ -23,3 +24,30 @@
23#define UART_TX_PIN GPIO_PIN3 24#define UART_TX_PIN GPIO_PIN3
24#define UART_RX_PIN GPIO_PIN2 25#define UART_RX_PIN GPIO_PIN2
25 26
27/* Flash SPI */
28#define FLASH_SPI_PORT GPIO_PORT_P3
29#define FLASH_SPI_NCS_PIN GPIO_PIN0
30#define FLASH_SPI_CLK_PIN GPIO_PIN1
31#define FLASH_SPI_MISO_PIN GPIO_PIN2
32#define FLASH_SPI_MOSI_PIN GPIO_PIN3
33
34
35/* On Board EEPROM 25xx256*/
36#define EEPROM_SLAVE_ADDRESS 0x50
37
38
39/* On Board Sensors */
40#define IN219
41#define OPT3001
42#define HDC1080
43#define BMP280
44#define MPU9250
45#define TMP007
46
47#define Board_HDC1080_ADDR 0x40
48#define Board_INA219_ADDR 0x41
49#define Board_TMP007_ADDR 0x44
50#define Board_OPT3001_ADDR 0x45
51#define Board_MPU9250_ADDR 0x68
52#define Board_BMP280_ADDR 0x77
53
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_M24xx256/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_I2C_M24xx256/i3mote.h
index 750f90e..92b71fb 100644
--- a/Basic-Test-Package/MSP432/Test_MSP432_I2C_M24xx256/i3mote.h
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_M24xx256/i3mote.h
@@ -1,10 +1,9 @@
1/* Rev.B */ 1/* HID Rev.B */
2#define HID_PORT GPIO_PORT_P6 2#define HID_PORT GPIO_PORT_P6
3#define LEDR GPIO_PIN2 3#define LEDR GPIO_PIN2
4#define LEDG GPIO_PIN3 4#define LEDG GPIO_PIN3
5#define BUTTON GPIO_PIN1 5#define BUTTON GPIO_PIN1
6 6
7
8/* Rev.A 7/* Rev.A
9#define LED_PORT GPIO_PORT_P8 8#define LED_PORT GPIO_PORT_P8
10#define LEDR GPIO_PIN5 9#define LEDR GPIO_PIN5
@@ -13,4 +12,42 @@
13*/ 12*/
14 13
15 14
15/* Power Control */
16#define CTL_PWR_PORT GPIO_PORT_P2
17#define GPS_PWR_nEN_PIN GPIO_PIN4
18#define SSM_PWR_nEN_PIN GPIO_PIN5
19
20
21/* Debg UART */
22#define UART_BAUD_115200
23#define UART_PORT GPIO_PORT_P1
24#define UART_TX_PIN GPIO_PIN3
25#define UART_RX_PIN GPIO_PIN2
26
27/* Flash SPI */
28#define FLASH_SPI_PORT GPIO_PORT_P3
29#define FLASH_SPI_NCS_PIN GPIO_PIN0
30#define FLASH_SPI_CLK_PIN GPIO_PIN1
31#define FLASH_SPI_MISO_PIN GPIO_PIN2
32#define FLASH_SPI_MOSI_PIN GPIO_PIN3
33
34
35/* On Board EEPROM 25xx256*/
16#define EEPROM_SLAVE_ADDRESS 0x50 36#define EEPROM_SLAVE_ADDRESS 0x50
37
38
39/* On Board Sensors */
40#define IN219
41#define OPT3001
42#define HDC1080
43#define BMP280
44#define MPU9250
45#define TMP007
46
47#define Board_HDC1080_ADDR 0x40
48#define Board_INA219_ADDR 0x41
49#define Board_TMP007_ADDR 0x44
50#define Board_OPT3001_ADDR 0x45
51#define Board_MPU9250_ADDR 0x68
52#define Board_BMP280_ADDR 0x77
53
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.c b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.c
new file mode 100644
index 0000000..1ee90a5
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.c
@@ -0,0 +1,250 @@
1/* --COPYRIGHT--,BSD
2 * Copyright (c) 2015, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32//****************************************************************************
33//
34// HAL_I2C.c - Hardware abstraction layer for I2C with MSP432P401R
35//
36//****************************************************************************
37
38#include <driverlib.h>
39#include <HAL_I2C.h>
40
41
42/* I2C Master Configuration Parameter */
43const eUSCI_I2C_MasterConfig i2cConfig =
44{
45 EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
46 12000000, // SMCLK = 12MHz
47 EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 100khz
48 0, // No byte counter threshold
49 EUSCI_B_I2C_NO_AUTO_STOP // No Autostop
50};
51
52void Init_I2C_GPIO()
53{
54 /* Select I2C function for I2C_SCL(P3.7) */
55 GPIO_setAsPeripheralModuleFunctionOutputPin(
56 GPIO_PORT_P3,
57 GPIO_PIN7,
58 GPIO_PRIMARY_MODULE_FUNCTION);
59
60 /* Select I2C function for I2C_SDA(P3.6) */
61 GPIO_setAsPeripheralModuleFunctionOutputPin(
62 GPIO_PORT_P3,
63 GPIO_PIN6,
64 GPIO_PRIMARY_MODULE_FUNCTION);
65}
66
67
68/***************************************************************************//**
69 * @brief Configures I2C
70 * @param none
71 * @return none
72 ******************************************************************************/
73
74void I2C_init(void)
75{
76 /* Initialize USCI_B0 and I2C Master to communicate with slave devices*/
77 I2C_initMaster(EUSCI_B2_BASE, &i2cConfig);
78 //I2C_initMaster(EUSCI_B2_BASE, &i2cConfig);
79
80 /* Disable I2C module to make changes */
81 I2C_disableModule(EUSCI_B2_BASE);
82 //I2C_disableModule(EUSCI_B2_BASE);
83
84 /* Enable I2C Module to start operations */
85 I2C_enableModule(EUSCI_B2_BASE);
86 //I2C_enableModule(EUSCI_B2_BASE);
87
88 return;
89}
90
91
92/***************************************************************************//**
93 * @brief Reads data from the sensor
94 * @param writeByte Address of register to read from
95 * @return Register contents
96 ******************************************************************************/
97
98unsigned short I2C_read16(unsigned char writeByte)
99{
100 volatile int val = 0;
101 volatile int valScratch = 0;
102
103 /* Set master to transmit mode PL */
104 I2C_setMode(EUSCI_B2_BASE,
105 EUSCI_B_I2C_TRANSMIT_MODE);
106
107 /* Clear any existing interrupt flag PL */
108 I2C_clearInterruptFlag(EUSCI_B2_BASE,
109 EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
110
111 /* Wait until ready to write PL */
112 while (I2C_isBusBusy(EUSCI_B2_BASE));
113
114 /* Initiate start and send first character */
115 I2C_masterSendMultiByteStart(EUSCI_B2_BASE, writeByte);
116
117 /* Wait for TX to finish */
118 while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,
119 EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));
120
121 /* Initiate stop only */
122 I2C_masterSendMultiByteStop(EUSCI_B2_BASE);
123
124 /* Wait for Stop to finish */
125 while(!I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_STOP_INTERRUPT));
126
127 /*
128 * Generate Start condition and set it to receive mode.
129 * This sends out the slave address and continues to read
130 * until you issue a STOP
131 */
132 I2C_masterReceiveStart(EUSCI_B2_BASE);
133
134 /* Wait for RX buffer to fill */
135 while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_RECEIVE_INTERRUPT0)));
136
137 /* Read from I2C RX register */
138 val = I2C_masterReceiveMultiByteNext(EUSCI_B2_BASE);
139
140 /* Receive second byte then send STOP condition */
141 valScratch = I2C_masterReceiveMultiByteFinish(EUSCI_B2_BASE);
142
143 /* Shift val to top MSB */
144 val = (val << 8);
145 /* Read from I2C RX Register and write to LSB of val */
146 val |= valScratch;
147
148 /* Return temperature value */
149 return (int16_t)val;
150}
151
152
153
154
155unsigned char I2C_read8(unsigned short addr)
156{
157 volatile int val = 0;
158 volatile int valScratch = 0;
159
160 /* Set master to transmit mode PL */
161 I2C_setMode(EUSCI_B2_BASE,
162 EUSCI_B_I2C_TRANSMIT_MODE);
163
164 /* Clear any existing interrupt flag PL */
165 I2C_clearInterruptFlag(EUSCI_B2_BASE,
166 EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
167
168 /* Wait until ready to write PL */
169 while (I2C_isBusBusy(EUSCI_B2_BASE));
170
171 /* Initiate start and send first character */
172 I2C_masterSendMultiByteStart(EUSCI_B2_BASE,addr&0x00FF);
173 /* Wait for TX to finish */
174 while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));
175
176 /* Send Next Character */
177 //I2C_masterSendMultiByteNext(EUSCI_B2_BASE,(unsigned char)(addr&0x00FF));
178 /* Wait for TX to finish */
179 //while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));
180
181 /* Initiate stop only */
182 I2C_masterSendMultiByteStop(EUSCI_B2_BASE);
183 /* Wait for Stop to finish */
184 while(!I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_STOP_INTERRUPT));
185
186 /*
187 * Generate Start condition and set it to receive mode.
188 * This sends out the slave address and continues to read until you issue a STOP
189 */
190
191 I2C_setMode(EUSCI_B2_BASE,EUSCI_B_I2C_RECEIVE_MODE);
192 while (I2C_isBusBusy(EUSCI_B2_BASE));
193
194 val=I2C_masterReceiveSingleByte(EUSCI_B2_BASE);
195
196 /* Return temperature value */
197 return val;
198}
199
200
201
202/***************************************************************************//**
203 * @brief Writes data to the sensor
204 * @param pointer Address of register you want to modify
205 * @param writeByte Data to be written to the specified register
206 * @return none
207 ******************************************************************************/
208
209void I2C_write16(unsigned short pointer, unsigned short writeByte)
210{
211 /* Set master to transmit mode PL */
212 I2C_setMode(EUSCI_B2_BASE,
213 EUSCI_B_I2C_TRANSMIT_MODE);
214
215 /* Clear any existing interrupt flag PL */
216 I2C_clearInterruptFlag(EUSCI_B2_BASE,
217 EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
218
219 /* Wait until ready to write PL */
220 while (I2C_isBusBusy(EUSCI_B2_BASE));
221
222 /* Initiate start and send first character */
223 I2C_masterSendMultiByteStart(EUSCI_B2_BASE,(unsigned char)(pointer>>8));
224 while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));
225
226
227 I2C_masterSendMultiByteNext(EUSCI_B2_BASE,(unsigned char)(pointer&0x00FF));
228 while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));
229
230
231 I2C_masterSendMultiByteFinish(EUSCI_B2_BASE,
232 (unsigned char)(writeByte&0xFF));
233 while(!(I2C_getInterruptStatus(EUSCI_B2_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0)));
234
235 while (I2C_isBusBusy(EUSCI_B2_BASE));
236
237}
238
239
240void I2C_setslave(unsigned int slaveAdr)
241{
242 /* Specify slave address for I2C */
243 I2C_setSlaveAddress(EUSCI_B2_BASE,slaveAdr);
244
245 /* Enable and clear the interrupt flag */
246 I2C_clearInterruptFlag(EUSCI_B2_BASE,
247 EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_RECEIVE_INTERRUPT0);
248
249 return;
250}
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.h b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.h
new file mode 100644
index 0000000..d8bf2c0
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/HAL_I2C.h
@@ -0,0 +1,50 @@
1/* --COPYRIGHT--,BSD
2 * Copyright (c) 2015, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32//****************************************************************************
33//
34// HAL_I2C.h - Prototypes of hardware abstraction layer for I2C between
35// MSP432P401R and OPT3001
36//
37//****************************************************************************
38
39#ifndef __HAL_I2C_H_
40#define __HAL_I2C_H_
41
42void Init_I2C_GPIO(void);
43void I2C_init(void);
44unsigned short I2C_read16(unsigned char);
45unsigned char I2C_read8(unsigned short writeByte);
46void I2C_write16(unsigned short pointer, unsigned short writeByte);
47void I2C_setslave(unsigned int slaveAdr);
48
49
50#endif /* __HAL_I2C_H_ */
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/i3mote.h
new file mode 100644
index 0000000..92b71fb
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/i3mote.h
@@ -0,0 +1,53 @@
1/* HID Rev.B */
2#define HID_PORT GPIO_PORT_P6
3#define LEDR GPIO_PIN2
4#define LEDG GPIO_PIN3
5#define BUTTON GPIO_PIN1
6
7/* Rev.A
8#define LED_PORT GPIO_PORT_P8
9#define LEDR GPIO_PIN5
10#define LEDG GPIO_PIN6
11#define BUTTON GPIO_PIN7
12*/
13
14
15/* Power Control */
16#define CTL_PWR_PORT GPIO_PORT_P2
17#define GPS_PWR_nEN_PIN GPIO_PIN4
18#define SSM_PWR_nEN_PIN GPIO_PIN5
19
20
21/* Debg UART */
22#define UART_BAUD_115200
23#define UART_PORT GPIO_PORT_P1
24#define UART_TX_PIN GPIO_PIN3
25#define UART_RX_PIN GPIO_PIN2
26
27/* Flash SPI */
28#define FLASH_SPI_PORT GPIO_PORT_P3
29#define FLASH_SPI_NCS_PIN GPIO_PIN0
30#define FLASH_SPI_CLK_PIN GPIO_PIN1
31#define FLASH_SPI_MISO_PIN GPIO_PIN2
32#define FLASH_SPI_MOSI_PIN GPIO_PIN3
33
34
35/* On Board EEPROM 25xx256*/
36#define EEPROM_SLAVE_ADDRESS 0x50
37
38
39/* On Board Sensors */
40#define IN219
41#define OPT3001
42#define HDC1080
43#define BMP280
44#define MPU9250
45#define TMP007
46
47#define Board_HDC1080_ADDR 0x40
48#define Board_INA219_ADDR 0x41
49#define Board_TMP007_ADDR 0x44
50#define Board_OPT3001_ADDR 0x45
51#define Board_MPU9250_ADDR 0x68
52#define Board_BMP280_ADDR 0x77
53
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/main.c b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/main.c
new file mode 100644
index 0000000..a112ea0
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/main.c
@@ -0,0 +1,266 @@
1//****************************************************************************
2//
3//****************************************************************************
4#include "i3mote.h"
5#include "HAL_I2C.h"
6
7/* DriverLib Includes */
8#include <driverlib.h>
9
10/* Standard Includes */
11#include <stdlib.h>
12#include <stdio.h>
13
14
15/* UART Configuration Parameter. These are the configuration parameters to
16 * make the eUSCI A UART module to operate with a 9600 baud rate.
17 * These values were calculated using the online calculator that TI provides at:
18 * http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
19 */
20#ifdef UART_BAUD_9600
21 const eUSCI_UART_Config uartConfig =
22 {
23 EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
24 78, // BRDIV = 78
25 2, // UCxBRF = 2
26 0, // UCxBRS = 0
27 EUSCI_A_UART_NO_PARITY, // No Parity
28 EUSCI_A_UART_LSB_FIRST, // LSB First
29 EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
30 EUSCI_A_UART_MODE, // UART mode
31 EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling
32 };
33#endif
34
35#ifdef UART_BAUD_115200
36 const eUSCI_UART_Config uartConfig =
37 {
38 EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
39 6, // BRDIV = 6
40 8, // UCxBRF = 8
41 32, // UCxBRS = 32
42 EUSCI_A_UART_NO_PARITY, // No Parity
43 EUSCI_A_UART_LSB_FIRST, // LSB First
44 EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
45 EUSCI_A_UART_MODE, // UART mode
46 EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling
47 };
48#endif
49
50#define SYSFREQ 12000000
51
52/* External UART */
53#undef UART
54
55/*
56 * Global Variables
57 */
58#define BUFF_SIZE 4
59char buffer[BUFF_SIZE];
60unsigned int i=0;
61unsigned short val;
62
63
64void exit_err(int val, int err){
65 MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P6, GPIO_PIN2);
66 exit(-1);
67}
68
69
70void main(void)
71{
72 /* Halting WDT and disabling master interrupts */
73 MAP_WDT_A_holdTimer();
74 MAP_Interrupt_disableMaster();
75
76 /* Initializes Clock System: Required Freq 12Mhz */
77 MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
78 MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
79 MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
80 MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
81 MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
82
83 /* Set LED as outputs and Initial Value */
84 MAP_GPIO_setAsOutputPin(HID_PORT,LEDR|LEDG);
85 MAP_GPIO_setOutputLowOnPin(HID_PORT,LEDR|LEDG);
86
87 /* Set ENA Pin as Output and Enable (Active Low) */
88 MAP_GPIO_setAsOutputPin(CTL_PWR_PORT,GPS_PWR_nEN_PIN);
89 MAP_GPIO_setOutputLowOnPin(CTL_PWR_PORT,GPS_PWR_nEN_PIN);
90
91 /* UART */
92 #ifdef UART
93 /* Selecting P1.2 and P1.3 in UART mode */
94 MAP_GPIO_setAsPeripheralModuleFunctionInputPin(UART_PORT,
95 UART_RX_PIN | UART_TX_PIN, GPIO_PRIMARY_MODULE_FUNCTION);
96 /* Configuring UART Module */
97 MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);
98 /* Enable UART module */
99 MAP_UART_enableModule(EUSCI_A0_BASE);
100 /* Enabling UART interrupts */
101 MAP_UART_enableInterrupt(EUSCI_A0_BASE,EUSCI_A_UART_RECEIVE_INTERRUPT);
102 MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
103 MAP_Interrupt_enableSleepOnIsrExit();
104 #endif
105
106 /* Initialize I2C communication */
107 Init_I2C_GPIO();
108 I2C_init();
109 #ifndef UART
110 printf("I2C Init\n\r");
111 #endif
112
113 /* INA219 */
114 #ifdef INA219
115
116 I2C_setslave(Board_INA219_ADDR);
117
118 val=I2C_read16(0x00);
119
120 #ifndef UART
121 printf("INA219 ConfReg (default) 0x399F: %04X\n",val);
122 #endif
123
124 if( (val&0xFFFF) != 0x399F)
125 exit_err(0x399F,val);
126
127 #endif
128
129
130
131 /* OPT3001 */
132 #ifdef OPT3001
133
134 I2C_setslave(Board_OPT3001_ADDR);
135
136 val=I2C_read16(0x7E);
137 #ifndef UART
138 printf("OPT3001 Manufactured ID 0x5449: %04X\n",val);
139 #endif
140 val=I2C_read16(0x7F);
141
142 #ifndef UART
143 printf("OPT3001 Device ID 0x3001: %04X\n",val);
144 #endif
145
146 if( (val&0xFFFF) != 0x3001)
147 exit_err(0x3001,val);
148
149 #endif
150
151
152 /* HDC1080 */
153 #ifdef HDC1080
154
155 I2C_setslave(Board_HDC1080_ADDR);
156
157 val=I2C_read16(0xFE);
158 #ifndef UART
159 printf("HDC1080 Manufactured ID 0x5449: %04X\n",val);
160 #endif
161
162 val=I2C_read16(0xFF);
163 #ifndef UART
164 printf("HDC1080 Device ID 0x1050: %04X\n",val);
165 #endif
166
167 if( (val&0xFFFF) != 0x1050)
168 exit_err(0x1050,val);
169
170 #endif
171
172
173 /* TMP007 */
174 #ifdef TMP007
175
176 I2C_setslave(Board_TMP007_ADDR);
177
178 val=I2C_read16(0x1E);
179 #ifndef UART
180 printf("TMP007 Manufactured ID 0x5449: %04X\n",val);
181 #endif
182
183 val=I2C_read16(0x1F);
184 #ifndef UART
185 printf("TMP007 Device ID 0x0078: %04X\n",val);
186 #endif
187
188 if( (val&0xFFFF) != 0x0078)
189 exit_err(0x0078,val);
190 #endif
191
192 /* BMP280 */
193 #ifdef BMP280
194
195 I2C_setslave(Board_BMP280_ADDR);
196
197 val=I2C_read8(0xD0);
198 #ifndef UART
199 printf("BMP280 ID 0x58: %02X\n",val);
200 #endif
201
202 if( (val&0xFF) != 0x58)
203 exit_err(0x58,val);
204 #endif
205
206 /* MPU9250 */
207 #ifdef MPU9250
208
209 I2C_setslave(Board_MPU9250_ADDR);
210
211 val=I2C_read8(0x75);
212 #ifndef UART
213 printf("MPU9250 WHOIAM 0x71: %02X\n",val);
214 #endif
215
216 if( (val&0xFF) != 0x71)
217 exit_err(0x71,val);
218 #endif
219
220 /* Done */
221 MAP_GPIO_setOutputHighOnPin(CTL_PWR_PORT,GPS_PWR_nEN_PIN);
222
223 /*
224 * Configuring SysTick to toggle every 0.25s
225 */
226 MAP_SysTick_enableModule();
227 MAP_SysTick_setPeriod(SYSFREQ/4);
228 MAP_Interrupt_enableSleepOnIsrExit();
229 MAP_SysTick_enableInterrupt();
230
231 /* Enabling MASTER interrupts */
232 MAP_Interrupt_enableMaster();
233
234 while(1){
235 MAP_PCM_gotoLPM0();
236 }
237
238}
239
240
241void SysTick_Handler(void)
242{
243 MAP_GPIO_toggleOutputOnPin(HID_PORT,LEDG);
244}
245
246/* EUSCI A0 UART ISR - Nothing to do now */
247void EUSCIA0_IRQHandler(void)
248{
249
250 /*
251 * EUSCI A0 UART ISR - Echoes data back to PC host
252 *
253 uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);
254 MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);
255
256 if(status & EUSCI_A_UART_RECEIVE_INTERRUPT)
257 {
258 MAP_GPIO_toggleOutputOnPin(HID_PORT,LEDR);
259 MAP_UART_transmitData(EUSCI_A0_BASE, MAP_UART_receiveData(EUSCI_A0_BASE));
260 }
261 **/
262}
263
264
265
266
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/msp432p401r.cmd b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/msp432p401r.cmd
new file mode 100644
index 0000000..346c191
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/msp432p401r.cmd
@@ -0,0 +1,84 @@
1/******************************************************************************
2*
3* Copyright (C) 2012 - 2015 Texas Instruments Incorporated - http://www.ti.com/
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions
7* are met:
8*
9* Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11*
12* Redistributions in binary form must reproduce the above copyright
13* notice, this list of conditions and the following disclaimer in the
14* documentation and/or other materials provided with the
15* distribution.
16*
17* Neither the name of Texas Instruments Incorporated nor the names of
18* its contributors may be used to endorse or promote products derived
19* from this software without specific prior written permission.
20*
21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*
33* Default linker command file for Texas Instruments MSP432P401R
34*
35* File creation date: 2015-09-03
36*
37*****************************************************************************/
38
39--retain=flashMailbox
40
41MEMORY
42{
43 MAIN (RX) : origin = 0x00000000, length = 0x00040000
44 INFO (RX) : origin = 0x00200000, length = 0x00004000
45 SRAM_CODE (RWX): origin = 0x01000000, length = 0x00010000
46 SRAM_DATA (RW) : origin = 0x20000000, length = 0x00010000
47}
48
49/* The following command line options are set as part of the CCS project. */
50/* If you are building using the command line, or for some reason want to */
51/* define them here, you can uncomment and modify these lines as needed. */
52/* If you are using CCS for building, it is probably better to make any such */
53/* modifications in your CCS project and leave this file alone. */
54/* */
55/* A heap size of 1024 bytes is recommended when you plan to use printf() */
56/* for debug output to the console window. */
57/* */
58/* --heap_size=1024 */
59/* --stack_size=512 */
60/* --library=rtsv7M4_T_le_eabi.lib */
61
62/* Section allocation in memory */
63
64SECTIONS
65{
66 .intvecs: > 0x00000000
67 .text : > MAIN
68 .const : > MAIN
69 .cinit : > MAIN
70 .pinit : > MAIN
71 .init_array : > MAIN
72
73 .flashMailbox : > 0x00200000
74
75 .vtable : > 0x20000000
76 .data : > SRAM_DATA
77 .bss : > SRAM_DATA
78 .sysmem : > SRAM_DATA
79 .stack : > SRAM_DATA (HIGH)
80}
81
82/* Symbolic definition of the WDTCTL register for RTS */
83WDTCTL_SYM = 0x4000480C;
84
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/startup_msp432p401r_ccs.c b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/startup_msp432p401r_ccs.c
new file mode 100644
index 0000000..0852500
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/startup_msp432p401r_ccs.c
@@ -0,0 +1,255 @@
1/*
2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
5 *
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * --/COPYRIGHT--*/
37//*****************************************************************************
38//
39// Copyright (C) 2012 - 2015 Texas Instruments Incorporated - http://www.ti.com/
40//
41// Redistribution and use in source and binary forms, with or without
42// modification, are permitted provided that the following conditions
43// are met:
44//
45// Redistributions of source code must retain the above copyright
46// notice, this list of conditions and the following disclaimer.
47//
48// Redistributions in binary form must reproduce the above copyright
49// notice, this list of conditions and the following disclaimer in the
50// documentation and/or other materials provided with the
51// distribution.
52//
53// Neither the name of Texas Instruments Incorporated nor the names of
54// its contributors may be used to endorse or promote products derived
55// from this software without specific prior written permission.
56//
57// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
58// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
59// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
60// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
61// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
63// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
67// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68//
69// MSP432 Family Interrupt Vector Table for CGT
70//
71//****************************************************************************
72
73#include <stdint.h>
74
75/* Forward declaration of the default fault handlers. */
76static void resetISR(void);
77static void nmiISR(void);
78static void faultISR(void);
79static void defaultISR(void);
80
81
82/* External declaration for the reset handler that is to be called when the */
83/* processor is started */
84extern void _c_int00(void);
85
86/* External declaration for system initialization function */
87extern void SystemInit(void);
88
89/* Linker variable that marks the top of the stack. */
90extern unsigned long __STACK_END;
91
92
93/* External declarations for the interrupt handlers used by the application. */
94extern void EUSCIA0_IRQHandler (void);
95extern void SysTick_Handler(void);
96
97
98/* Interrupt vector table. Note that the proper constructs must be placed on this to */
99/* ensure that it ends up at physical address 0x0000.0000 or at the start of */
100/* the program if located at a start address other than 0. */
101#pragma RETAIN(interruptVectors)
102#pragma DATA_SECTION(interruptVectors, ".intvecs")
103void (* const interruptVectors[])(void) =
104{
105 (void (*)(void))((uint32_t)&__STACK_END),
106 /* The initial stack pointer */
107 resetISR, /* The reset handler */
108 nmiISR, /* The NMI handler */
109 faultISR, /* The hard fault handler */
110 defaultISR, /* The MPU fault handler */
111 defaultISR, /* The bus fault handler */
112 defaultISR, /* The usage fault handler */
113 0, /* Reserved */
114 0, /* Reserved */
115 0, /* Reserved */
116 0, /* Reserved */
117 defaultISR, /* SVCall handler */
118 defaultISR, /* Debug monitor handler */
119 0, /* Reserved */
120 defaultISR, /* The PendSV handler */
121 SysTick_Handler, /* The SysTick handler */
122 defaultISR, /* PSS ISR */
123 defaultISR, /* CS ISR */
124 defaultISR, /* PCM ISR */
125 defaultISR, /* WDT ISR */
126 defaultISR, /* FPU ISR */
127 defaultISR, /* FLCTL ISR */
128 defaultISR, /* COMP0 ISR */
129 defaultISR, /* COMP1 ISR */
130 defaultISR, /* TA0_0 ISR */
131 defaultISR, /* TA0_N ISR */
132 defaultISR, /* TA1_0 ISR */
133 defaultISR, /* TA1_N ISR */
134 defaultISR, /* TA2_0 ISR */
135 defaultISR, /* TA2_N ISR */
136 defaultISR, /* TA3_0 ISR */
137 defaultISR, /* TA3_N ISR */
138 EUSCIA0_IRQHandler, /* EUSCIA0 ISR */
139 defaultISR, /* EUSCIA1 ISR */
140 defaultISR, /* EUSCIA2 ISR */
141 defaultISR, /* EUSCIA3 ISR */
142 defaultISR, /* EUSCIB0 ISR */
143 defaultISR, /* EUSCIB1 ISR */
144 defaultISR, /* EUSCIB2 ISR */
145 defaultISR, /* EUSCIB3 ISR */
146 defaultISR, /* ADC14 ISR */
147 defaultISR, /* T32_INT1 ISR */
148 defaultISR, /* T32_INT2 ISR */
149 defaultISR, /* T32_INTC ISR */
150 defaultISR, /* AES ISR */
151 defaultISR, /* RTC ISR */
152 defaultISR, /* DMA_ERR ISR */
153 defaultISR, /* DMA_INT3 ISR */
154 defaultISR, /* DMA_INT2 ISR */
155 defaultISR, /* DMA_INT1 ISR */
156 defaultISR, /* DMA_INT0 ISR */
157 defaultISR, /* PORT1 ISR */
158 defaultISR, /* PORT2 ISR */
159 defaultISR, /* PORT3 ISR */
160 defaultISR, /* PORT4 ISR */
161 defaultISR, /* PORT5 ISR */
162 defaultISR, /* PORT6 ISR */
163 defaultISR, /* Reserved 41 */
164 defaultISR, /* Reserved 42 */
165 defaultISR, /* Reserved 43 */
166 defaultISR, /* Reserved 44 */
167 defaultISR, /* Reserved 45 */
168 defaultISR, /* Reserved 46 */
169 defaultISR, /* Reserved 47 */
170 defaultISR, /* Reserved 48 */
171 defaultISR, /* Reserved 49 */
172 defaultISR, /* Reserved 50 */
173 defaultISR, /* Reserved 51 */
174 defaultISR, /* Reserved 52 */
175 defaultISR, /* Reserved 53 */
176 defaultISR, /* Reserved 54 */
177 defaultISR, /* Reserved 55 */
178 defaultISR, /* Reserved 56 */
179 defaultISR, /* Reserved 57 */
180 defaultISR, /* Reserved 58 */
181 defaultISR, /* Reserved 59 */
182 defaultISR, /* Reserved 60 */
183 defaultISR, /* Reserved 61 */
184 defaultISR, /* Reserved 62 */
185 defaultISR /* Reserved 63 */
186};
187
188
189/* This is the code that gets called when the processor first starts execution */
190/* following a reset event. Only the absolutely necessary set is performed, */
191/* after which the application supplied entry() routine is called. Any fancy */
192/* actions (such as making decisions based on the reset cause register, and */
193/* resetting the bits in that register) are left solely in the hands of the */
194/* application. */
195void resetISR(void)
196{
197 SystemInit();
198
199 /* Jump to the CCS C Initialization Routine. */
200 __asm(" .global _c_int00\n"
201 " b.w _c_int00");
202}
203
204/* This is the code that gets called when the processor receives a NMI. This */
205/* simply enters an infinite loop, preserving the system state for examination */
206/* by a debugger. */
207static void nmiISR(void)
208{
209 /* Fault trap exempt from ULP advisor */
210 #pragma diag_push
211 #pragma CHECK_ULP("-2.1")
212
213 /* Enter an infinite loop. */
214 while(1)
215 {
216 }
217
218 #pragma diag_pop
219}
220
221
222/* This is the code that gets called when the processor receives a fault */
223/* interrupt. This simply enters an infinite loop, preserving the system state */
224/* for examination by a debugger. */
225static void faultISR(void)
226{
227 /* Fault trap exempt from ULP advisor */
228 #pragma diag_push
229 #pragma CHECK_ULP("-2.1")
230
231 /* Enter an infinite loop. */
232 while(1)
233 {
234 }
235
236 #pragma diag_pop
237}
238
239
240/* This is the code that gets called when the processor receives an unexpected */
241/* interrupt. This simply enters an infinite loop, preserving the system state */
242/* for examination by a debugger. */
243static void defaultISR(void)
244{
245 /* Fault trap exempt from ULP advisor */
246 #pragma diag_push
247 #pragma CHECK_ULP("-2.1")
248
249 /* Enter an infinite loop. */
250 while(1)
251 {
252 }
253
254 #pragma diag_pop
255}
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/system_msp432p401r.c b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/system_msp432p401r.c
new file mode 100644
index 0000000..9479e03
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_I2C_Sensors/system_msp432p401r.c
@@ -0,0 +1,434 @@
1/*
2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
5 *
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * --/COPYRIGHT--*/
37/**************************************************************************//**
38* @file system_msp432p401r.c
39* @brief CMSIS Cortex-M4F Device Peripheral Access Layer Source File for
40* MSP432P401R
41* @version V1.00
42* @date 20-Oct-2015
43*
44* @note View configuration instructions embedded in comments
45*
46******************************************************************************/
47//*****************************************************************************
48//
49// Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
50//
51// Redistribution and use in source and binary forms, with or without
52// modification, are permitted provided that the following conditions
53// are met:
54//
55// Redistributions of source code must retain the above copyright
56// notice, this list of conditions and the following disclaimer.
57//
58// Redistributions in binary form must reproduce the above copyright
59// notice, this list of conditions and the following disclaimer in the
60// documentation and/or other materials provided with the
61// distribution.
62//
63// Neither the name of Texas Instruments Incorporated nor the names of
64// its contributors may be used to endorse or promote products derived
65// from this software without specific prior written permission.
66//
67// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
68// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
69// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
70// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
71// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
72// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
73// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
77// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78//
79//*****************************************************************************
80
81#include <stdint.h>
82#include "msp.h"
83
84/*--------------------- Configuration Instructions ----------------------------
85 1. If you prefer to halt the Watchdog Timer, set __HALT_WDT to 1:
86 #define __HALT_WDT 1
87 2. Insert your desired CPU frequency in Hz at:
88 #define __SYSTEM_CLOCK 3000000
89 3. If you prefer the DC-DC power regulator (more efficient at higher
90 frequencies), set the __REGULATOR to 1:
91 #define __REGULATOR 1
92 *---------------------------------------------------------------------------*/
93
94/*--------------------- Watchdog Timer Configuration ------------------------*/
95// Halt the Watchdog Timer
96// <0> Do not halt the WDT
97// <1> Halt the WDT
98#define __HALT_WDT 1
99
100/*--------------------- CPU Frequency Configuration -------------------------*/
101// CPU Frequency
102// <1500000> 1.5 MHz
103// <3000000> 3 MHz
104// <12000000> 12 MHz
105// <24000000> 24 MHz
106// <48000000> 48 MHz
107#define __SYSTEM_CLOCK 1500000
108
109/*--------------------- Power Regulator Configuration -----------------------*/
110// Power Regulator Mode
111// <0> LDO
112// <1> DC-DC
113#define __REGULATOR 1
114
115/*----------------------------------------------------------------------------
116 Define clocks, used for SystemCoreClockUpdate()
117 *---------------------------------------------------------------------------*/
118#define __VLOCLK 10000
119#define __MODCLK 24000000
120#define __LFXT 32768
121#define __HFXT 48000000
122
123/*----------------------------------------------------------------------------
124 Clock Variable definitions
125 *---------------------------------------------------------------------------*/
126uint32_t SystemCoreClock = __SYSTEM_CLOCK; /*!< System Clock Frequency (Core Clock)*/
127
128/**
129 * Update SystemCoreClock variable
130 *
131 * @param none
132 * @return none
133 *
134 * @brief Updates the SystemCoreClock with current core Clock
135 * retrieved from cpu registers.
136 */
137void SystemCoreClockUpdate(void)
138{
139 uint32_t source, divider;
140 uint8_t dividerValue;
141
142 float dcoConst;
143 int32_t calVal;
144 uint32_t centeredFreq;
145 int16_t dcoTune;
146
147 divider = (CS->CTL1 & CS_CTL1_DIVM_MASK) >> CS_CTL1_DIVM_OFS;
148 dividerValue = 1 << divider;
149 source = CS->CTL1 & CS_CTL1_SELM_MASK;
150
151 switch(source)
152 {
153 case CS_CTL1_SELM__LFXTCLK:
154 if(BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS))
155 {
156 // Clear interrupt flag
157 CS->KEY = CS_KEY_VAL;
158 CS->CLRIFG |= CS_CLRIFG_CLR_LFXTIFG;
159 CS->KEY = 1;
160
161 if(BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS))
162 {
163 if(BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS))
164 {
165 SystemCoreClock = (128000 / dividerValue);
166 }
167 else
168 {
169 SystemCoreClock = (32000 / dividerValue);
170 }
171 }
172 else
173 {
174 SystemCoreClock = __LFXT / dividerValue;
175 }
176 }
177 else
178 {
179 SystemCoreClock = __LFXT / dividerValue;
180 }
181 break;
182 case CS_CTL1_SELM__VLOCLK:
183 SystemCoreClock = __VLOCLK / dividerValue;
184 break;
185 case CS_CTL1_SELM__REFOCLK:
186 if (BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS))
187 {
188 SystemCoreClock = (128000 / dividerValue);
189 }
190 else
191 {
192 SystemCoreClock = (32000 / dividerValue);
193 }
194 break;
195 case CS_CTL1_SELM__DCOCLK:
196 dcoTune = (CS->CTL0 & CS_CTL0_DCOTUNE_MASK) >> CS_CTL0_DCOTUNE_OFS;
197
198 switch(CS->CTL0 & CS_CTL0_DCORSEL_MASK)
199 {
200 case CS_CTL0_DCORSEL_0:
201 centeredFreq = 1500000;
202 break;
203 case CS_CTL0_DCORSEL_1:
204 centeredFreq = 3000000;
205 break;
206 case CS_CTL0_DCORSEL_2:
207 centeredFreq = 6000000;
208 break;
209 case CS_CTL0_DCORSEL_3:
210 centeredFreq = 12000000;
211 break;
212 case CS_CTL0_DCORSEL_4:
213 centeredFreq = 24000000;
214 break;
215 case CS_CTL0_DCORSEL_5:
216 centeredFreq = 48000000;
217 break;
218 }
219
220 if(dcoTune == 0)
221 {
222 SystemCoreClock = centeredFreq;
223 }
224 else
225 {
226
227 if(dcoTune & 0x1000)
228 {
229 dcoTune = dcoTune | 0xF000;
230 }
231
232 if (BITBAND_PERI(CS->CTL0, CS_CTL0_DCORES_OFS))
233 {
234 dcoConst = *((float *) &TLV->DCOER_CONSTK_RSEL04);
235 calVal = TLV->DCOER_FCAL_RSEL04;
236 }
237 /* Internal Resistor */
238 else
239 {
240 dcoConst = *((float *) &TLV->DCOIR_CONSTK_RSEL04);
241 calVal = TLV->DCOIR_FCAL_RSEL04;
242 }
243
244 SystemCoreClock = (uint32_t) ((centeredFreq)
245 / (1
246 - ((dcoConst * dcoTune)
247 / (8 * (1 + dcoConst * (768 - calVal))))));
248 }
249 break;
250 case CS_CTL1_SELM__MODOSC:
251 SystemCoreClock = __MODCLK / dividerValue;
252 break;
253 case CS_CTL1_SELM__HFXTCLK:
254 if(BITBAND_PERI(CS->IFG, CS_IFG_HFXTIFG_OFS))
255 {
256 // Clear interrupt flag
257 CS->KEY = CS_KEY_VAL;
258 CS->CLRIFG |= CS_CLRIFG_CLR_HFXTIFG;
259 CS->KEY = 1;
260
261 if(BITBAND_PERI(CS->IFG, CS_IFG_HFXTIFG_OFS))
262 {
263 if(BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS))
264 {
265 SystemCoreClock = (128000 / dividerValue);
266 }
267 else
268 {
269 SystemCoreClock = (32000 / dividerValue);
270 }
271 }
272 else
273 {
274 SystemCoreClock = __HFXT / dividerValue;
275 }
276 }
277 else
278 {
279 SystemCoreClock = __HFXT / dividerValue;
280 }
281 break;
282 }
283}
284
285/**
286 * Initialize the system
287 *
288 * @param none
289 * @return none
290 *
291 * @brief Setup the microcontroller system.
292 *
293 * Performs the following initialization steps:
294 * 1. Enables the FPU
295 * 2. Halts the WDT if requested
296 * 3. Enables all SRAM banks
297 * 4. Sets up power regulator and VCORE
298 * 5. Enable Flash wait states if needed
299 * 6. Change MCLK to desired frequency
300 * 7. Enable Flash read buffering
301 */
302void SystemInit(void)
303{
304 // Enable FPU if used
305 #if (__FPU_USED == 1) /* __FPU_USED is defined in core_cm4.h */
306 SCB->CPACR |= ((3UL << 10 * 2) | /* Set CP10 Full Access */
307 (3UL << 11 * 2)); /* Set CP11 Full Access */
308 #endif
309
310 #if (__HALT_WDT == 1)
311 WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // Halt the WDT
312 #endif
313
314 SYSCTL->SRAM_BANKEN = SYSCTL_SRAM_BANKEN_BNK7_EN; // Enable all SRAM banks
315
316 #if (__SYSTEM_CLOCK == 1500000) // 1.5 MHz
317 // Default VCORE is LDO VCORE0 so no change necessary
318
319 // Switches LDO VCORE0 to DCDC VCORE0 if requested
320 #if __REGULATOR
321 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
322 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
323 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
324 #endif
325
326 // No flash wait states necessary
327
328 // DCO = 1.5 MHz; MCLK = source
329 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
330 CS->CTL0 = CS_CTL0_DCORSEL_0; // Set DCO to 1.5MHz
331 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
332 CS->KEY = 0;
333
334 // Set Flash Bank read buffering
335 FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
336 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
337
338 #elif (__SYSTEM_CLOCK == 3000000) // 3 MHz
339 // Default VCORE is LDO VCORE0 so no change necessary
340
341 // Switches LDO VCORE0 to DCDC VCORE0 if requested
342 #if __REGULATOR
343 while(PCM->CTL1 & PCM_CTL1_PMR_BUSY);
344 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
345 while(PCM->CTL1 & PCM_CTL1_PMR_BUSY);
346 #endif
347
348 // No flash wait states necessary
349
350 // DCO = 3 MHz; MCLK = source
351 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
352 CS->CTL0 = CS_CTL0_DCORSEL_1; // Set DCO to 1.5MHz
353 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
354 CS->KEY = 0;
355
356 // Set Flash Bank read buffering
357 FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
358 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
359
360 #elif (__SYSTEM_CLOCK == 12000000) // 12 MHz
361 // Default VCORE is LDO VCORE0 so no change necessary
362
363 // Switches LDO VCORE0 to DCDC VCORE0 if requested
364 #if __REGULATOR
365 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
366 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
367 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
368 #endif
369
370 // No flash wait states necessary
371
372 // DCO = 12 MHz; MCLK = source
373 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
374 CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz
375 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
376 CS->KEY = 0;
377
378 // Set Flash Bank read buffering
379 FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
380 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
381
382 #elif (__SYSTEM_CLOCK == 24000000) // 24 MHz
383 // Default VCORE is LDO VCORE0 so no change necessary
384
385 // Switches LDO VCORE0 to DCDC VCORE0 if requested
386 #if __REGULATOR
387 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
388 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
389 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
390 #endif
391
392 // 1 flash wait state (BANK0 VCORE0 max is 12 MHz)
393 FLCTL->BANK0_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_1;
394 FLCTL->BANK1_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_1;
395
396 // DCO = 24 MHz; MCLK = source
397 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
398 CS->CTL0 = CS_CTL0_DCORSEL_4; // Set DCO to 24MHz
399 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
400 CS->KEY = 0;
401
402 // Set Flash Bank read buffering
403 FLCTL->BANK0_RDCTL |= (FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
404 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
405
406 #elif (__SYSTEM_CLOCK == 48000000) // 48 MHz
407 // Switches LDO VCORE0 to LDO VCORE1; mandatory for 48 MHz setting
408 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
409 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_1;
410 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
411
412 // Switches LDO VCORE1 to DCDC VCORE1 if requested
413 #if __REGULATOR
414 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
415 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_5;
416 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
417 #endif
418
419 // 2 flash wait states (BANK0 VCORE1 max is 16 MHz, BANK1 VCORE1 max is 32 MHz)
420 FLCTL->BANK0_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_2;
421 FLCTL->BANK1_RDCTL &= ~FLCTL_BANK1_RDCTL_WAIT_MASK | FLCTL_BANK1_RDCTL_WAIT_2;
422
423 // DCO = 48 MHz; MCLK = source
424 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
425 CS->CTL0 = CS_CTL0_DCORSEL_5; // Set DCO to 48MHz
426 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
427 CS->KEY = 0;
428
429 // Set Flash Bank read buffering
430 FLCTL->BANK0_RDCTL |= (FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
431 FLCTL->BANK1_RDCTL |= (FLCTL_BANK1_RDCTL_BUFD | FLCTL_BANK1_RDCTL_BUFI);
432 #endif
433
434}