Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

; GPIO base addresses of port D and E gpioFbase EQU 0 x 4 0 0 5 D 0 0 0 gpioEbase EQU 0 x

; GPIO base addresses of port D and E
gpioFbase EQU 0x4005D000
gpioEbase EQU 0x4005C000
gpioAbase EQU 0x40058000
gpioDbase EQU 0x4005B000
; PWM 0 base adress
pwm0base EQU 0x40028000
; PWM register offsets
pwmcc EQU 0x... ; TO DO
pwm0ctl EQU 0x... ; TO DO
pwm0gena EQU 0x... ; TO DO
pwm0genb EQU 0x... ; TO DO
pwm0load EQU 0x... ; TO DO
pwm0cmpa EQU 0x... ; TO DO
pwmenable EQU 0x... ; TO DO
; ADC 0 base adress
adc0base EQU 0x40038000
; ADC register offsets
adcactss EQU 0x000
adcemux EQU 0x014
adcssmux3 EQU 0x0A0
adcssemux3 EQU 0x0B8
adcssctl3 EQU 0x0A4
adcssfifo3 EQU 0x0A8
adcpssi EQU 0x028
; GPIO offsets, least significant 8 bits (mostly)
gpioData EQU 0x000 ; 'data' add relevant gpio data mask offset for masking, to read or write all values add 0x3FC to base which is sum of all bit constants
gpioDir EQU 0x400 ; 'direction' 0 for inp, 1 for out, inp by default
gpioAfsel EQU 0x420 ; 'alterrnate function select' 0 for standard gpio and gpio register used in this time, 1 for path over selected alternate hardware function, hardware function selection is done by gpiopctl register control, 0 default
gpioPctl EQU 0x52C ; 'port control' see documentation
gpioLock EQU 0x520 ; to unlock 0x4c4f434b shoulb be written, any other write locks back, enables write access to gpiocr
gpioCr EQU 0x524 ; 'commit' gpioafsel, pur, pdr, den can only be changed with setting bit in cr, only modified when unlock gpiolock
gpioAmsel EQU 0x528 ; 'analog mode select' only valid for pins of adc, set for analog,
gpioDen EQU 0x51c ; 'digital enable'
; GPIO data mask offset constant, [9:2] in address are ussed for [7:0] bits masking
; to only write to pin 5 of any port 'five' offset should be added to gpiodata
; to only write to pins 2 and 5 of any port data should be written dataregister address + 'two'+'five' offset address remainings left unchange in output 0 in input mode
gpioDataZero EQU 0x004
gpioDataOne EQU 0x008
gpioDataTwo EQU 0x010
gpioDataThree EQU 0x020
gpioDataFour EQU 0x040
gpioDataFive EQU 0x080
gpioDataSix EQU 0x100
gpioDataSeven EQU 0x200
; GPIO clck gating register
; default 0 and disabled by clck blocking
; bit #0 for port A and #1 for port B should be set to enable ports
; after setting 3 clck cycle is needed to reach port registers properly
rcgcgpio EQU 0x400FE608
rcgcpwm EQU 0x400FE640
rcgadc EQU 0x400FE638
delayData EQU 0x40000 ; use this delay data as the time spent on one frequency mode
highFreq EQU 0x00FFF ; use this value for high frequency mode
lowFreq EQU 0x01FFF ; use this value for low frequency mode
AREA MYCODE, CODE
ALIGN
ENTRY
EXPORT __main
__main
NOP
BL initialize
loop
LDR R1,=adc0base
ADD R1, R1, #adcpssi
LDR R0,[R1]
ORR R0, R0, #0x08 ; trigger ADC to start a conversion
STR R0,[R1]
LDR R1,=adc0base
ADD R1, #adcssfifo3
LDR R0,[R1] ; read 12-bit ADC output data, the converted value is now in R0
; TO DO: write the most significant 8 bit of converted value to port D
; TO DO: make necessary changes on the PWM registers so that the buzzer keeps changing its frequency,
; also control the volume of the buzzer with ADC output value
; don't worry about the PWM-buzzer connection, they will be connected physically
B loop
initialize
; enable clck for ports A, D, E and F
LDR R1,=rcgcgpio
LDR R0,[R1]
ORR R0, R0, #0x39 ;
STR R0,[R1]
NOP
NOP
NOP
LDR R1,=rcgcpwm ; enable PWM clock
LDR R0,[R1]
ORR R0, R0, #0x01 ; PWM0
STR R0,[R1]
NOP
NOP
NOP
LDR R1,=rcgadc ; enable ADC clock
LDR R0,[R1]
ORR R0, R0, #0x01 ; ADC0
STR R0,[R1]
NOP
NOP
NOP
; port A init
LDR R1,=gpioAbase
ADD R1, R1, #gpioDir
LDR R0,[R1]
ORR R0, R0, #0xFF
STR R0,[R1]
LDR R1,=gpioAbase
ADD R1, R1, #gpioAfsel
LDR R0,[R1]
BIC R0, #0xFF
STR R0,[R1]
LDR R1,=gpioAbase
ADD R1, R1, #gpioDen
LDR R0,[R1]
ORR R0, R0, #0xFF
STR R0,[R1]
; port D init
LDR R1,=gpioDbase
ADD R1, R1, #gpioDir
LDR R0,[R1]
ORR R0, R0, #0xFF
STR R0,[R1]
LDR R1,=gpioDbase
ADD R1, R1, #gpioAfsel
LDR R0,[R1]
BIC R0, #0xFF
STR R0,[R1]
LDR R1,=gpioDbase
ADD R1, R1, #gpioDen
LDR R0,[R1]
ORR R0, R0, #0xFF
STR R0,[R1]
; port F init
LDR R1,=gpioFbase
ADD R1, R1, #gpioDir
LDR R0,[R1]
ORR R0, R0, #0xFF
STR R0,[R1]
LDR R1,=gpioFbase
ADD R1, R1, #gpioAfsel
LDR R0,[R1]
ORR R0, #0x01 ; set for PWM0
STR R0,[R1]
LDR R1,=gpioFbase
ADD R1, R1, #gpioPctl
LDR R0,[R1]
ORR R0, #0x06 ; write 6 to select PWM from alternate functions
STR R0,[R1]
LDR R1,=gpioFbase
ADD R1, R1, #gpioDen
LDR R0,[R1]
ORR R0, R0, #0xFF
STR R0,[R1]
; port E init
LDR R1,=gpioEbase
ADD R1, R1, #gpioAfsel
LDR R0,[R1]
ORR R0, #0x08
STR R0,[R1]
LDR R1,=gpioEbase
ADD R1, R1, #gpioDen
LDR R0,[R1]
BIC R0, R0, #0x08
STR R0,[R1]
LDR R1,=gpioEbase
ADD R1, R1, #gpioAmsel
LDR R0,[R1]
ORR R0, R0, #0x08
STR R0,[R1]
; ADC init
LDR R1,=adc0base
ADD R1, R1, #adcactss ; bit field [3:0]->[SS3 enable, SS2 enable, SS1 enable, SS0 enable]
LDR R0,[R1]
BIC R0, R0, #0x08
STR R0,[R1]
LDR R1,=adc0base
ADD R1, R1, #adcemux ; bit field [15:0]-> SS3[0x0=processor triggered(adcpssi)],[SS2 trigger], SS1 trigger, SS0 trigger
LDR R0,[R1]
BIC R0, R0, #0xF000
STR R0,[R1]
LDR R1,=adc0base
ADD R1, R1, #adcssmux3 ; bit field [3:0]-> SS3 input select (if adcssemux3 bit is set, there is an offset of 16)
LDR R0,[R1]
BIC R0, R0, #0xF
STR R0,[R1]
LDR R1,=adc0base

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

Draw a picture consisting parts of monocot leaf

Answered: 1 week ago

Question

OUTCOME 5 Discuss sexual harassment as an employment equity issue.

Answered: 1 week ago