⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mode_iv.c

📁 Welcome to the software files for the ADS8361 to TMS320F2812! There are two project files in each
💻 C
字号:
/************************************************************/
/* FILENAME: mode_IV.c                            			*/
/* DESCRIPTION: This program uses SPI1 to read 512 x 4ch 	*/
/*	samples continuously from the ADS8361 16-bit 500KSPS 	*/
/*	Analog-to-Digital Converter.  The samples are stored in */
/* 	the buffer called SPI_Data.                     		*/             
/* AUTHOR	: DAP Application Group, T. Hendrick, Dallas    */
/*    CREATED 2003(C) BY TEXAS INSTRUMENTS INCORPORATED.  	*/
/* VERSION: 1.0 							                */
/************************************************************/

/* PortF acts as GPIO to control M0(F10) and M1(F8), A0 is  */
/* "don't care in this mode                                 */

#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"

// Global Variables
#define Samples 512
#define Channels  4
int idx = 0, ch;
unsigned int dummy0 = 0x0;
unsigned int dummy1 = 0x0000;
unsigned int SPI_UB_Temp;
unsigned int SPI_LB_Temp;
unsigned int SPI_Data[Channels][Samples];

// Prototype statements for functions found within this file.
void delay_loop(int count);
void spi_init(void);
void spi_fifo_init(void);
void spi_xmit(void);
// Prototype statements for GPIO functions found within this file.
void Toggle_A0(int);
void Toggle_STE(int);
void Toggle_M0(int);
void Toggle_M1(int);
void ToggleRD_CONVST(void);
void SYNC_UP(void);		
void main(void)
{

// Initialize System Control registers, PLL, WatchDog, Clocks to default state:
    // This function is found in the DSP28_SysCtrl.c file.
    InitSysCtrl();

// Select GPIO for the device or for the specific application:
    // This function is found in the DSP28_Gpio.c file.
    // InitGpio(); skip this as this is example selects the I/O for McBSP in this file itself
     InitGpio();   

// Initialize PIE vector table:
    // The PIE vector table is initialized with pointers to shell Interrupt 
    // Service Routines (ISR).  The shell routines are found in DSP28_DefaultIsr.c.
    // Insert user specific ISR code in the appropriate shell ISR routine in 
    // the DSP28_DefaultIsr.c file.

    // Disable and clear all CPU interrupts:
    DINT;
    IER = 0x0000;
    IFR = 0x0000;

    // Initialize Pie Control Registers To Default State:
        // This function is found in the DSP28_PieCtrl.c file.
    InitPieCtrl();

    // Initialize the PIE Vector Table To a Known State:
    // This function is found in DSP28_PieVect.c.
    // This function populates the PIE vector table with pointers
    // to the shell ISR functions found in DSP28_DefaultIsr.c.
    InitPieVectTable();    
    
// User specific functions, Reassign vectors, Enable Interrupts, etc:

    EALLOW;
    GpioMuxRegs.GPEMUX.all=0x0000;    // Select GPIOs to be McBSP pins     
    GpioMuxRegs.GPEDIR.all=0x0001;    // Select GPIOF3 as OUT, /CS to ADC
    GpioMuxRegs.GPFMUX.all=0x0007;    // Select GPIOs to be McBSP pins     
    GpioMuxRegs.GPFDIR.all=0x7F08;    // Select GPIOF3 as OUT, /CS to ADC
    GpioMuxRegs.GPAMUX.all=0x0000;    // Select GPIOA2 & 3 for FSx and FSr     
    GpioMuxRegs.GPADIR.all=0x0004;    // Select GPIOA2 as OUT, 3 as IN
    EDIS;
    spi_init();
    spi_fifo_init();    

	
while(1)                                                // Forever Loop
	{
	SYNC_UP();
	for(idx=0; idx<Samples; idx++)
		{
		Toggle_STE(0);
 		for(ch=0; ch<Channels; ch++)
		{		
		ToggleRD_CONVST();
	    spi_xmit();

	    SPI_LB_Temp = SpiaRegs.SPIRXBUF>>13;
	    SPI_UB_Temp = SpiaRegs.SPIRXBUF<<3;
    while(SpiaRegs.SPIFFRX.bit.RXFFST ==0) { }
		SPI_Data[ch][idx] = (SPI_UB_Temp + SPI_LB_Temp);	    
		}
	    delay_loop(30);
	    }
	}  //Place probe point here for array display
}     

