-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpot.s
More file actions
53 lines (50 loc) · 1.44 KB
/
pot.s
File metadata and controls
53 lines (50 loc) · 1.44 KB
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
;---------pot.s---------
ADCPSSI EQU 0X40038028
ADCRIS EQU 0X40038004
ADCSSFIFO3 EQU 0X400380A8
ADCISC EQU 0X4003800C
SRAM_BASE EQU 0x20000400
SRAM_SIZE EQU 30000
ADCSSMUX3 EQU 0X400380A0
;------------------------
AREA routines, CODE, READONLY
THUMB
EXPORT read_pot
switch_mux_to_pot PROC
PUSH {R0,R1,LR}
LDR R1,=ADCSSMUX3 ; make input source as AIN1(PE2) for sequencer 3
MOV R0,#0x01 ; select AIN1
STR R0,[R1]
POP {R0,R1,LR}
BX LR
ENDP
read_sample_to_R5 PROC
PUSH {R0,R2,R3,R4,R6,LR}
LDR R3, =ADCRIS ; interrupt address
LDR R4, =ADCSSFIFO3 ; result address
LDR R2, =ADCPSSI ; sample sequence initiate address
LDR R6,= ADCISC
; initiate sampling by enabling sequencer 3 in ADC0_PSSI
Smpl LDR R0, [R2]
ORR R0, R0, #0x08 ; set bit 3 for SS3
STR R0, [R2]
; check for sample complete (bit 3 of ADC0_RIS set)
Cont LDR R0, [R3]
ANDS R0, R0, #8
BEQ Cont
;branch fails if the flag is set so data can be read and flag is cleared
LDR R5, [R4] ;store the data
MOV R0, #8
STR R0, [R6] ; clear flag
POP {R0,R2,R3,R4,R6,LR}
BX LR
ENDP
read_pot PROC; start sampling routine
PUSH {LR}
BL switch_mux_to_pot
BL read_sample_to_R5
; store r5 to sram
MOV R10,R5
done POP {PC}
ENDP
END