MC_C_Suggestions - Dr.
Gugel,
 



Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Dr.
Gugel,
 

 I
mentioned
after
class
on
Monday
that
there
were
a
few
quirks
to
writing
the
code
in
C.
To
start
off,
I
found
it
useful
to
not
use
 any
of
the
functions
TI
provided,
as
they
tend
to
do
much
more
than
we
need
in
our
limited
applications.
Without
proper
 modification
of
the
DSP2833x_Examples.h
file,
the
InitSysCtrl()
function
will
improperly
set
the
PLL
and
clock
divider
registers
 ,
giving
a
SYSCLKOUT
that
is
far
faster
than
the
7.5MHz
we
are
expecting.
The
function
below
can
instead
be
called
to
achieve
 the
desired
7.5MHz
SYSCLKOUT:
 

 void
initSYSCLKOUT(
void
)
 {
 





EALLOW;
 





SysCtrlRegs.PLLCR.bit.DIV
=
0;

















//Set
Pll
to
bypass
 





SysCtrlRegs.PLLSTS.bit.DIVSEL
=
2;













//Set
SysClkOut
to
OscClk/2
 





EDIS;
 }
 

 The
EALLOW;
and
EDIS;
commands
are
not
100%
necessary,
if
EALLOW
has
already
been
asserted
previous
to
calling
this
 function.
 

 In
order
to
properly
apply
one
of
the
most
valuable
functions
provided
by
TI,
the
DELAY_US(int
n)
function,
 DSP2833x_Examples.h
must
be
modified.
In
the
CPU_RATE
section,
all
defines
must
be
commented
out
except
for
the
 following,
which
is
to
be
added.
 

 #define
CPU_RATE

133.333L


//
for
a
7.5MHz
CPU
clock
speed
(SYSCLKOUT)
 

 Then,
the
student
may
call
DELAY_US(int
n);
in
their
code
to
insert
a
delay
of
n
µs.
This
comes
in
handy
when
talking
to
the
 LCD.
 

 In
talking
to
the
LCD,
it
is
also
necessary
to
write
directly
to
a
memory
location,
which
is
not
as
straightforward
in
C.
The
code
 below
allows
you
to
define
a
memory
location
as
a
pointer
and
then
write
to
it:
 

 int*
latch
=
(int*)0x4000;
 *latch
=
var;
















//could
be
immediate
value
(0x1234)
 

 Finally,
to
set
the
PIE
Vector
to
a
user‐defined
C
ISR
I
used
the
following:
 

 PieVectTable.SCIRXINTB
=
&scibRXISR;





//set
Vector
to
scibRXISR




 

 And
the
ISR
itself
was
defined
as
shown
below:
 

 interrupt
void
scibRXISR(
void
)
 {
 





//
interrupt
code
goes
here
 }
 

 I
hope
these
examples
can
be
helpful
for
those
writing
lab
code
in
C.
If
you
need
anything
else,
or
would
like
the
full
source
for
 lab
8,
let
me
know.
 

 Michael
R
Carroll
 ...
View Full Document

This document was uploaded on 07/11/2011.

Ask a homework question - tutors are online