1 ; -*- coding: utf-8 -*-
3 ; ======================================================================
4 ; INIT MSP-EXP430FR4133 board
5 ; ======================================================================
8 ; http://www.ebay.fr/itm/CP2102-USB-UART-Board-mini-Data-Transfer-Convertor-Module-Development-Board-/251433941479
10 ; for sd card socket be carefull : pin CD must be present !
11 ; http://www.ebay.com/itm/2-PCS-SD-Card-Module-Slot-Socket-Reader-For-Arduino-MCU-/181211954262?pt=LH_DefaultDomain_0&hash=item2a3112fc56
14 ; J101 eZ-FET <-> target
15 ; -----------------------
17 ; P3 <-> P4 - TEST - TEST
18 ; P5 <-> P6 - RST - RST
19 ; P7 <-> P8 - TX1 - P1.0 UCA0 TXD ---> RX UARTtoUSB module
20 ; P9 <->P10 - RX1 - P1.1 UCA0 RXD <--- TX UARTtoUSB module
21 ; P11<->P12 - CTS - P2.4
22 ; P13<->P14 - RTS - P2.3
23 ; P15<->P16 - VCC - 3V3
25 ; P19<->P20 - GND - VSS
27 ; Launchpad Header Left J1
28 ; ------------------------
40 ; Launchpad Header Right J2
41 ; -------------------------
43 ; P2 - P1.7 TA0.1/TDO/A7
44 ; P3 - P1.6 TA0.2/TDI/TCLK/A6
47 ; P6 - P5.2 UCB0SIMO/UCB0SDA
48 ; P7 - P5.3 UCB0SOMI/UCB0SCL
49 ; P8 - P1.3 UCA0STE/A3
50 ; P9 - P1.4 MCLK/TCK/A4
51 ; P10- P1.5 TA0CLK/TMS/A5
104 ; ===================================================================================
105 ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
106 ; then wire VCC and GND of bridge onto J13 connector
107 ; ===================================================================================
109 ; ---------------------------------------------------
110 ; MSP - MSP-EXP430FR4133 LAUNCHPAD <--> OUTPUT WORLD
111 ; ---------------------------------------------------
117 ; +-4k7-< DeepRST <-- GND
119 ; P1.0 - UCA0 TXD J101.8 --+-> RX UARTtoUSB bridge
120 ; P1.1 - UCA0 RXD J101.10 <---- TX UARTtoUSB bridge
121 ; P2.3 - RTS J101.14 ----> CTS UARTtoUSB bridge (if TERMINALCTSRTS option)
122 ; VCC - J101.16 <---- VCC (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
123 ; GND - J101.20 <---> GND (optional supply from UARTtoUSB bridge)
125 ; P2.7 - J1.5 <---- OUT IR_Receiver (1 TSOP32236)
127 ; P4.1 - LFXI 32768Hz quartz
128 ; P4.2 - LFXO 32768Hz quartz
130 ; P5.2 - UCB0 SDA/SIMO J2.6 <---> SDA I2C Slave
131 ; P5.3 - UCB0 SCL/SOMI J2.7 <---- SCL I2C Slave
133 ; P5.1 - UCB0 CLK J1.7 ----> orange SD_CLK
134 ; P5.2 - UCB0 SDA/SIMO J2.6 ----> grey SD_SDI
135 ; P5.3 - UCB0 SCL/SOMI J2.7 <---- purple SD_SDO
136 ; P8.0 - J1.6 <---- violin SD_CD (Card Detect)
137 ; P8.1 - J1.2 ----> brown SD_CS (Card Select)
139 ; P8.2 - Soft I2C_Master J1.9 ----> SDA software I2C Master
140 ; P8.3 - Soft I2C_Master J1.10 <---> SCL software I2C Master
143 ; ----------------------------------------------------------------------
144 ; POWER ON RESET AND INITIALIZATION : I/O
145 ; ----------------------------------------------------------------------
147 ; ----------------------------------------------------------------------
148 ; POWER ON RESET AND INITIALIZATION : PORT1/2
149 ; ----------------------------------------------------------------------
151 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
153 BIS #-1,&PAREN ; all input pins with resistor
154 BIS #-1,&PAOUT ; all pins with PULLUP resistor
158 ; P1.0 - TX0 --> JP1 --> red LED1 --> GND
162 SW1 .equ 4 ; P1.2 = S1
165 IO_WIPE .equ 4 ; P1.2 = S1 = FORTH Deep_RST pin
171 TXD .equ 1 ; P1.0 = TXD
173 BUS_TERM .equ 003h ; TX RX
176 HANDSHAKOUT .set P2OUT
178 RTS .set 8 ; P2.3 bit position
179 CTS .set 10h ; P2.4 bit position
181 .IFDEF TERMINAL4WIRES
182 ; RTS output is wired to the CTS input of UART2USB bridge
183 ; configure RTS as output high to disable RX TERM during start FORTH
184 BIS.B #RTS,&P2DIR ; RTS as output high
185 .IFDEF TERMINAL5WIRES
186 BIC.B #CTS,&P2OUT ; CTS input pulled down
187 .ENDIF ; TERMINAL5WIRES
188 .ENDIF ; TERMINAL4WIRES
191 SW2 .equ 40h ; P2.6 = S2
193 ; ----------------------------------------------------------------------
194 ; POWER ON RESET AND INITIALIZATION : PORT3/4
195 ; ----------------------------------------------------------------------
197 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
199 BIS #0FEFFh,&PBREN ; pullup for all pins resistors else P4.0
200 MOV #-1,&PBOUT ; OUT1 for all pins else P4
206 ; P4.1 - LFXI 32768Hz quartz
207 ; P4.2 - LFXO 32768Hz quartz
211 LED2 .equ 1 ; P4.0 LED2 green
213 ; PORTx default wanted state : pins as input with pullup resistor
215 ; ----------------------------------------------------------------------
216 ; POWER ON RESET AND INITIALIZATION : PORT5/6
217 ; ----------------------------------------------------------------------
219 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
221 BIS #-1,&PCREN ; all pins with pull resistors
222 MOV #-1,&PCOUT ; all pins OUT1
235 SD_SEL .equ PCSEL0 ; to configure UCB0
236 SD_REN .equ PCREN ; to configure pullup resistors
237 BUS_SD .equ 000Eh ; pins P5.1 as UCB0CLK, P5.2 as UCB0SIMO & P5.3 as UCB0SOMI
239 ; PORTx default wanted state : pins as input with pullup resistor
241 ; ----------------------------------------------------------------------
242 ; POWER ON RESET AND INITIALIZATION : PORT7/8
243 ; ----------------------------------------------------------------------
245 BIS #-1,&PDREN ; all pins with pull resistors
246 MOV #-1,&PDOUT ; all pins OUT1
254 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
256 ; PORTx default wanted state : pins as input with pullup resistor
258 ; ----------------------------------------------------------------------
260 ; ----------------------------------------------------------------------
263 MOV.B #0A5h, &FRCTL0_H ; enable FRCTL0 access
264 MOV.B #10h, &FRCTL0 ; 1 waitstate @ 16 MHz
265 MOV.B #01h, &FRCTL0_H ; disable FRCTL0 access
268 ; ----------------------------------------------------------------------
269 ; POWER ON RESET SYS config
270 ; ----------------------------------------------------------------------
272 ; BIC #1,&SYSCFG0 ; enable write program in FRAM
273 MOV #0A500h,&SYSCFG0 ; enable write MAIN and INFO
275 ; ----------------------------------------------------------------------
276 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
277 ; ----------------------------------------------------------------------
279 ; CS code for EXP430FR4133
281 ; to measure REFO frequency, output ACLK on P8.1:
284 ; result : REFO = ? kHz
287 ; MOV #0000h,&CSCTL3 ; FLL select XT1, FLLREFDIV=0 (default value)
288 MOV #0000h,&CSCTL4 ; ACLOCK select XT1, MCLK & SMCLK select DCOCLKDIV
289 BIS.B #06,&P4SEL0 ; P4.2 as XOUT, P4.1 as XIN
291 BIS #0010h,&CSCTL3 ; FLL select REFCLOCK
292 ; MOV #0100h,&CSCTL4 ; ACLOCK select REFO, MCLK & SMCLK select DCOCLKDIV (default value)
294 BIC.B #-1,&CSCTL1 ; clear DCORSEL (Set 1MHZ DCORSEL), DCOFTRIM=0, ENable MODulation to reduce EMI
295 .IF FREQUENCY = 1 ; nothing else to do
296 .ELSEIF FREQUENCY = 2
297 BIS.B #2,&CSCTL1 ; Set 2MHZ DCORSEL
298 .ELSEIF FREQUENCY = 4
299 BIS.B #4,&CSCTL1 ; Set 4MHZ DCORSEL
300 .ELSEIF FREQUENCY = 8
301 BIS.B #6,&CSCTL1 ; Set 8MHZ DCORSEL
302 .ELSEIF FREQUENCY = 12
303 BIS.B #8,&CSCTL1 ; Set 12MHZ DCORSEL
304 .ELSEIF FREQUENCY = 16
305 BIS.B #10,&CSCTL1 ; Set 16MHZ DCORSEL
307 .error "bad frequency setting, only 1,2,4,8,12,16 MHz"
309 ; MOV #INT(FREQUENCY*1000000/32768)-1,&CSCTL2; set FLLD=0 (DCOCLKCDIV=DCO),set FLLN for frequency slight lower
310 MOV #INT(FREQUENCY*1000000/32768),&CSCTL2; set FLLD=0 (DCOCLKCDIV=DCO),set FLLN for frequency slight upper
311 MOV #64,X ; 64* 3 ms = 192 ms delay, because FLL lock time = 120 ms
312 ClockWaitX MOV &FREQ_KHZ,Y ;
313 ClockWaitY SUB #1,Y ;1
314 JNZ ClockWaitY ;2 FREQ_KHZ x 3 ==> 3ms