Sie sind auf Seite 1von 74

PRIMER-TMS320F2812

TMS320F2812 Development Kit

User Manual

PANTECH PROLABS INDIA PVT LTD.


#41, Rajeshwari street , Santhosh Nagar, Kandhanchavadi, Chennai - 600 096
Ph : 044 64524445/46/47 | www.pantechsolutions.net
BRANCHES @ CHENNAI | COIMBATORE | MADURAI | HYDERABAD | BANGALORE | KOCHI

www.pantechsolutions.net

TMS320F2812

PS-PRIMER-TMS320F2812
TMS320F2812- Development Kit

Hardware & Software User Manual

www.pantechsolutions.net

TMS320F2812

HELP LINE & SUPPORT


Corporate Office

044 64524445/46/47

Website

www.pantechsolutions.net

Forum

To post your queries, problems and to discuss with the online


Community
https://www.pantechsolutions.net/forum

Blog

https://www.pantechsolutions.net/blog

YouTube

www.youtube.com/pantechsolutions[For Video Demos and


Animations]

Social Media Support :

Facebook ( To get notification of latest product update and event)


https://www.facebook.com/pantechsolutions
Twitter (To get notification of latest product update and event)
https://twitter.com/pantechsolution
Google+ (To get notification of latest product update and event)
https://plus.google.com/+pantechsolutions/posts
Linkedin (To get notification of latest product update and event)
http://www.linkedin.com/in/pantechsolutions
Slide share Tutorials [For Technical Presentations]
http://www.slideshare.net/pantechsolutions

E-Mail

For Order Enquiry, Sales & Support


sales@pantechsolutions.net

www.pantechsolutions.net

TMS320F2812

Contents

1. Introduction ............................................................................................................................................ 6
1.1 Packages ................................................................................................................................................. 6
1.2 Technical or Customer Support............................................................................................................. 6
2. Specifications .......................................................................................................................................... 7
2.1 General Block Diagram ........................................................................................................................... 9
2.2 TMS320F2812 Processor Features ..................................................................................................... 10
3. Connector Details.................................................................................................................................... 12
3.1 Expansion Connectors .......................................................................................................................... 12
3.2 SPI Connector ....................................................................................................................................... 13
3.3 ADC Connector ..................................................................................................................................... 13
3.4 Address and Data Bus Connector ........................................................................................................ 14
3.5 JTAG Connector .................................................................................................................................... 14
3.6 Jumper Details ...................................................................................................................................... 15
3.7 Test point Details.................................................................................................................................. 16
3.8 Boot mode Selection ............................................................................................................................ 16
4. Power Supply........................................................................................................................................... 17
5. On-board Peripherals ............................................................................................................................. 17
5. General Procedure to Work F2812 ........................................................................................................ 18
6. Code Composer Studio ........................................................................................................................... 20
6.1 Introduction of Code Composer Studio .............................................................................................. 20
6.2 Launching The Code Composer Studio V4 .......................................................................................... 20
6.3 Setting The Workspace Location ......................................................................................................... 20
6.4 Create a New Project ............................................................................................................................ 21
6.5 Add a Files to Project ........................................................................................................................... 26
6.6 Create a Target Configuration File ..................................................................................................... 28
6.7 Build a Project ...................................................................................................................................... 30
6.8 Run a project ........................................................................................................................................ 32
6.9 Console Window ................................................................................................................................... 35
6.10 Help ...................................................................................................................................................... 35

www.pantechsolutions.net

TMS320F2812

EXAMPLE PROGRAMS ON TMS320 KIT(TMS320F2812) ........................................................................... 36

Example 1: Running an LED.................................................................................................... 37


Example 2: Push Button and Led ........................................................................................... 39
Example 3: Switch and Led ..................................................................................................... 42
Example 4: Buzzer ................................................................................................................... 44
Example 5: Relay ..................................................................................................................... 46
Example 6: LCD ....................................................................................................................... 48
Example 7: UART..................................................................................................................... 52
Example 8: ADC ....................................................................................................................... 55
Example 9: PWMA .................................................................................................................. 60
Example 10: PWMB ................................................................................................................ 62
Example 11: SPI EEPROM AT25HP256 .................................................................................. 64
Example 12: SPI DAC MCP4921 ............................................................................................. 70

www.pantechsolutions.net

TMS320F2812

1. Introduction
Thank you for purchasing the PS-PRIMER-TMS320F2812 Kit. You will find it useful
in developing your TMS320F2812 application.
PRIMER-TMS320F2812 Kit, is proposed to smooth the progress of developing and
debugging of various designs encompassing of High speed 16-bit Architecture
from Texas Instrument. The board supports most of the TI components devices and some
peripheral options in the Code Composer Studio v4. It integrates on board LEDs, UART, Relays,
LCD Display, PWM Motor CONTROL Interface, ADC, SPI DAC, SPI EEPROM and CAN on board
XDS100 USB V1 EMULATOR.

1.1 Packages

PRIMER-TMS320F2812 Kit

USB CABLE

Serial Port Cable

5V Adapter

Printed User Manual

DVD contains
o

Software (Programmers, IDE) & Example Programs

1.2 Technical or Customer Support


E-mail questions to
support@pantechsolutions.net
Send questions by mail to

Tel
Mobile
Website

Pantech Prolabs India Pvt Ltd,


#41, Rajeswari Street,
Santhosh Nagar,
Kandanchavadi,
OMR, Chennai 600 096,
Tamil Nadu, India.
: 044 64524445/46/47
: 9840974408
: www.pantechsolutions.net
www.pantechsolutions.net

TMS320F2812

2. Specifications
MCU

Texas Instrument TMS320, TMS320F2812 ( 16 Bit


DSC )

Memory

Flash Devices: Up to 128K x 16 Flash


(Four 8K x 16 and Six 16K x 16 Sectors)
ROM Devices: Up to 128K x 16 ROM
1K x 16 OTP ROM
L0 and L1: 2 Blocks of 4K x 16 Each Single-Access
RAM (SARAM)
H0: 1 Block of 8K x 16 SARAM
M0 and M1: 2 Blocks of 1K x 16 Each SARAM

Clock

25MHz crystal
(125MHz CPU clock)

On-Board

On Board XDS100 USB Emulator V1

Peripherals

8 Nos. LEDs

4 Nos. Digital Input(Slide Switch)

8 Push Switch

2X16 Character LCD with back Light

4 Nos. Analog Input (Potentiometer)

256k SPI EEPROM

12 bit SPI DAC

CAN Interface to study

1 Nos. of SPDT Relay

UART(RS232) interface

Buzzer (Alarm)

Boot Mode Options

www.pantechsolutions.net

TMS320F2812

Power

5V DC- Adaptor,
Power from USB (+5V) (+3.3V, 800mA)

Connectors

1 Nos. 50 Pin Address & Data lines connector

3 Nos.20 Pin Port Connectors

External SPI Connectors

JTAG (Programming/ Debugging)

RS232 Connector (Serial Port)

20 PIN Expansion Connector

External Analog Input Connector

External Relay Input Connector

Power Connector

USB Connector

SPI DAC Connector

CAN Connector

www.pantechsolutions.net

TMS320F2812

2.1 General Block Diagram

5V Input
1.8V&3.3V

XDS 100 USB V1


EMULATOR

JTAG
Port

RELAY

4 Nos
Slide Switch

2x16 LCD

14Pin PortD/E/G
Connector

SPI DAC Output

TMS320F2812
20Pin Port A
Connector

PWM Motor
Driver Connector

20Pin Port B
Connector

25 MHZ CRYSTAL

20Pin Port F
Connector

SPI EEPROM

On-Board Analog
Inputs

CAN

Buzzer

8 Nos PUSH
Switch

8 Nos
LEDs

www.pantechsolutions.net

RS232

TMS320F2812

2.2 TMS320F2812 Processor Features

16-bit Digital Signal Controller CPU from TEXAS Instruments in a 176 pin LQFP package.

High-Performance Static CMOS Technology


o

150 MHz (6.67-ns Cycle Time)

150 MHz (6.67-ns Cycle Time) 1.9-V Core @150 MHz, 3.3-V I/O) Design

JTAG Boundary Scan Support

High-Performance 32-Bit CPU ( TMS320C28x)

10

16 x 16 and 32 x 32 MAC Operations

16 x 16 Dual MAC

Harvard Bus Architecture

Atomic Operations

Fast Interrupt Response and Processing

Unified Memory Programming Model

4M Linear Program/Data Address Reach

Code-Efficient (in C/C++ and Assembly)

TMS320F24x/LF240x Processor Source Code Compatible

On-Chip Memory
o

Flash Devices: Up to 128K x 16 Flash (Four 8K x 16 and Six 16K x 16 Sectors)

ROM Devices: Up to 128K x 16 ROM

1K x 16 OTP ROM

L0 and L1: 2 Blocks of 4K x 16 Each Single-Access RAM (SARAM)

H0: 1 Block of 8K x 16 SARAM

M0 and M1: 2 Blocks of 1K x 16 Each SARAM

Boot ROM (4K x 16)


o

With Software Boot Modes

Standard Math Tables

External Interface (2812)


o

Over 1M x 16 Total Memory

Programmable Wait States

Programmable Read/Write Strobe Timing

Three Individual Chip Selects

Clock and System Control


o

Dynamic PLL Ratio Changes Supported

On-Chip Oscillator
www.pantechsolutions.net

TMS320F2812

Watchdog Timer Module

Three External Interrupts

Peripheral Interrupt Expansion (PIE) Block That Supports 45 Peripheral Interrupts

Three 32-Bit CPU-Timers

128-Bit Security Key/Lock

Protects Flash/ROM/OTP and L0/L1 SARAM

Prevents Firmware Reverse-Engineering

Motor Control Peripherals


o

Two Event Managers (EVA, EVB)

Compatible to 240xA Devices

Serial Port Peripherals


o

Serial Peripheral Interface (SPI)

Two Serial Communications Interfaces (SCIs), Standard UART

Enhanced Controller Area Network (eCAN)

Multichannel Buffered Serial Port (McBSP)

12-Bit ADC, 16 Channels


o

2 x 8 Channel Input Multiplexer

Two Sample-and-Hold

Single/Simultaneous Conversions

Fast Conversion Rate: 80 ns/12.5 MSPS

Up to 56 General-Purpose I/O (GPIO) Pins

Advanced Emulation Features

11

Analysis and Breakpoint Functions

Real-Time Debug via Hardware

Real-Time Debug via Hardware


o

ANSI C/C++ Compiler/Assembler/Linker

Code Composer Studio IDE

DSP/BIOS

JTAG Scan Controllers

Low-Power Modes and Power Savings


o

IDLE, STANDBY, HALT Modes Supported

Disable Individual Peripheral Clocks

www.pantechsolutions.net

TMS320F2812

3. Connector Details
3.1 Expansion Connectors

12

www.pantechsolutions.net

TMS320F2812

3.2 SPI Connector

3.3 ADC Connector

13

www.pantechsolutions.net

TMS320F2812

3.4 Address and Data Bus Connector

3.5 JTAG Connector

14

www.pantechsolutions.net

TMS320F2812

3.6 Jumper Details

Power supply

Adapter (+5V)

usb cable(+5V)

Micro controller mode select

Micro processor mode select

PLL Disable

PLL Enable

No connection

Chip select - GPIOG5

J2
XMP/MC
J7
PLLDIS
J6
SPI EEPROM
J15
SPI EEPROM

Write Protect pin for SPI EEPROM

J16

WP
Dont place jumper.

SPI DAC
J18

PORT A
J20
PORT B
J21
PORTD/E/G
J22

15

Chip Select SPI Enable pin


Chip Select GPIOG4 pin
3.3V select for expansion connector
5V select for expansion connector
3.3V select for expansion connector
5V select for expansion connector
3.3V select for expansion connector
5V select for expansion connector

www.pantechsolutions.net

TMS320F2812

3.7 Test point Details


The following test points are used to check or test the boards,
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

TP1 ADCREFIN
TP2 READ/WRITE
TP3 5V
TP4 3.3V
TP5 1.8V
TP6 GROUND
TP7 RESET
TP8 XCLK IN
TP9 XCLC OUT
TP10 CLKOUT

3.8 Boot mode Selection


The Boot ROM is factory-programmed with boot-loading software. The Boot ROM program executes
after device reset and checks several GPIO pins to determine which boot mode to enter. For example,
the user can select to execute code already present in the internal Flash or download new
software to internal RAM through one of several serial ports. Other boot modes exist as well.
BOOT MODE SELECTED
GPIO PU status(3)
Jump to Flash/ROM address 0x3F 7FF6.
Call SPI_Boot to load from an external serial SPI
EEPROM
Call SCI_Boot to load from SCI-A
Jump to H0 SARAM address 0x3F 8000
Jump to OTP address 0x3D 7800
Call Parallel_Boot to load from GPIO Port B

GPIOF4
(SCITXDA)
PU
1
0

GPIOF12
(MXDA)
NO PU
x
1

GPIOF3
(SPISTEA)
NO PU
x
x

GPIOF2
(SPICLK)
NO PU
x
x

0
0
0
0

0
0
0
0

1
1
0
0

1
0
1
0

Note: PU = pin has an internal pullup.


No PU = pin does not have an internal pullup.
1 = high logic (3.3v)
0 = low logic (0v)
x = Either High / Low Logic

16

www.pantechsolutions.net

TMS320F2812

4. Power Supply
The external power can be DC, with a voltage 5V/1A output at 230V AC input. The TMS320F2812
board produces 3.3V were using an ADP3339 voltage regulator, This Voltage providing supply to
the Controller & related peripherals. LM1117 voltage regulator will produce the 1.8V and used
for core voltage of Digital Signal Controller. Here, USB meant for power supply as well as XDS100
USB V1 Emulator. Separate power source select Jumper available.
PWR

ON

SW1

OFF

On/Off Switch (SW1) for controlling power to the board.


Note: Refer Jumper table for power source select

5. On-board Peripherals
This Development kit comes with following interfacing options

On Board XDS100 USB V1 Emulator

8 Number LEDs

4 Number Digital Input(Slide Switch)

8 Push Switch Digital Input

16x2 Character LCD with back Light

4 Number Analog Input (Potentiometer)

256k SPI EEPROM

12 bit SPI DAC

CAN Interface to study

1 Number of SPDT Relay

UART(RS232) interface

Buzzer (Alarm)

Boot Mode Options (SARAM/FLASH)

17

www.pantechsolutions.net

TMS320F2812

5. General Procedure to Work F2812

1. Open Code Composer Studio v4.


2. In Workspace Launcher.
a. BROWSE Select the project location and make one new folder, MAKE NEW
FOLDER Type the Workspace name, OK OK.
3. FILE NEW CCS PROJECT
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.

Project name: Type your project name.


Tick use default location. NEXT
Project type: C2000.
Tick Debug and Release. NEXT NEXT.
Output type: Executable.
Device Variant: generic C28xx Device and TMS320F2812.
Device Endianness : little
Code Generation Tools: TI v5.2.3.
Run time support library: automatic.
Target content: none.
FINISH

4. FILE NEW SOURCE FILE


a. Source file: Type your projectname.c (.c extension is must).
b. Type the program.
c. FILE SAVE.
5. Paste the following library files in Project location.
a.
DSP281x_CpuTimers.c
b.
DSP281x_DefaultIsr.c
c.
DSP281x_GlobalVariableDefs.c
d.
DSP281x_PieCtrl.c
e.
DSP281x_PieVect.c
6. Paste the following Linker file in the project location.
a.
DSP281x_Headers_nonBIOS.cmd
b.
F2812_EzDSP_RAM_lnk.cmd
Note: Those c files and linker files are available at cd.

18

www.pantechsolutions.net

TMS320F2812

7. PROJECT PROPERTIES C/C++ BUILD BASIC OPTION


a. Target processor version(--silicon version, -mv) : 28
b. IN C/C++ BUILD, INCLUDE OPTIONS (Add dir to #include search path (-include path,-I)) select this add icon and add the following two path by
individually.
"${XDAIS_CG_ROOT}/packages/ti/xdais"
"C:/tidcs/c28/DSP281x/v120/DSP281x_headers/include
c. IN C/C++ BUILD, c2000 linker ->file search path (Add dir to #include search
path(--include path,-I)) select this add icon
path by individually.

and add the following three

"rts2800_ml.lib"
"${PROJECT_ROOT}"
"C:\Program Files\Texas Instruments\ccsv4\tools\compiler\c2000\lib"
8. FILE NEW TARGET CONFIGURATION FILE
a.
b.
c.

file name: projectname. ccxml (.ccxml extension is must)


Connection: Texas Instrument XDS100 v1 USB Emulator.
Device: TMS320C2812. SAVE.

7. In C/C++ Project window, Right click the project REBUILD PROJECT.


8. Connections:
d. Connect the usb cable, PC to KIT.
e. Connect the 5v adapter and Power on the kit.
TARGET DEBUG ACTIVE PROJECT.(Then see out at corresponding place after run)

19

www.pantechsolutions.net

TMS320F2812

6. Code Composer Studio


6.1 Introduction of Code Composer Studio
Code Composer Studio Integrated Design Environment for the C2000 Family of Texas
Instruments Digital Signal Processors. Simply, Code Composer Studio is the environment for project
development for all tools needed to build an application for the C2000-Family.
The objective of this module is to understand the basic functions of the Code Composer Studio
v4, how to create and debug a project in CCS v4 for TMS320F2812/F28335 kit. This following section will
introduces some of the basic features and functions in Code Composer Studio so you can create and
build simple projects. Experienced users can proceed to the following sections for more in-depth
explanations of Code Composer Studios various features.
Finally, you will able to work the TYRO-TMS320F2812/TMS320F28335/TMS320F28069 kit with CCS v4

6.2 Launching The Code Composer Studio V4


Click this icon shown
on your desktop. A prompt will appear asking for a workspace
location. To launch Code Composer Studio IDE for the first time, configure Code Composer Studio for a
fixed workspace location.

6.3 Setting The Workspace Location


To create a workspace location using standard configuration file:

1. Double-click the

Setup CCStudio icon on desktop.

The workspace launcher dialog box appears.


Note: Be sure that workspace location is empty for a fresh project

20

www.pantechsolutions.net

TMS320F2812

2. Tick the use this as the default and do not ask again (Optional).
Note: Again to get the workspace launcher at startup. open ccs go to window preference general
startup and shutdown tick prompt for workspace on startup.
3. Click ok.
4. The empty workspace editor will open.

6.4 Create a New Project


To create a project, follow these steps:
1. Launch Code Composer Studio. See Chapter 2
2. From the CCStudio File menu, choose New CCS Project.

New CCS Project dialog box appears.

21

www.pantechsolutions.net

TMS320F2812

3. In the Project Name field, type the project name & click Next.
4. Tick the use default Location field, type or browse to the folder you created as workspace
location. Click Next.

22

www.pantechsolutions.net

TMS320F2812

5. In the Project type field, Select C2000.


6. Tick Debug and Release in configuration box. Click Next.
7. Then also, click next.
8. In output Type, select the Executable.

9. In Device Variant, Choose TMS320C28XX & TMS320F2812.


10. Click Finish. Code Composer Studio creates a project file called practice.pjt. This file stores your
project settings and references the various files used by your project.

23

www.pantechsolutions.net

TMS320F2812

11. From the CCStudio C/C++ Projects, Right click the led [Active Debug] New Source File.

12. In the source file field, Type the source file name with extension. (led.c)

24

www.pantechsolutions.net

TMS320F2812

Click Finish.

Type the program in led.c editor window then, File Save.

25

www.pantechsolutions.net

TMS320F2812

6.5 Add a Files to Project


After creating the project and source file we must add some addition files to our project. These
addition files may vary depend upon the projects which we used.
Create/add new source files to your project by right-clicking on the project in the C/C++
Projects
1. From the CCStudio C/C++ Projects, Right click the led [ Active Debug ] Select the Add files to
project or you can directly paste the needed files to the project location, if you paste these files
in project location then no need to proceed Add files to project step.

a. Paste the following library C files in project location.


i. DSP281x_CpuTimers.c
ii. DSP281x_DefaultIsr.c
iii. DSP281x_GlobalVariableDefs.c
iv. DSP281x_PieCtrl.c
v. DSP281x_PieVect.c
b. Paste the following Linker file in the project location.
i. DSP281x_Headers_nonBIOS.cmd
ii. F2812_EzDSP_RAM_lnk.cmd
Note: Those c files and linker files are available at DVD.

26

www.pantechsolutions.net

TMS320F2812

Then browse and select all the needed files.

Click Open. The selected all the files are added to your project.

27

www.pantechsolutions.net

TMS320F2812

6.6 Create a Target Configuration File


1. From the CCStudio C/C++ Projects, Right click the led [Active Debug] New Source File.

2. New Target Configuration dialog appears. Then Click Finish

28

www.pantechsolutions.net

TMS320F2812

NewTargetConfiguration.ccxml will open, This will help to communicate between hardware and
software. While connecting the hardware to the software the target configuration file will run. If any
initialize needed we can add gel file additionally in the target configuration.
3.

In General setup, there is more connection available to choose. According to our board, we
have to choose XDS 100 USB emulator version 1 and TMS320F2812 (Target Device).

4. Tick the TMS320F2812 & Click Save.

29

www.pantechsolutions.net

TMS320F2812

6.7 Build a Project


Before Building the project we must modify project properties, add the include files and path
according to our usage.
1. From the CCStudio C/C++ Projects, Right click the led [Active Debug] Properties.
2. In C/C++ Build, go to C2000 compiler
a. Include Options (Add dir to #include search path (--include_path,-I)) select this add icon
and add the following three path by individually.
"${XDAIS_CG_ROOT}/packages/ti/xdais"
"C:/tidcs/c28/DSP281x/v120/DSP281x_headers/include"

30

www.pantechsolutions.net

TMS320F2812

3. IN C/C++ Build, go to c2000 linker


a. Basic option - stack size - 0x400.
b. Include library file or command file as input (--library,-I)
"rts2800_ml.lib"
c. file search path (Add <dir> to library search path(--include_path,-i)) select this add icon
and add the following three path by individually.
"${PROJECT_ROOT}"
"C:\Program Files\Texas Instruments\ccsv4\tools\compiler\c2000\lib"

4. From the CCStudio C/C++ Projects, Right click the led [Active Debug] Build Project or Rebuild
Project.
Note: Once the project is successfully build you will get 0 Errors. If Error arise check the code and project
properties then rebuild the project.

31

www.pantechsolutions.net

TMS320F2812

6.8 Run a project


To run a project,
1. Target Debug Active Project.

Note: at this step Target will connect, gel file will run, led. out will load to target then finally Keep the
cursor at main () of program to start execute.

32

www.pantechsolutions.net

TMS320F2812

2. This is Debug workspace, at this we can debug a code using breakpoints, single stepping, watch
window, memory etc..,

33

www.pantechsolutions.net

TMS320F2812

3. Target Run.
For led code, check the output on board. The Leds is will on and off with few delay.
4. Target Halt.

5. Target Terminate all.

34

www.pantechsolutions.net

TMS320F2812

Again the ccs will return to edit workspace from debug workspace.

6. Close the Code composer studio.

6.9 Console Window


The Output window is located at the bottom of the screen by default. By default, the printf
function displays in console window, showing information such as the contents of Stdout and the build
log.

6.10 Help
Code Composer Studio provides many help tools through the Help menu. Select Help Contents
to search by contents. Select Help Tutorial to access tutorials to guide you through the Code Composer
Studio development process.
Select Help Web Resources to obtain the most current help topics and other guidance. User
manuals are PDF files that provide information on specific features or processes. You can access updates
and a number of optional plug-ins through Help Update Advisor.

35

www.pantechsolutions.net

TMS320F2812

EXAMPLE PROGRAMS ON TMS320


KIT(TMS320F2812)

36

www.pantechsolutions.net

TMS320F2812

Example 1: Running an LED


Project Description:
This example code shows the indication of LED On/Off. By driving a High logic to output
port pin illuminate an LED. Driving High and Low logic with delay LED turns on and off
alternatively.
Hardware Connections:
HARDWARE PIN OUT
D2
D3
D4
D5
D6
D7
D8
D9

GPIOF7
GPIOF8
GPIOF9
GPIOF10
GPIOF11
GPIOF12
GPIOF13
GPIOF14

CONNECTIONS

OUTPUT

Select the 2nd Switch SW11


to Enable Led

LEDs will be Turned ON


and OFF at regular
interval.

Source Code:
Running LED on TMS320F2812 Kit
#include "DSP281x_Device.h"
#define
#define
#define
#define
#define
#define
#define
#define

LED1
LED2
LED3
LED4
LED5
LED6
LED7
LED8

GpioDataRegs.GPFDAT.bit.GPIOF7
GpioDataRegs.GPFDAT.bit.GPIOF8
GpioDataRegs.GPFDAT.bit.GPIOF9
GpioDataRegs.GPFDAT.bit.GPIOF10
GpioDataRegs.GPFDAT.bit.GPIOF11
GpioDataRegs.GPFDAT.bit.GPIOF12
GpioDataRegs.GPFDAT.bit.GPIOF13
GpioDataRegs.GPFDAT.bit.GPIOF14

// Prototype statements for functions found within this file.


void delay_loop(long);
void Gpio_select(void);
void InitSystem(void);
void main(void)
{
unsigned int i;
unsigned int LED[8]= {0x0001,0x0002,0x0004,0x0008,
0x0010,0x0020,0x0040,0x0080};
InitSystem();
// Initialize the DSP's core Registers
Gpio_select();
// Setup the GPIO Multiplex Registers

37

www.pantechsolutions.net

TMS320F2812

while(1)
{
for(i=0;i<14;i++)
{
if(i<7)
GpioDataRegs.GPFDAT.all = ((LED[i])<<7);
else
GpioDataRegs.GPFDAT.all = ((LED[14-i])<<7);
delay_loop(10000000);
}
}
}
void delay_loop(long end)
{
long i;
for (i = 0; i < end; i++);
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPFMUX.all = 0x0;
GpioMuxRegs.GPFDIR.all = 0x7F80;
EDIS;
}

// GPIO PORT

as input

void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10; // Setup the Clock PLL to Xly by 5
SysCtrlRegs.HISPCP.all = 0x1; // HSPCP Prescaler to divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // LSPCP Prescaler to divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The Led Will On and Off alternatively.

38

www.pantechsolutions.net

TMS320F2812

Example 2: Push Button and Led


Project Description:
This example code shows the indication of LED according to push button state. By
reading a push button state from PORTA and PORTB and writing the corresponding value to
PORTF illuminates an LED.
Hardware Connections:
HARDWARE PIN OUT
D2
D3
D4
D5
D6
D7
D8
D9
SW3
SW4
SW5
SW6
SW7
SW8
SW9
SW10

GPIOF7
GPIOF8
GPIOF9
GPIOF10
GPIOF11
GPIOF12
GPIOF13
GPIOF14
GPIOA11
GPIOA12
GPIOA13
GPIOA14
GPIOB11
GPIOB12
GPIOB13
GPIOB14

CONNECTIONS

OUTPUT

Select the 2nd Switch SW11


to Enable Led
LEDs will be Turned OFF
according to switch state.

Source Code:
Push Button and Led on TMS320F2812 Kit
#include "DSP281x_Device.h"
#define
#define
#define
#define

SW1
SW2
SW3
SW4

#define
#define
#define
#define
#define
#define
#define

LED1
LED2
LED3
LED4
LED5
LED6
LED7

39

GpioDataRegs.GPDDAT.bit.GPIOD0
GpioDataRegs.GPDDAT.bit.GPIOD1
GpioDataRegs.GPDDAT.bit.GPIOD5
GpioDataRegs.GPDDAT.bit.GPIOD6
GpioDataRegs.GPFDAT.bit.GPIOF7
GpioDataRegs.GPFDAT.bit.GPIOF8
GpioDataRegs.GPFDAT.bit.GPIOF9
GpioDataRegs.GPFDAT.bit.GPIOF10
GpioDataRegs.GPFDAT.bit.GPIOF11
GpioDataRegs.GPFDAT.bit.GPIOF12
GpioDataRegs.GPFDAT.bit.GPIOF13
www.pantechsolutions.net

TMS320F2812

#define LED8 GpioDataRegs.GPFDAT.bit.GPIOF14


#define
#define
#define
#define
#define
#define
#define
#define

BUTTON1
GpioDataRegs.GPADAT.bit.GPIOA11
BUTTON2
GpioDataRegs.GPADAT.bit.GPIOA12
BUTTON3
GpioDataRegs.GPADAT.bit.GPIOA13
BUTTON4
GpioDataRegs.GPADAT.bit.GPIOA14
BUTTON5
GpioDataRegs.GPBDAT.bit.GPIOB11
BUTTON6
GpioDataRegs.GPBDAT.bit.GPIOB12
BUTTON7
GpioDataRegs.GPBDAT.bit.GPIOB13
BUTTON8 GpioDataRegs.GPBDAT.bit.GPIOB14

// Prototype statements for functions found within this file.


void delay_loop(long);
void Gpio_select(void);
void InitSystem(void);
void main(void)
{
InitSystem();
Gpio_select();

// Initialize the DSP's core Registers


// Setup the GPIO Multiplex Registers

while(1)
{
LED1 = BUTTON1;
LED2 = BUTTON2;
LED3 = BUTTON3;
LED4 = BUTTON4;
LED5 = BUTTON5;
LED6 = BUTTON6;
LED7 = BUTTON7;
LED8 = BUTTON8;
delay_loop(1000000);
}
}
void delay_loop(long end)
{
long i;
for (i = 0; i < end; i++);
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all = 0x0;
GpioMuxRegs.GPBMUX.all = 0x0;
GpioMuxRegs.GPFMUX.all = 0x0;

// all GPIO port Pin's to I/O

GpioMuxRegs.GPADIR.all = 0x0;
// GPIO PORT
GpioMuxRegs.GPBDIR.all = 0x0;
// GPIO Port
GpioMuxRegs.GPFDIR.all = 0x7F80;// GPIO PORT
EDIS;

40

www.pantechsolutions.net

as input
as OUTPUT

TMS320F2812

}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to multiply
by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The Led Will Off according to push button state.
41

www.pantechsolutions.net

TMS320F2812

Example 3: Switch and Led


Project Description:
This example code shows the indication of LED according to SWITCH state. By Reading a
switch state from PORTD and writing the corresponding value to PORTF illuminates an LED.
Hardware Connections:
HARDWARE PIN OUT
D2
D3
D4
D5
SW12
SW13
SW14
SW15

GPIOF7
GPIOF8
GPIOF9
GPIOF10
GPIOD0
GPIOD1
GPIOD5
GPIOD0

CONNECTIONS
Select the 2nd Switch SW11
to Enable Led

OUTPUT

LEDs will be Turned ON


according to switch state.

Source Code:
Switch and Led on TMS320F2812 Kit
#include "DSP281x_Device.h"
#define
#define
#define
#define

SW1
SW2
SW3
SW4

#define
#define
#define
#define

LED1
LED2
LED3
LED4

GpioDataRegs.GPDDAT.bit.GPIOD0
GpioDataRegs.GPDDAT.bit.GPIOD1
GpioDataRegs.GPDDAT.bit.GPIOD5
GpioDataRegs.GPDDAT.bit.GPIOD6
GpioDataRegs.GPFDAT.bit.GPIOF7
GpioDataRegs.GPFDAT.bit.GPIOF8
GpioDataRegs.GPFDAT.bit.GPIOF9
GpioDataRegs.GPFDAT.bit.GPIOF10

// Prototype statements for functions found within this file.


void delay_loop(long);
void Gpio_select(void);
void InitSystem(void);
void main(void)
{
InitSystem();

// Initialize the DSP's core Registers

Gpio_select();

// Setup the GPIO Multiplex Registers

while(1)
{

42

www.pantechsolutions.net

TMS320F2812

LED1 = SW1;
LED2 = SW2;
LED3 = SW3;
LED4 = SW4;
delay_loop(1000000);
}
}
void delay_loop(long end)
{
long i;
for (i = 0; i < end; i++);
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPDMUX.all = 0x0;
GpioMuxRegs.GPFMUX.all = 0x0;
GpioMuxRegs.GPDDIR.all = 0x0;
// GPIO PORT
GpioMuxRegs.GPFDIR.all = 0x0780;// GPIO PORT
EDIS;

as input
as input

}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10; // Setup the Clock PLL to xly by 5
SysCtrlRegs.HISPCP.all = 0x1; // HSPCP Prescaler to divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // LSPCP Prescaler to divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The Led Will On or Off according to switch state.
43

www.pantechsolutions.net

TMS320F2812

Example 4: Buzzer
Project Description:
This example code shows to power up the buzzer using GPIO line. By driving a High logic
to port pin, buzzer will sound. Driving High and Low logic with delay buzzer will On and Off
alternatively.
Hardware Connections:

HARDWARE PIN OUT


BUZZER
LS1

GPIOE0

CONNECTIONS

OUTPUT

Select the 3rd Switch SW11


to Enable Buzzer

Buzzer will be Turned ON


and OFF at regular
interval.

Source Code:
Buzzer on TMS320F2812 Kit
#include "DSP281x_Device.h"
#define BUZZER
#define ON
#define OFF

GpioDataRegs.GPEDAT.bit.GPIOE0
1
0

// Prototype statements for functions found within this file.


void delay_loop(long);
void Gpio_select(void);
void InitSystem(void);
void main(void)
{
unsigned int i=0;
InitSystem();
Gpio_select();

// Initialize the DSP's core Registers


// Setup the GPIO Multiplex Registers

while(i<15)
{
BUZZER = ON;
delay_loop(1000000);
BUZZER = OFF;
delay_loop(1000000);
i++;
}
}

44

www.pantechsolutions.net

TMS320F2812

void delay_loop(long end)


{
long i;
for (i = 0; i < end; i++);
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPEMUX.all = 0x0;
GpioMuxRegs.GPEDIR.all = 0x1;
EDIS;
}

// GPIO PORT

as input

void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The Buzzer Will On and Off alternatively.

45

www.pantechsolutions.net

TMS320F2812

Example 5: Relay
Project Description:
This example code shows to power up the Relay using GPIO line. By driving a High logic
to port pin, relay will on. Driving High and Low logic with delay relay will On and Off
alternatively.
Hardware Connections:
HARDWARE PIN OUT
Relay

GPIOE2

CONNECTIONS

OUTPUT

Select the 4th Switch SW11


to Enable Relay

5 Times Relay will be


Turned ON and OFF at
regular interval.

Source Code:
Relay on TMS320F2812 Kit
#include "DSP281x_Device.h"
#define RELAY
#define ON
#define OFF

GpioDataRegs.GPEDAT.bit.GPIOE1
1
0

// Prototype statements for functions found within this file.


void delay_loop(long);
void Gpio_select(void);
void InitSystem(void);
void main(void)
{
unsigned int i=0;
InitSystem();

// Initialize the DSP's core Registers

Gpio_select();

// Setup the GPIO Multiplex Registers

while(i<5)
{
RELAY = ON;
delay_loop(10000000);
RELAY = OFF;
delay_loop(10000000);
i++;
}
}

46

www.pantechsolutions.net

TMS320F2812

void delay_loop(long end)


{
long i;
for (i = 0; i < end; i++);
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPEMUX.all = 0x0;
GpioMuxRegs.GPEDIR.all = 0x2;
EDIS;
}

// GPIO PORT

as input

void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The Relay Will On and Off alternatively.
47

www.pantechsolutions.net

TMS320F2812

Example 6: LCD
Project Description:
This example code shows the string on LCD.
Hardware Connections:
HARDWARE PIN OUT
RS

GPIOF8

RW
E
D0-D3
D4

GND
GPIOF9
NC
GPIOF10

D5
D6
D7

GPIOF11
GPIOF12
GPIOF13

CONNECTIONS

OUTPUT

Turn ON the corresponding


switch for LCD in +5V selt

It displays a string

Note: The TMS320F2812 Kit have 2x16 LCD. Seven pins are needed to create 4-bit interface; 4 data bits
(GPIOF10 to GPIOF13, D4-D7), address bit (RS-GPIOF8), read/write bit (R/W- gnd) and control signal (EGPIOF9). C2148 Education Board - Users Guide Page 25
The LCD is powered by 5V power supply from the switch SW11.

Source Code:
LCD on TMS320F2812 Kit
#include "DSP281x_Device.h"
#define RS GpioDataRegs.GPFDAT.bit.GPIOF8
#define EN GpioDataRegs.GPFDAT.bit.GPIOF9
#define DATA_PORT
void
void
void
void
void

GpioDataRegs.GPFDAT.all

LCD_init(void);
LCD_cmd(unsigned char);
LCD_dat(unsigned char);
delay_ms(long end);
InitSystem();

unsigned char i,temp;


const unsigned char Msg1[] = "16x2 LCD Test...";
const unsigned char Msg2[] = "F2812 EVB BOARD ";
void main()

48

www.pantechsolutions.net

TMS320F2812

{
InitSystem();
EALLOW;
GpioMuxRegs.GPFMUX.bit.MCLKXA_GPIOF8 = 0; // Muxing port Pin's to I/O
GpioMuxRegs.GPFMUX.bit.MCLKRA_GPIOF9 = 0;
GpioMuxRegs.GPFMUX.bit.MFSXA_GPIOF10 = 0;
GpioMuxRegs.GPFMUX.bit.MFSRA_GPIOF11 = 0;
GpioMuxRegs.GPFMUX.bit.MDXA_GPIOF12 = 0;
GpioMuxRegs.GPFMUX.bit.MDRA_GPIOF13 = 0;
GpioMuxRegs.GPFDIR.bit.GPIOF8 = 1;
/Muxing port as ouput
GpioMuxRegs.GPFDIR.bit.GPIOF9 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF10 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF11 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF12 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF13 = 1;
LCD_init();
delay_ms(20000);
while(1)
{
LCD_cmd(0x01);
delay_ms(5000000);
LCD_cmd(0x80);
for(i=0;i<16;i++)
{
LCD_dat(Msg1[i]);
delay_ms(1000000);
}

// First line

LCD_cmd(0xc0);
for(i=0;i<16;i++)
{
LCD_dat(Msg2[i]);
delay_ms(1000000);
}

// Second Line

}
}

void LCD_init(void)
{
delay_ms(100);
LCD_cmd(0x33);
LCD_cmd(0x32);
delay_ms(500);
LCD_cmd(0x28);
D4-D7 MSB Lines.
LCD_cmd(0x0c);
LCD_cmd(0x06);
LCD_cmd(0x01);
}

49

// 38 for 8 data lines , 28 for 4 data lines use

www.pantechsolutions.net

TMS320F2812

void LCD_cmd(unsigned char cmd)


{
temp = ((cmd & 0xF0)>>4);
DATA_PORT = temp << 10;
RS = 0;
EN = 1;
delay_ms(3000);
EN = 0;
temp = cmd & 0x0F;
DATA_PORT = temp << 10;
RS = 0;
EN = 1;
delay_ms(3000);
EN = 0;
}
void LCD_dat(unsigned char byte)
{
temp = ((byte & 0xF0)>>4);
DATA_PORT = temp << 10;
RS = 1;
EN = 1;
delay_ms(3000);
EN = 0;
temp = byte & 0x0F;
DATA_PORT = temp << 10;
RS = 1;
EN = 1;
delay_ms(3000);
EN = 0;
}
void InitSystem()
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x0068 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;

50

www.pantechsolutions.net

TMS320F2812

SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}
void delay_ms(long end)
{
long i;
for (i = 0; i < end; i++);
}

Verify Output:
The Strings are displayed at LCD.

51

www.pantechsolutions.net

TMS320F2812

Example 7: UART
Project Description:
This example code shows the character on hyper terminal in pc.
Hardware Connections:
HARDWARE PIN OUT
SCIATX

GPIOF4

SCIARX

GPIOF5

SCIBTX

GPIOG4

SCIBRX

GPIOG5

CONNECTIONS

OUTPUT

Make switch 1 & 2 in SW16


for UART A(SCIA)
Make switch 3 & 4 in SW16
for UART B(SCIB)

Output will be displayed


in hyper terminal for
UART A

Source Code:
UART on TMS320F2812 Kit
#include "DSP281x_Device.h"
#include <stdio.h>
void
void
void
void
void

InitSystem(void);
SCI_Init(void);
single_UART(unsigned char cmd);
UART_conv(unsigned long int conv);
Delay_1ms(long);

char message[] = {"The F2812-UART is fine !\n\r"};


int index =0;
// pointer into string
long i;
void main(void)
{
unsigned long i;
EALLOW;
GpioMuxRegs.GPFMUX.bit.SCIRXDA_GPIOF5 = 1;// muxing the uart pin
GpioMuxRegs.GPFMUX.bit.SCITXDA_GPIOF4 = 1;
EDIS;

52

www.pantechsolutions.net

TMS320F2812

InitSystem();

// Initialize the DSP's core Registers

SCI_Init();
while(1)
{
SciaRegs.SCITXBUF=message[index++];
while ( SciaRegs.SCICTL2.bit.TXEMPTY == 0); //wait for TX empty
if (index > 26)
index =0;
for(i=0;i<150000;i++);

// Software - delay approx. 2 sec.

}
}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=1;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}
void SCI_Init(void)
{
SciaRegs.SCICCR.all =0x0007; // 1 stop bit,No loopback No parity,8
char bits,async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCIHBAUD = 405 >> 8 ; // 9600 Baud ; LSPCLK = 31.25MHz
SciaRegs.SCILBAUD = 405 & 0x00FF;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset

53

www.pantechsolutions.net

TMS320F2812

}
void UART_conv(unsigned long int conv)
{
unsigned int
j=0,cap_freq1,cap_freq2,cap_freq3,cap_freq4,cap_freq5,cap_freq6;
cap_freq1 = conv/1000;
cap_freq2 = conv%1000;
cap_freq3 = cap_freq2/100;
cap_freq4 = cap_freq2%100;
cap_freq5 = cap_freq4/10;
cap_freq6 = cap_freq4%10;
single_UART(cap_freq1+0x30);
single_UART(cap_freq3+0x30);
single_UART(cap_freq5+0x30);
single_UART(cap_freq6+0x30);
for(j=0;j<1250;j++);
}
void single_UART(unsigned char cmd)
{
SciaRegs.SCITXBUF=cmd;
while ( SciaRegs.SCICTL2.bit.TXEMPTY == 0);
}

