1 ; -*- coding: utf-8 -*-
4 ; ======================================================================
5 ; INIT CHIPSTICK MSP430FR2433
6 ; ======================================================================
9 ; http://www.ebay.fr/itm/CP2102-USB-UART-Board-mini-Data-Transfer-Convertor-Module-Development-Board-/251433941479
11 ; for sd card socket be carefull : pin CD must be present !
12 ; http://www.ebay.com/itm/2-PCS-SD-Card-Module-Slot-Socket-Reader-For-Arduino-MCU-/181211954262?pt=LH_DefaultDomain_0&hash=item2a3112fc56
15 ; ChipStick PROG Header
16 ; ------------------------
24 ; ChipStick Header PL1
25 ; ------------------------
28 ; P3 - 4 - P1.5 UCA0 RX/SOMI
29 ; P4 - 3 - P1.4 UCA0 TX/SIMO
30 ; P5 - 5 - P1.6 UCA0 CLK
33 ; P8 - 7 - P1.0 UCB0 STE
34 ; P9 - 8 - P1.1 UCB0 CLK
35 ; P10- 9 - P1.2 UCB0 SIMO/SDA
37 ; ChipStick Header PL2
38 ; -------------------------
44 ; P6 - 17 - P2.6 UCA1 TX/SIMO
45 ; P7 - 16 - P2.5 UCA1 RX/SOMI
46 ; P8 - 15 - P2.4 UCA1 CLK
48 ; P10- 10 - P1.3 UCB0 SOMI/SCL
51 ; LED1 - 14 - P3.1 UCA1 STE
57 ; ===================================================================================
58 ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
59 ; then wire VCC and GND of bridge onto J13 connector
60 ; ===================================================================================
62 ; ---------------------------------------------------
63 ; CHIPSTICK_FR2433 <--> OUTPUT WORLD
64 ; ---------------------------------------------------
70 ; +--4k7-< DeepRST <-- GND
72 ; P1.4 - UCA0 TXD PL1.4 - <-+-> RX UARTtoUSB bridge
73 ; P1.5 - UCA0 RXD PL1.3 - <---- TX UARTtoUSB bridge
74 ; P3.2 - RTS PL1.2 - ----> CTS UARTtoUSB bridge (if TERMINALCTSRTS option)
76 ; P3.0 - PL1.7 - ----> /CS SPI_RAM
77 ; P1.1 - UCB0 CLK PL1.9 - ----> CLK SPI_RAM
78 ; P1.2 - UCB0 SIMO PL1.10 - ----> SI SPI_RAM
79 ; P1.3 - UCB0 SOMI PL2.10 - <---- S0 SPI_RAM
82 ; P1.1 - UCB0 CLK PL1.9 - ----> SD_CLK
83 ; P1.2 - UCB0 SIMO PL1.10 - ----> SD_SDI
84 ; P1.3 - UCB0 SOMI PL2.10 - <---- SD_SDO
85 ; P2.3 - PL1.6 - <---- SD_CD (Card Detect)
86 ; P2.2 - PL2.9 - ----> SD_CS (Card Select)
88 ; P1.2 - UCB0 SDA PL1.10 - <---> SDA I2C Slave
89 ; P1.3 - UCB0 SCL PL2.10 - ----> SCL I2C Slave
91 ; P2.2 - PL2.9 - ----> SCL I2C SoftMaster
92 ; P2.0 - PL2.3 - <---> SDA I2C SoftMaster
94 ; P1.0 - UCB0 STE PL1.8 - <---- TSSOP32236 (IR RC5)
96 ; ----------------------------------------------------------------------
97 ; POWER ON RESET AND INITIALIZATION : I/O
98 ; ----------------------------------------------------------------------
100 ; ----------------------------------------------------------------------
101 ; POWER ON RESET AND INITIALIZATION : PORT1/2
102 ; ----------------------------------------------------------------------
104 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
106 ; PORTx default wanted state : pins as input with pullup resistor
108 MOV #-1,&PAOUT ; OUT1 for all pins
109 BIS #-1,&PAREN ; all pins with pull resistors
117 BUS_TERM .equ 0Ch ; P1.2=SDA P1.3=SCL
121 SD_SEL .equ PASEL0 ; to configure UCB0
122 SD_REN .equ PAREN ; to configure pullup resistors
123 BUS_SD .equ 000Eh ; pins P1.1 as UCB0CLK, P1.2 as UCB0SIMO & P1.3 as UCB0SOMI
136 SW1 .equ 10h ; P1.4 = FORTH Deep_RST pin
139 BUS_SD .equ 0070h ; pins P1.4,P1.5,P1.6
145 CD_SD .equ 8 ; P2.3 as Card Detect
148 CS_SD .equ 4 ; P2.2 as Card Select
152 ; ----------------------------------------------------------------------
153 ; POWER ON RESET AND INITIALIZATION : PORT3
154 ; ----------------------------------------------------------------------
156 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
161 HANDSHAKOUT .equ P3OUT
166 ; RTS output is wired to the CTS input of UART2USB bridge
167 ; CTS is not used by FORTH terminal
168 ; configure RTS as output high to disable RX TERM during start FORTH
170 ; PORTx default wanted state : pins as input with pullup resistor
172 MOV.B #001h,&P3DIR ; all pins as input else LED1 as output
173 BIS.B #-1,&P3REN ; all inputs with pull resistors
174 MOV.B #0FDh,&P3OUT ; all pins with pullup resistors and LED1 = output low
176 .IFDEF TERMINAL4WIRES
177 ; RTS output is wired to the CTS input of UART2USB bridge
178 ; configure RTS as output high to disable RX TERM during start FORTH
179 BIS.B #RTS,&P3DIR ; RTS as output high
180 .IFDEF TERMINAL5WIRES
181 ; CTS input must be wired to the RTS output of UART2USB bridge
182 ; configure CTS as input low (true) to avoid lock when CTS is not wired
183 BIC.B #CTS,&P3OUT ; CTS input pulled down
184 .ENDIF ; TERMINAL5WIRES
185 .ENDIF ; TERMINAL4WIRES
187 ; ----------------------------------------------------------------------
189 ; ----------------------------------------------------------------------
192 MOV.B #0A5h, &FRCTL0_H ; enable FRCTL0 access
193 MOV.B #10h, &FRCTL0 ; 1 waitstate @ 16 MHz
194 MOV.B #01h, &FRCTL0_H ; disable FRCTL0 access
197 ; ----------------------------------------------------------------------
198 ; POWER ON RESET SYS config
199 ; ----------------------------------------------------------------------
202 ; BIC #1,&SYSCFG0 ; enable write program in FRAM
203 MOV #0A500h,&SYSCFG0 ; enable write MAIN and INFO
205 ; ----------------------------------------------------------------------
206 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
207 ; ----------------------------------------------------------------------
209 ; CS code for EXP430FR2433
211 ; to measure REFO frequency, output ACLK on P2.2:
214 ; result : REFO = 32.69kHz
217 ; MOV #0000h,&CSCTL3 ; FLL select XT1, FLLREFDIV=0 (default value)
218 MOV #0000h,&CSCTL4 ; ACLOCK select XT1, MCLK & SMCLK select DCOCLKDIV
219 BIS.B #03,&P2SEL0 ; P2.0 as XOUT, P2.1 as XIN
221 BIS #0010h,&CSCTL3 ; FLL select REFCLOCK
222 MOV #0200h,&CSCTL4 ; ACLOCK select VLOCLK, MCLK & SMCLK select DCOCLKDIV (default value)
224 BIC.B #-1,&CSCTL1 ; clear DCORSEL (Set 1MHZ DCORSEL), DCOFTRIM=0, ENable MODulation to reduce EMI
225 .IF FREQUENCY = 1 ; nothing else to do
226 .ELSEIF FREQUENCY = 2
227 BIS.B #2,&CSCTL1 ; Set 2MHZ DCORSEL
228 .ELSEIF FREQUENCY = 4
229 BIS.B #4,&CSCTL1 ; Set 4MHZ DCORSEL
230 .ELSEIF FREQUENCY = 8
231 BIS.B #6,&CSCTL1 ; Set 8MHZ DCORSEL
232 .ELSEIF FREQUENCY = 12
233 BIS.B #8,&CSCTL1 ; Set 12MHZ DCORSEL
234 .ELSEIF FREQUENCY = 16
235 BIS.B #10,&CSCTL1 ; Set 16MHZ DCORSEL
237 .error "bad frequency setting, only 1,2,4,8,12,16 MHz"
239 ; MOV #INT(FREQUENCY*1000000/32768)-1,&CSCTL2; set FLLD=0 (DCOCLKCDIV=DCO),set FLLN for frequency slight lower
240 MOV #INT(FREQUENCY*1000000/32768),&CSCTL2; set FLLD=0 (DCOCLKCDIV=DCO),set FLLN for frequency slight upper
241 MOV #128,X ; 128* 3 ms = 384 ms delay, because FLL lock time = 280 ms
242 ClockWaitX MOV &FREQ_KHZ,Y ;
243 ClockWaitY SUB #1,Y ;1
244 JNZ ClockWaitY ;2 FREQ_KHZ x 3 ==> 3ms