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
|
/*******************************************************************************
* MSP432 Clock System - HFXT Startup
*
* Description:
*
* HFXTAL:
* Starts the 48MHz crystal attached to HFXTIN/HFXTOUT
* Sources MCLK from the crystal
*
* LFXTL:
* Starts the 32khz crystal attached to LFXTIN/LFXTOUT
* Sources AMCLK from crystal
*
* Internal DCO:
* Starts the DCO
* Sources SMCLK from DCO
*
* Blinks an LED using SysTick (which is sourced from MCLK).
*
*
*
* MSP432P401
* ------------------
* /|\| |
* | | |
* --|RST P8.5 |---> LED
* | |
* | PJ.3 HFXTIN |<--------
* | | < 48Mhz xTal >
* | PJ.2 HFXTOUT |<--------
* | |
* | PJ.0 LFXIN |<--------
* | | < 32khz xTal >
* | PJ.1 LFXOUT |<--------
* | |
* | P4.2 |--> ACLK - 32.768 KHz
* | P4.3 |--> MCLK - 12.000 MHz
* | P4.4 |--> HSMCLK - 6.000 MHz
* | P7.0 |--> SMCLK
* | |
*
* Author: Timothy Logan
* Rev: B.Martinez
******************************************************************************/
#include "i3mote.h"
/* DriverLib Includes */
#include "driverlib.h"
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
int main(void)
{
/* Halting the Watchdog */
MAP_WDT_A_holdTimer();
/* Configuring pins for peripheral/crystal usage*/
/* LFXTAL */
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
GPIO_PIN0 | GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION);
/* HFXTL */
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
/* Clocks Output */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4,
GPIO_PIN2|GPIO_PIN3|GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7,
GPIO_PIN0, GPIO_PRIMARY_MODULE_FUNCTION);
/* LEDs */
MAP_GPIO_setAsOutputPin(HID_PORT,LEDG|LEDR);
MAP_GPIO_setOutputHighOnPin(HID_PORT, LEDG|LEDR);
/* Setting the external clock frequency. This API is optional */
CS_setExternalClockSourceFrequency(32000,12000000);
/* Starting HFXT in non-bypass mode without a timeout. Before we start
* we have to change VCORE to 1 to support the 48MHz frequency */
MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
CS_startHFXT(false);
/* Initializing MCLK to HFXT (effectively 48/4 MHz) */
MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_4);
/* Initializing ACLK to LFXT */
CS_startLFXT(false);
MAP_CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
/* Initializes Aux. Clocks System with DCO */
MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
/*
* Configuring SysTick to trigger at 6000000
* MCLK is 12MHz so this will make it toggle every 0.5s
* */
MAP_SysTick_enableModule();
MAP_SysTick_setPeriod(6000000);
MAP_Interrupt_enableSleepOnIsrExit();
MAP_SysTick_enableInterrupt();
/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
while (1)
{
MAP_PCM_gotoLPM0();
}
}
void SysTick_Handler(void)
{
MAP_GPIO_toggleOutputOnPin(HID_PORT, LEDG|LEDR);
}
|