void Delay_1ms(long end)


{
long i;
for (i = 0; i <(9000 * end); i++);
}

Verify Output:
These characters are "The F2812-UART is fine !\n\r"transmit to hyper terminal in
pc.

54

www.pantechsolutions.net

TMS320F2812

Example 8: ADC
Project Description:
This example code shows the converted digital value of 0 to 3.3v input through
potentiometer in LCD. The analog to digital Converted value will be displayed at LCD.
Hardware Connections:
HARDWARE PIN OUT
CH0
CH1
CH2
CH3

CONNECTIONS

OUTPUT

ADC1 to ADC4 output is


displayed at UART

ADCINA0
ADCINA1
ADCINA2
ADCINA3

Source Code:
ADC on TMS320F2812 Kit
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"
#include <stdio.h>
#define ADC_usDELAY 8000L
#define ADC_usDELAY2 20L
void
void
void
void
void
void
void
void
void

SCI_Init();
InitPieCtrl();
InitPieVectTable();
InitCpuTimers();
single_UART(unsigned char cmd);
UART_conv(unsigned long int conv);
InitAdc(void);
InitSystem(void);
Delay_1ms(long);

interrupt void adc_isr(void); // Prototype for ADC result ISR


// Global variables used in this example:
int Voltage_A0;
int Voltage_A1;
int Voltage_A2;
int Voltage_A3;
int Temp,Temp1,Temp2,Temp3;
unsigned char1,char2;
const
const
const
const

55

unsigned
unsigned
unsigned
unsigned

char
char
char
char

ADC0[]
ADC1[]
ADC2[]
ADC3[]

=
=
=
=

{"ADCA0
{"ADCA1
{"ADCA2
{"ADCA3

"};
"};
"};
"};

www.pantechsolutions.net

TMS320F2812

void main(void)
{
unsigned int i;
InitSystem();

// Initialize the DSP's core Registers

EALLOW;
GpioMuxRegs.GPFMUX.bit.SCIRXDA_GPIOF5 = 1;// muxing the uart pin
GpioMuxRegs.GPFMUX.bit.SCITXDA_GPIOF4 = 1;
EDIS;

InitPieCtrl(); // Function Call to init PIE-unit ( code :


DSP281x_PieCtrl.c)
InitPieVectTable(); // Function call to init PIE vector table ( code
: DSP281x_PieVect.c )
InitAdc();
// Function call for basic ADC initialisation
SCI_Init();
// re-map PIE - entry for GP Timer 1 Compare Interrupt
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.ADCINT = &adc_isr;
EDIS;
// This is needed to disable write to EALLOW protected
registers
// Enable ADC interrupt: PIE-Group1 , interrupt 6
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
// Enable CPU INT1 which is connected to ADC interrupt:
IER = 1;
EINT;
// Enable Global interrupt INTM
ERTM;
// Enable Global realtime interrupt DBGM
// Configure ADC
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;
// 0 - Dual & 1 - Cascade
Sequencer Mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 0;
// 0 - No Continuous run &
1 - Continuous run
AdcRegs.ADCTRL1.bit.CPS = 1;
// prescaler = 1
AdcRegs.ADCMAXCONV.all = 0x0003;
// Setup 4 conv's on SEQ
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
// Setup ADCINA0 as 1st
SEQ1 conv.// Assumes EVA Clock is already enabled in InitSysCtrl();
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;
// Setup ADCINA1 as 2nd
SEQ1 conv.// Drive T1PWM / T2PWM by T1/T2 - logic
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;
// Setup ADCINA2
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3;
// Setup ADCINA3
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start
SEQ1// Polarity of GP Timer 1 Compare = Active low
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt
(every EOEvaRegs.GPTCONA.bit.T1PIN = 1;
AdcRegs.ADCTRL3.bit.ADCCLKPS = 2;
// Divide HSPCLK by 4

56

www.pantechsolutions.net

TMS320F2812

// Configure EVA
// Assumes EVA Clock is already enabled in InitSysCtrl();
// Disable T1PWM / T2PWM outputs
EvaRegs.GPTCONA.bit.TCMPOE = 0;
// Polarity of GP Timer 1 Compare = forced low
EvaRegs.GPTCONA.bit.T1PIN = 0;
EvaRegs.GPTCONA.bit.T1TOADC = 2;
// Enable EVASOC in EVA

EvaRegs.T1CON.bit.FREE = 0;
// Stop on emulation suspend
EvaRegs.T1CON.bit.SOFT = 0;
// Stop on emulation suspend
EvaRegs.T1CON.bit.TMODE = 2;
// Continuous up count mode
EvaRegs.T1CON.bit.TPS = 1;
// prescaler = 1
EvaRegs.T1CON.bit.TENABLE = 1;
// enable GP Timer 1
EvaRegs.T1CON.bit.TCLKS10 = 0;
// internal clock
EvaRegs.T1CON.bit.TCLD10 = 0;
// Compare Reload when zero
EvaRegs.T1CON.bit.TECMPR = 0;
// Disable Compare
operation
EvaRegs.T1PR = 145;
for(i=0;i<6;i++)
single_UART(ADC0[i]);
for(i=0;i<6;i++)
single_UART(ADC1[i]);
for(i=0;i<6;i++)
single_UART(ADC2[i]);
for(i=0;i<6;i++)
single_UART(ADC3[i]);
single_UART('\n');
while(1)
{
single_UART('\r');
Temp = Voltage_A0>>4;
UART_conv(Temp);
single_UART(0x20);
single_UART(0x20);
Temp1 = Voltage_A1>>4;
UART_conv(Temp1);
single_UART(0x20);
single_UART(0x20);
Temp2 = Voltage_A2>>4;
UART_conv(Temp2);
single_UART(0x20);
single_UART(0x20);
Temp3 = Voltage_A3>>4;

57

www.pantechsolutions.net

TMS320F2812

UART_conv(Temp3);
Delay_1ms(1000);
}
}

void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=1;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=1;
EDIS;
}
interrupt void adc_isr(void)
{
Voltage_A0 = AdcRegs.ADCRESULT0>>4;
Voltage_A1 = AdcRegs.ADCRESULT1>>4;
Voltage_A2 = AdcRegs.ADCRESULT2>>4;
Voltage_A3 = AdcRegs.ADCRESULT3>>4;
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

// Reset SEQ1
// Clear INT SEQ1 bit
// Acknowledge interrupt to PIE

void InitAdc(void)
{
extern void DSP28x_usDelay(Uint32 Count);
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;
// Power up
bandgap/reference circuitry
DELAY_US(ADC_usDELAY);
// Delay before powering up rest of ADC

58

www.pantechsolutions.net

TMS320F2812

AdcRegs.ADCTRL3.bit.ADCPWDN = 1;
DELAY_US(ADC_usDELAY2);

// Power up rest of ADC


// Delay after powering up ADC

}
void SCI_Init(void)
{
SciaRegs.SCICCR.all =0x0007; // 1 stop bit,No loopback No parity,8
char bits,async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCIHBAUD = 405 >> 8 ; // 9600 Baud ; LSPCLK = 31.25MHz
SciaRegs.SCILBAUD = 405 & 0x00FF;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
void UART_conv(unsigned long int conv)
{
unsigned int
j=0,cap_freq1,cap_freq2,cap_freq3,cap_freq4,cap_freq5,cap_freq6;
cap_freq1 = conv/1000;
cap_freq2 = conv%1000;
cap_freq3 = cap_freq2/100;
cap_freq4 = cap_freq2%100;
cap_freq5 = cap_freq4/10;
cap_freq6 = cap_freq4%10;
single_UART(cap_freq1+0x30);
single_UART(cap_freq3+0x30);
single_UART(cap_freq5+0x30);
single_UART(cap_freq6+0x30);
for(j=0;j<1250;j++);
}
void single_UART(unsigned char cmd)
{
SciaRegs.SCITXBUF=cmd;
while ( SciaRegs.SCICTL2.bit.TXEMPTY == 0);
}
void Delay_1ms(long end)
{
long i;
for (i = 0; i <(9000 * end); i++);
}

Verify Output:
The ADC1 to ADC4 output are displayed at UART.
59

www.pantechsolutions.net

TMS320F2812

Example 9: PWMA
Project Description:
This example code generates the eight PWM using Event manager (EVA).
Hardware Connections:
HARDWARE PIN OUT
PORT A(A0)

GPIOA0

PORT A(A1)

GPIOA1

PORT A(A2)

GPIOA2

PORT A(A3)

GPIOA3

PORT A(A4)

GPIOA4

PORT A(A5)

GPIOA5

PORT A(A6)

GPIOA6

PORT A(A7)

GPIOA7

CONNECTIONS

OUTPUT

Make all the four slide


switches to no
connection(Downwards)

PWM output at port A

Source Code:
PWM onTMS320F2812 Kit
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"

// DSP281x Headerfile Include File


// DSP281x Examples Include File

// Prototype statements for functions found within this file.


void InitSystem(void);
void main(void)
{
InitSystem();
EALLOW;
GpioMuxRegs.GPAMUX.all = 0x01FF; // EVA PWM 1-6 pins
GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
EDIS;
DINT;
EvaRegs.T1PR = 0x186A;
EvaRegs.T1CMPR = 0x0C35;
EvaRegs.T1CNT = 0x0000;
EvaRegs.T2PR = 0x186A;
EvaRegs.T2CMPR = 0x0C35;
EvaRegs.T2CNT = 0x0000;

// Timer1 period
// Timer1 compare
// Timer1 counter
// Timer2 period
// Timer2 compare
// Timer2 counter

EvaRegs.GPTCONA.bit.TCMPOE = 1;// Drive T1/T2 PWM by compare logic

60

www.pantechsolutions.net

TMS320F2812

EvaRegs.GPTCONA.bit.T1PIN = 1; // Polarity of GP Timer 1 Compare =


Active low
EvaRegs.GPTCONA.bit.T2PIN = 2; // Polarity of GP Timer 2 Compare =
Active high
EvaRegs.CMPR1 = 0x0C35;
EvaRegs.CMPR2 = 0x0C35;
EvaRegs.CMPR3 = 0x0C35;

// Enable compare for PWM1-PWM6

EvaRegs.ACTRA.all = 0x0666;
EvaRegs.DBTCONA.all = 0x0530;
EvaRegs.COMCONA.all = 0xA600;
EvaRegs.T1CON.all = 0x1042;

// Disable deadband

// TMODE = continuous up/down & Timer

enable
EvaRegs.T2CON.all = 0x1042;
for(;;);
}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The PWM is Generated at PORT A (A0 to A7) using Event Manager (EVA).
61

www.pantechsolutions.net

TMS320F2812

Example 10: PWMB


Project Description:
This example code generates the eight PWM using Event manager (EVB).
Hardware Connections:
HARDWARE PIN OUT
PORT B(B0)

GPIOB0

PORT B(B1)

GPIOB1

PORT B(B2)

GPIOB2

PORT B(B3)

GPIOB3

PORT B(B4)

GPIOB4

PORT B(B5)

GPIOB5

PORT B(B6)

GPIOB6

PORT B(B7)

GPIOB7

CONNECTIONS

OUTPUT

Make all the four slide


switches to no
connection(Downwards)

PWM output at port B

Source Code:
PWM onTMS320F2812 Kit
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"

// DSP281x Headerfile Include File


// DSP281x Examples Include File
// Prototype statements for
functions found within this file.
void InitSystem(void);
void main(void)
{
InitSystem();
EALLOW;
GpioMuxRegs.GPAMUX.all = 0x01FF; // EVA PWM 1-6 pins
GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
EDIS;
DINT;
EvbRegs.T3PR = 0x186A;
EvbRegs.T3CMPR = 0x0C35;
EvbRegs.T3CNT = 0x0000;

// Timer1 period
// Timer1 compare
// Timer1 counter

EvbRegs.T4PR = 0x186A;
EvbRegs.T4CMPR = 0x0C35;
EvbRegs.T4CNT = 0x0000;

// Timer2 period
// Timer2 compare
// Timer2 counter

EvbRegs.GPTCONB.bit.TCMPOE = 1;

62

// Drive T1/T2 PWM by compare

www.pantechsolutions.net

TMS320F2812

logic
EvbRegs.GPTCONB.bit.T3PIN = 1;
Active low
EvbRegs.GPTCONB.bit.T4PIN = 2;
Active high
EvbRegs.CMPR4 = 0x0C35;
EvbRegs.CMPR5 = 0x0C35;
EvbRegs.CMPR6 = 0x0C35;

// Polarity of GP Timer 1 Compare =


// Polarity of GP Timer 2 Compare =

// Enable compare for PWM1-PWM6

EvbRegs.ACTRB.all = 0x0666;
EvbRegs.DBTCONB.all = 0x0530; // Disable deadband
EvbRegs.COMCONB.all = 0xA600;
EvbRegs.T3CON.all = 0x1042;
Timer enable
EvbRegs.T4CON.all = 0x1042;

// TMODE = continuous up/down &

for(;;);
}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=1;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}

Verify Output:
The PWM is Generated at PORT B (B0 to B7) using Event Manager (EVB).

63

www.pantechsolutions.net

TMS320F2812

Example 11: SPI EEPROM AT25HP256


Project Description:
This example code will write and read data using AT25HP256 SPI EEPROM.
Hardware Connections:
HARDWARE PIN OUT
MISO

GPIOF0

MOSI

GPIOF1

SCK

GPIOF2

CS

GPIOG5

CONNECTIONS

OUTPUT

Select GPIOG5 as chip


select in J15

EEPROM content will


displayed in LCD

Source Code:
SPI EEPROM onTMS320F2812 Kit
#include "DSP281x_Device.h"
//SPI_COMMANDS
#define READ 0x03
#define WRITE 0x02
#define WRDI 0x04
#define WREN 0x06
#define RDSR 0x05
#define WRSR 0x01
#define
#define

EEPROM_CS_LOW()
EEPROM_CS_HIGH()

GpioDataRegs.GPGDAT.bit.GPIOG5 = 0
GpioDataRegs.GPGDAT.bit.GPIOG5 = 1

#define RS GpioDataRegs.GPFDAT.bit.GPIOF8
#define EN GpioDataRegs.GPFDAT.bit.GPIOF9
#define DATA_PORT

GpioDataRegs.GPFDAT.all

// Prototype statements for functions found within this file.


void SPI_Init(void);
unsigned short SPI_Write_Read_Read(unsigned short Data);
void AT25HP256_WRSR(unsigned short wrsr,unsigned short data );
unsigned short AT25HP256_RDSR(unsigned short rdsr);
void AT25HP256_Page_Write(unsigned short addrl, unsigned short addrh);
unsigned char AT25HP256_Read(unsigned short addrl, unsigned short addrh);
void
void
void
void
void

LCD_init(void);
LCD_cmd(unsigned char);
LCD_dat(unsigned char);
delay_ms(long end);
InitSystem();

64

www.pantechsolutions.net

TMS320F2812

unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned

int Spi_VarRx[100];
int i,j,k,i1,x;
int i,j=0,High,Value=0,Out=0;
int Srvalue=0,Srvalue1=0,Srvalue2=0;
char receive_value[128];
int read1,lsb,msb;
char Msg[17]="SPI TEST PROGRAM";
char RMsg[17];

unsigned char temp;


const unsigned char Msg1[] = "AT25HP256 EEPROM";
const unsigned char Msg2[] = "DELFINO DSP KIT ";
void main()
{
InitSystem();
EALLOW;
// LCD Lines
GpioMuxRegs.GPFMUX.bit.MCLKXA_GPIOF8 = 0;
GpioMuxRegs.GPFMUX.bit.MCLKRA_GPIOF9 = 0;
GpioMuxRegs.GPFMUX.bit.MFSXA_GPIOF10 = 0;
GpioMuxRegs.GPFMUX.bit.MFSRA_GPIOF11 = 0;
GpioMuxRegs.GPFMUX.bit.MDXA_GPIOF12 = 0;
GpioMuxRegs.GPFMUX.bit.MDRA_GPIOF13 = 0;
GpioMuxRegs.GPFDIR.bit.GPIOF8 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF9 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF10 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF11 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF12 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF13 = 1;

// Muxing port Pin's to I/O

//Muxing port as ouput

// SPI Lines
GpioMuxRegs.GPFMUX.bit.SPISIMOA_GPIOF0 = 1; // SIMO
GpioMuxRegs.GPFMUX.bit.SPISOMIA_GPIOF1 = 1; // SOMI
GpioMuxRegs.GPFMUX.bit.SPICLKA_GPIOF2 = 1; // CLK
GpioMuxRegs.GPFMUX.bit.SPISTEA_GPIOF3 = 1; // EA
GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5 = 0; // I/O
GpioMuxRegs.GPGDIR.bit.GPIOG5 = 1;
// output
EDIS;
DINT;
IER = 0x0000;
IFR = 0x0000;
SPI_Init();
LCD_init();
delay_ms(20000);
EEPROM_CS_HIGH();
LCD_cmd(0x01);
delay_ms(5000000);

65

www.pantechsolutions.net

TMS320F2812

LCD_cmd(0x80);
for(i=0;i<16;i++)
{
LCD_dat(Msg1[i]);
delay_ms(1000000);
}

// First line

for(i=0;i<16;i++)
{
RMsg[i] = 0;
}
Srvalue = AT25HP256_RDSR(RDSR);
AT25HP256_Page_Write(0x0,0x0);
delay_ms(5000);
while(1)
{
for(i=0;i<16;i++)
{
RMsg[i] = AT25HP256_Read(0x0,i);
}
delay_ms(5000);
LCD_cmd(0xC0);
for(i=0;i<16;i++)
{
LCD_dat(RMsg[i]);
delay_ms(500);
}
delay_ms(1000);

// second line

}
}

void LCD_init(void)
{
delay_ms(100);
LCD_cmd(0x33);
LCD_cmd(0x32);
delay_ms(500);
LCD_cmd(0x28);
use D4-D7 MSB Lines.
LCD_cmd(0x0c);
LCD_cmd(0x06);
LCD_cmd(0x01);
}

// 38 for 8 data lines , 28 for 4 data lines

void LCD_cmd(unsigned char cmd)


{
temp = ((cmd & 0xF0)>>4);

66

www.pantechsolutions.net

TMS320F2812

DATA_PORT = temp << 10;


RS = 0;
EN = 1;
delay_ms(3000);
EN = 0;
temp = cmd & 0x0F;
DATA_PORT = temp << 10;
RS = 0;
EN = 1;
delay_ms(3000);
EN = 0;
}
void LCD_dat(unsigned char byte)
{
temp = ((byte & 0xF0)>>4);
DATA_PORT = temp << 10;
RS = 1;
EN = 1;
delay_ms(3000);
EN = 0;
temp = byte & 0x0F;
DATA_PORT = temp << 10;
RS = 1;
EN = 1;
delay_ms(3000);
EN = 0;
}
void InitSystem()
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x0068 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=1;

67

www.pantechsolutions.net

TMS320F2812

SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}
void delay_ms(long end)
{
long i;
for (i = 0; i < end; i++);
}
void SPI_Init(void)
{
EEPROM_CS_HIGH();
SpiaRegs.SPICCR.all = 0x0007; //Reset = 0,SPILBK = 0,Char len = 8 bit
SpiaRegs.SPICTL.all =0x000F; //Disable Overrun Interrupt,MASTER
mode,Enable Transmission,SPI INT ENA = 0 , No SPI - Interrupts
SpiaRegs.SPISTS.all =0x0080;
SpiaRegs.SPIBRR = 70;
//Baud Rate = LSPCLK / ( SPIBRR
+ 1) 31.25 MHz / ( 3 + 1 ) = 1.25 MHz
SpiaRegs.SPICCR.bit.SPISWRESET = 1; // relinquish SPI from reset
}
/****************************/
/* SPI 16 bit Data to Dac */
/****************************/
unsigned short SPI_Write_Read(unsigned short Data)
{
unsigned short receive;
SpiaRegs.SPITXBUF = (Data<<8) & 0xff00;
// LOWER 8bit to
upper 8bit--Spi transmits 8bit msb
while (SpiaRegs.SPISTS.bit.INT_FLAG == 0); // wait for end of
transmission
receive = SpiaRegs.SPIRXBUF;
// to clear INT_FLAG
read SPIRXBUF
return receive;
}
void AT25HP256_WRSR(unsigned short wrsr,unsigned short data)
{
EEPROM_CS_LOW();
SPI_Write_Read(wrsr);
SPI_Write_Read(data);
EEPROM_CS_HIGH();
}
unsigned short AT25HP256_RDSR(unsigned short rdsr)
{
unsigned short read;
EEPROM_CS_LOW();
SPI_Write_Read(rdsr);
read = SPI_Write_Read(0xFF00);
to read value

68

www.pantechsolutions.net

// Dummy write

TMS320F2812

EEPROM_CS_HIGH();
return read;
}
void AT25HP256_Page_Write(unsigned short addrl, unsigned short addrh)
{
EEPROM_CS_LOW();
SPI_Write_Read(WREN);
EEPROM_CS_HIGH();
EEPROM_CS_LOW();
SPI_Write_Read(WRITE);
SPI_Write_Read(addrh);
SPI_Write_Read(addrl);
for(i=0;i<16;i++)
{
SPI_Write_Read(Msg[i]);
}
EEPROM_CS_HIGH();
}
unsigned char AT25HP256_Read(unsigned short addrh, unsigned short addrl)
{
unsigned char recDat=0;
EEPROM_CS_LOW();
SPI_Write_Read(READ);
SPI_Write_Read(addrh);
SPI_Write_Read(addrl);
recDat = SPI_Write_Read(0xFF);
EEPROM_CS_HIGH();
return recDat;
}

Verify Output:
The EEPROM content will displayed in LCD.

69

www.pantechsolutions.net

TMS320F2812

Example 12: SPI DAC MCP4921


Project Description:
This example code will convert the digital signal into analog signal using MCP4921 SPI
DAC.
Hardware Connections:
HARDWARE PIN OUT
MISO

GPIOF0

MOSI

GPIOF1

SCK

GPIOF2

CS

GPIOG4

CONNECTIONS

OUTPUT

Select GPIOG4 as chip


select in J18

Connect the Probe on J17


SPI DAC Connector

Source Code:
SPI DAC onTMS320F2812 Kit
#include "DSP281x_Device.h"
#include "DSP281x_Spi.h"
#include <stdio.h>
#include<math.h>
#define PI 3.14
#define
#define
void
void
void
void
void

DAC_CS_LOW()
DAC_CS_HIGH()

GpioDataRegs.GPGDAT.bit.GPIOG4 = 0
GpioDataRegs.GPGDAT.bit.GPIOG4 = 1

Gpio_select(void);
InitSystem(void);
SPI_Init(void);
SPI_Write(unsigned short Data);
Sent_to_SPI(unsigned short Value);

unsigned int i,j=0,High,Value=0;


const float sampf = 16000.0;
frquency is fixed
const int inpf = 1000;
the input frquency from 1khz to 8khz(1000 to 8000)
float sampt;
double teta;
signed int value;
int count,nsamp;

// Sampling
// change

void main(void)
{
InitSystem();

70

// Initialize the DSP's core Registers


www.pantechsolutions.net

TMS320F2812

Gpio_select();
DINT;

// Setup the GPIO Multiplex Registers

SPI_Init();
DAC_CS_HIGH();
sampt = 1/sampf;
nsamp = sampf/inpf;
while(1)
{
for(count=0;count<nsamp;count++)
{
teta = (2 * PI * inpf * sampt * count);
value = sin(teta)*2048;
Sent_to_SPI(value);
}
}
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all
GpioMuxRegs.GPBMUX.all =
GpioMuxRegs.GPDMUX.all =
GpioMuxRegs.GPFMUX.all =
GpioMuxRegs.GPEMUX.all =
GpioMuxRegs.GPGMUX.all =

= 0x0; // all GPIO port Pin's to I/O


0x0;
0x0;
0xF;
0x0;
0x0;

GpioMuxRegs.GPADIR.all = 0x0;
// GPIO PORT as input
GpioMuxRegs.GPBDIR.all = 0x00;
GpioMuxRegs.GPDDIR.all = 0x0;
GpioMuxRegs.GPDDIR.all = 0x0;
GpioMuxRegs.GPDDIR.all = 0x0;
GpioMuxRegs.GPEDIR.all = 0x0;
GpioMuxRegs.GPFDIR.all = 0x0;
GpioMuxRegs.GPGDIR.bit.GPIOG4 = 0x1; // GPIO PORT as output
GpioMuxRegs.GPGDIR.bit.GPIOG5 = 0x1;
GpioMuxRegs.GPAQUAL.all = 0x0;

// Set GPIO input qualifier values to

zero
GpioMuxRegs.GPBQUAL.all = 0x0;
GpioMuxRegs.GPDQUAL.all = 0x0;
GpioMuxRegs.GPEQUAL.all = 0x0;
EDIS;
}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
// Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1

71

www.pantechsolutions.net

TMS320F2812

// 0x00AF to NOT disable the Watchdog, Prescaler = 64


SysCtrlRegs.SCSR = 0;
// Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;
// Setup the Clock PLL to
multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to
divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to
divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=1;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}
void SPI_Init(void)
{
SpiaRegs.SPICCR.all = 0x004F; //Reset = 0,SPILBK = 0,Char len = 16
bit
SpiaRegs.SPICTL.all =0x000E; //Disable Overrun Interrupt,MASTER
mode,Enable Transmission,SPI INT ENA = 0 , No SPI - Interrupts
SpiaRegs.SPIBRR = 3;
//Baud Rate = LSPCLK / ( SPIBRR + 1)
// 31.25 MHz / ( 3 + 1 ) = 7.8 MHz
SpiaRegs.SPICCR.bit.SPISWRESET = 1; // relinquish SPI from reset
}

/****************************/
/* SPI 16 bit Data to Dac */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive;
Data = ( 0x3000 | Data );
SpiaRegs.SPITXBUF = Data;
//
while (SpiaRegs.SPISTS.bit.INT_FLAG == 0) ; // wait for end of
transmission
for (i=0;i<15;i++);
// wait for DAC to finish off
/* Clear any old data */
receive = SpiaRegs.SPIRXBUF;
}

72

www.pantechsolutions.net

TMS320F2812

void Sent_to_SPI(unsigned short Value)


{
DAC_CS_LOW();
Value = (0x0FFF & Value);
Value = (0x0800 ^ Value);
SPI_Write(Value);
for(j=0;j<10;j++);
DAC_CS_HIGH();
}

Verify Output:
The Sine wave is generated using SPI DAC MCP4921.

73

www.pantechsolutions.net

TMS320F2812

CHENNAI

HEAD OFFICE

Pantech Prolabs India Pvt Ltd.,


#41, Rajeshwari street,
Santhosh Nagar, Kandhanchavadi,
Chennai - 600096
Tamil Nadu | India
Ph : 044 64524445/46/47

COIMBATORE

E-MAIL
For Queries:
info@pantechmail.com
Technical Support:
support@pantechmail.com
Sales:
sales@pantechmail.com
Helpline Forum:
www.pantechsolutions.net/forum

MADURAI

Pantech Solutions Pvt Ltd.,

Pantech Solutions Pvt Ltd.,

II Floor, Sai Sruthi Complex,


3, Ramarkoil Street, Ram Nagar,
Coimbatore - 641 009
Tamil Nadu | India
Ph : +91 422 4506470

No. P, Basement Floor,


A.R.Plaza, | 16-17, North Veli Street,
Madurai - 625 001
Tamil Nadu | India
Ph : +91 452 4375382

HYDERABAD

COCHIN

Pantech Solutions Pvt Ltd.,

Pantech Solutions Pvt Ltd.,

G1, G2, Venkateshwara Appts,


3-6-430, Himayathnagar,
Near Hyundai Showroom
Hyderabad - 500 029
Andhara Pradesh | India
Ph : +91 40 40077960

No:44/1022,1st Floor,
Puthenpurakkal House,
Arya Padam Lana,
Kochi - 682017
Kerala | India
Ph:+91 484 2536270

EMBEDDED | VLSI | DSP | POWER ELECTRONICS | PCB DESIGN | PLC

74

www.pantechsolutions.net

TMS320F2812

Das könnte Ihnen auch gefallen