?? tms470r1a256_spi_06.c
字號:
//*****************************************************************************
// TMS470 Demo - SPI Sample Program master 5pin rti
//
// This is a SPI 5 pin - Slave Mode - RTI Interrupt configuration.
// Data from a table is transmitted from SPI 1 based on the RTI timing.
// This is a 5 pin configuration using SIMO SPICLK SOMI SCS ENA pins. Clock speed 12 Mhz.
//
//
// TMS-FET470A256
// _________________
// | |
// /|\| OSCIN|-
// | | | 12MHz
// --|PLLDIS OSCOUT|-
// | |
// ---|SPICLK SIMO|---
// | |
// ---|ENA SOMI|---
// | |
// | SCS|---
// | |
// |_________________|
//
//
//
//
//
// J. Mangino/A. Dannenberg
// Texas Instruments, Inc
// January 2005
// Built with IAR Embedded Workbench Version: 4.11A
//******************************************************************************
#include <intrinsic.h>
#include "iotms470r1a256.h"
#include "tms470r1a256_bit_definitions.h"
// LED moving pattern codes.
int led_table[] = {
0x0000,0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000, 0xffff
};
unsigned int datp;
int* ip;
void COMP1_irq_handler()
{
RTICINT = 0x00; // interrupt control, clear CMP1 and enable CMP1 interrupt
RTICINT = 0x20;
if (*ip != 0xffff)
{
SPI1DAT1 = *ip;
ip++;
}
else
{
ip = led_table;
SPI1DAT1 = *ip;
ip++;
}
}
//------------------------------------------------------------------------------
// TMS470R1A256 Standard Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = IRQV
__irq __arm void irq_handler(void)
{
switch((0xff & IRQIVEC)-1)
{
case CIM_COMP1 : COMP1_irq_handler(); break;
}
}
void main(void)
{
// Set up peripheral registers.
// First disable interrupts.
__disable_interrupt();
ip = led_table;
// Setup system.
PCR = CLKDIV_4; // ICLK = SYSCLK/4
PCR |= PENABLE; // enable peripherals
REQMASK = (1 << CIM_COMP1); // Enable SPI Interrupt mask
// Setup periodic interrupt using RTI with RTICMP1
RTICNTEN = 0x03; // Stop counting
RTICNTR = 0; // clear 21-bits CNTR
// Setup periodic interrupt timer
// CMP1 used to generate interrupt.
RTIPCTL = 0x3; // preload 11-bits MOD
RTICMP1 = 0xfffff; //
RTICNTL = 0x00; // clear and disable tap
// interrupt control, clear CMP1 and enable CMP1 interrupt
RTICINT = 0x00;
RTICINT = 0x20;
// Start count, CNTR and MOD will count in both USER and SYSTEM mode
RTICNTEN = 0x00;
HETDIR = 0xffffffff; // Set HET as GIO outputs
HETDOUT = 0x813c3dd5; // Output off
HETDOUT = 0x00000000; // Output on
HETDOUT = 0x813c3dd5; // Output off
// SPI 1 Setup
SPI1CTRL1= CHARLEN_16 + PRESCALE_1; // char len = 16 prescale =1 spi baud =Iclk/2
SPI1CTRL2 = MASTER + CLKMOD; // Master mode
SPI1CTRL3 = 0x00; // Disable SPI1 Interrupt
SPI1PC6=SOMI_FUN + SIMO_FUN + CLK_FUN + SCS_FUN + ENA_FUN; //0x0e; // SIMO SPICLK ENA enables
SPI1CTRL2 |= SPIEN; // Enable SPIs
datp = SPI1BUF; // Dummy Read to clear buffer
__enable_interrupt(); // Enable Interrupts
// Loop forever.
while (1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -