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

📄 functions.c

📁 ADS8345 to TMS320C5416 DSP
💻 C
字号:
/************************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, 
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR 
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE. 
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET 
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY 
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR 
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL, 
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY 
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT 
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM. 
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF 
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS 
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF 
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S 
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF 
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS 
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted 
* by Texas Instruments is distributed as "freeware".  You may, 
* only under TI's copyright in the Program, use and modify the 
* Program without any charge or restriction.  You may 
* distribute to third parties, provided that you transfer a 
* copy of this license to the third party and the third party 
* agrees to these terms by its first use of the Program. You 
* must reproduce the copyright notice and any other legend of 
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains 
* copyrighted material, trade secrets and other TI proprietary 
* information and is protected by copyright laws, 
* international copyright treaties, and trade secret laws, as 
* well as other intellectual property laws.  To protect TI's 
* rights in the Program, you agree not to decompile, reverse 
* engineer, disassemble or otherwise translate any object code 
* versions of the Program to a human-readable form.  You agree 
* that in no event will you alter, remove or destroy any 
* copyright notice included in the Program.  TI reserves all 
* rights not specifically granted under this license. Except 
* as specifically provided herein, nothing in this agreement 
* shall be construed as conferring by implication, estoppel, 
* or otherwise, upon you, any license or other right under any 
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
*************************************************************/


/************************************************************
* FILENAME: Functions.c                            				
* DESCRIPTION: This example program uses McBSP1, DMA4              
* 	and DMA5 of 'C5416 to read 2048 samples from the ADS8345  
*  	16-bit 100KSPS Analog-to-Digital Converter.  The samples 
* 	are stored by DMA5 in an array called buffer.  When the
* 	DMA has transferred all 2048 samples it interrupts 
*	the CPU.  At which point, the CPU disables all the 
*	perpherals and begins to sort the data by channel. All
*	the samples read from analog input 0 are stored in 
*	Chan0, and likewise for the other 7 channels.
* Hardware Connections:									
*		ADC pin	->  DSP pin									
*		CS# 	->	GPIO (assumed LOW)							
*		CLK 	->  CLKX1										
*		DIN		->  DXR1										
*		DOUT 	-> 	DRR1										
*		BUSY 	-> 	FSR1									 */
/*************************************************************/
/* AUTHOR: DAP Application Group, L. Philipose, Dallas       */
/*         CREATED 2002(C) BY TEXAS INSTRUMENTS INCORPORATED.*/
/* VERSION: 1.0 							                 */
/*************************************************************/


#include "ads8345.h"
#include "c5416DMA_ads8345cfg.h"

/* Global Variables*/
/*Store digitized data in respective array*/
Uint16 Chan0[NSAMPLES/8], Chan1[NSAMPLES/8];
Uint16 Chan2[NSAMPLES/8], Chan3[NSAMPLES/8];
Uint16 Chan4[NSAMPLES/8], Chan5[NSAMPLES/8];
Uint16 Chan6[NSAMPLES/8], Chan7[NSAMPLES/8];
/* Place buffer in its own section, since this must reside in DMA */
/* Memory Map. Check your device datasheet for valid ranges of   */
/* DMA memory.                                                   */
#pragma DATA_SECTION(buffer, "dmaMem")
Uint16 buffer[NSAMPLES];
#pragma DATA_SECTION(CfgByte, "dmaMem1")
Uint16 CfgByte[NConfigWord]; 		/* A/D commands array */

/******************************************************************
* swiSortChan0Func(): Filters Channel 0 Data from buffer and stores 
*them in array called Chan0. 
******************************************************************/

void swiSortChan0Func()
{
	Uint16 n,i;

		n = 0;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan0[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan0 SWI done.\n");    
}

/******************************************************************
* swiSortChan1Func(): Filters Channel 1 Data from buffer and stores 
*them in array called Chan1. 
******************************************************************/

void swiSortChan1Func()
{
	Uint16 n=0,i=0;
	

		n = 1;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan1[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan1 SWI done.\n");    
}

/******************************************************************
* swiSortChan2Func(): Filters Channel 2 Data from buffer and stores 
*them in array called Chan2.
******************************************************************/

void swiSortChan2Func()
{
	Uint16 n=0,i=0;

		n = 2;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan2[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan2 SWI done.\n");    
}

/******************************************************************
* swiSortChan3Func(): Filters Channel 3 Data from buffer and stores 
*them in array called Chan3.
******************************************************************/

void swiSortChan3Func()
{
	Uint16 n=0,i=0;

		n = 3;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan3[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan3 SWI done.\n");    
}

/******************************************************************
* swiSortChan4Func(): Filters Channel 4 Data from buffer and stores 
*them in array called Chan4.
******************************************************************/

void swiSortChan4Func()
{
	Uint16 n=0,i=0;
	
		n = 4;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan4[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan4 SWI done.\n");    
}

/******************************************************************
* swiSortChan5Func(): Filters Channel 5 Data from buffer and stores 
*them in array called Chan5.
******************************************************************/

void swiSortChan5Func()
{
	Uint16 n=0,i=0;
	
		n = 5;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan5[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan5 SWI done.\n");    

}

/******************************************************************
* swiSortChan6Func(): Filters Channel 6 Data from buffer and stores 
*them in array called Chan6. 
******************************************************************/
void swiSortChan6Func()
{

	Uint16 n=0,i=0;

		n = 6;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan6[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan6 SWI done.\n");    

}

/******************************************************************
* swiSortChan7Func(): Filters Channel 7 Data from buffer and stores 
*them in array called Chan7. 
******************************************************************/

void swiSortChan7Func()
{

	Uint16 n=0,i=0;

		n = 7;
		for(i = 0;i<=(NSAMPLES/8);i++)
		{		
			Chan7[i]= buffer[n]; n+=8;		
		};

//	LOG_printf(&trace,"Chan7 SWI done.\n");    
}

/****************************************************************
*FUNCTION: RCV_isr()                                         	
*DESCRIPTION: DMA5 ISR function. When buffer is 
*full DMAC5 interrupt occurs.   
****************************************************************/
void RCV_isr()
{

/*All Samples have been read and stored, disable all peripherals */
		DMA_stop(hDma5);				/*Stop Receive DMA Channel*/
		DMA_stop(hDma4);				/*Stop Transmit DMA Channel*/

		MCBSP_close(hMcbsp1);			/*Reset & close McBSP */
		

/*Post "Sort" software Interrupts for all 8 channels*/
		SWI_post(&swiSORTCHAN0);		
		SWI_post(&swiSORTCHAN1);	
		SWI_post(&swiSORTCHAN2);	
		SWI_post(&swiSORTCHAN3);	
		SWI_post(&swiSORTCHAN4);	
		SWI_post(&swiSORTCHAN5);	
		SWI_post(&swiSORTCHAN6);	
		SWI_post(&swiSORTCHAN7);	
/*Print to the Message Log Window interrupt occurred*/
    	LOG_printf(&trace,"Full Buffer Int occurred.\n");    

}

/****************************************************************
*FUNCTION: ADC_init()                                         	
*DESCRIPTION: This function enables McBSP1 and sets A/D for
*	external clock mode.  
****************************************************************/

void ADC_init(void)
{
	int i=0;

/* Take MCBSP receive and transmit out of reset */
  	MCBSP_start(hMcbsp1, MCBSP_RCV_START | MCBSP_XMIT_START, 0 );	

/* Prime MCBSP DXR */
 	while (!MCBSP_xrdy(hMcbsp1)){;}
 	MCBSP_write16(hMcbsp1,0x8700); 

 /* Start the MCBSP and Sample Rate Generator */
  	MCBSP_start(hMcbsp1, MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 0 );

/*Flush Receiver*/
 	while (!MCBSP_rrdy(hMcbsp1)){;}
	MCBSP_read16(hMcbsp1); 
/*Write 0x0000 to McBSP1*/
 	while (!MCBSP_xrdy(hMcbsp1)){;}
 	MCBSP_write16(hMcbsp1,0x0000); 
 	while (!MCBSP_rrdy(hMcbsp1)){;}
 	MCBSP_read16(hMcbsp1);
}

⌨️ 快捷键说明

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