// Some Useful local functions
void delay_loop(int count)
{
    long      i;
    for (i = 0; i < count; i++) {}
}


void SYNC_UP()
{
	Toggle_M0(0);	         // Clear M0
	Toggle_M1(0);	         // Clear M1	
    Toggle_STE(0);           // Clear STE

//	Toggle_RD_CONVST via GPIO;
		ToggleRD_CONVST();
	    spi_xmit();
	    SPI_LB_Temp = SpiaRegs.SPIRXBUF>>13;
	    SPI_UB_Temp = SpiaRegs.SPIRXBUF<<3;
    while(SpiaRegs.SPIFFRX.bit.RXFFST ==0) { }
	Toggle_M0(1);	         // Set M0
	Toggle_M1(1);	         // Set M1
	Toggle_A0(1);	         // Choose A0/B0 or A1/B1 
	
//	Toggle_RD_CONVST via GPIO;		ToggleRD_CONVST();
		ToggleRD_CONVST();
	    spi_xmit();
	    SPI_LB_Temp = SpiaRegs.SPIRXBUF>>13;
	    SPI_UB_Temp = SpiaRegs.SPIRXBUF<<3;
    while(SpiaRegs.SPIFFRX.bit.RXFFST ==0) { }
    Toggle_STE(1);            // Set STE
}

void spi_xmit()
{
    SpiaRegs.SPITXBUF = 0xF000;  //Alternative to Toggle_A0
    SpiaRegs.SPITXBUF = 0x0000;    
    while(SpiaRegs.SPIFFTX.bit.TXFFST !=0) { }    
}    

void spi_init()
	{    
	   
	SpiaRegs.SPICCR.all =0x000F;	             // Reset on, rising edge, 16-bit char bits  
	SpiaRegs.SPICTL.all =0x0006;    		     // Enable master mode, normal phase,
                                                 // enable talk, and SPI int disabled.
	SpiaRegs.SPIBRR =0x0002;									
// Release Reset for SPI		
    SpiaRegs.SPICCR.all =0x008F;		         // Relinquish SPI from Reset   
                                                 // Bit 4 loop back mode enabled
    }
    
void spi_fifo_init()										
{
// Initialize SPI FIFO registers
    SpiaRegs.SPIFFTX.all=0xE140;
    SpiaRegs.SPIFFRX.all=0x2041;
    SpiaRegs.SPIFFCT.all=0x02;
    
}  

void Toggle_STE(int state)
{
	switch(state)
	{
	case 0:
		GpioDataRegs.GPFCLEAR.all = 0x0008;  // Clear M0    
		break;
	case 1:
		GpioDataRegs.GPFSET.all = 0x0008;    // Set M0 High
		break;
	}
}


void Toggle_M1(int state)
{
	switch(state)
	{
	case 0:
		GpioDataRegs.GPFCLEAR.all = 0x0100;  // Clear M1    
		break;
	case 1:
		GpioDataRegs.GPFSET.all = 0x0100;    // Set M1 High
		break;
	}
}

void Toggle_M0(int state)
{
	switch(state)
	{
	case 0:
		GpioDataRegs.GPFCLEAR.all = 0x0400;  // Clear M0    
		break;
	case 1:
		GpioDataRegs.GPFSET.all = 0x0400;    // Set M0 High
		break;
	}
}

void Toggle_A0(int state)
{
	switch(state)
	{
	case 0:
    	GpioDataRegs.GPFCLEAR.all = 0x0800;   // Clear A0    
		break;
	case 1:
		GpioDataRegs.GPFSET.all = 0x0800;     // Set A0
		break;
	}
}

void ToggleRD_CONVST()
{
    GpioDataRegs.GPACLEAR.all = 0x0004;  // Test Clear    
    asm (" RPT #30 || NOP");
    GpioDataRegs.GPASET.all = 0x0004;    // Test Set
}
//===========================================================================
// End Program.
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -