MAX121 是一款具有DSP接口的14位串行ADC,最大采样速率308KBPS,驱动程序如下:
#include
#include
MCBSP_Handle hADC;
/* */
MCBSP_Config ADC_Mcbsp0 = {
MCBSP_SPCR1_RMK(
MCBSP_SPCR1_DLB_OFF,
MCBSP_SPCR1_RJUST_RZF,
MCBSP_SPCR1_CLKSTP_NODELAY, //CLKSTP = 10(no clock delay)
MCBSP_SPCR1_DXENA_NA,
MCBSP_SPCR1_ABIS_DISABLE,
MCBSP_SPCR1_RINTM_RRDY,
0,
MCBSP_SPCR1_RRST_DISABLE
),
MCBSP_SPCR2_RMK(
MCBSP_SPCR2_FREE_NO,
MCBSP_SPCR2_SOFT_NO,
MCBSP_SPCR2_FRST_RESET,
MCBSP_SPCR2_GRST_RESET,
MCBSP_SPCR2_XINTM_XRDY,
0,
MCBSP_SPCR2_XRST_DISABLE
),
MCBSP_RCR1_RMK(
MCBSP_RCR1_RFRLEN1_OF(0),
MCBSP_RCR1_RWDLEN1_16BIT
),
MCBSP_RCR2_RMK(
MCBSP_RCR2_RPHASE_SINGLE,
MCBSP_RCR2_RFRLEN2_OF(0),
MCBSP_RCR2_RWDLEN2_8BIT,
MCBSP_RCR2_RCOMPAND_MSB,
MCBSP_RCR2_RFIG_YES,
MCBSP_RCR2_RDATDLY_0BIT //RDATDLY = 0
),
MCBSP_XCR1_RMK(
MCBSP_XCR1_XFRLEN1_OF(0),
MCBSP_XCR1_XWDLEN1_16BIT
),
MCBSP_XCR2_RMK(
MCBSP_XCR2_XPHASE_SINGLE,
MCBSP_XCR2_XFRLEN2_OF(0),
MCBSP_XCR2_XWDLEN2_8BIT,
MCBSP_XCR2_XCOMPAND_MSB,
MCBSP_XCR2_XFIG_YES,
MCBSP_XCR2_XDATDLY_0BIT //XDATDLY = 0
),
MCBSP_SRGR1_RMK(
MCBSP_SRGR1_FWID_OF(1),
MCBSP_SRGR1_CLKGDV_OF(1) //CLKGDV = 1
),
MCBSP_SRGR2_RMK(
MCBSP_SRGR2_GSYNC_FREE,
MCBSP_SRGR2_CLKSP_RISING,
MCBSP_SRGR2_CLKSM_INTERNAL, //CLKSM = 1
MCBSP_SRGR2_FSGM_DXR2XSR,
MCBSP_SRGR2_FPER_OF(15)
),
MCBSP_MCR1_DEFAULT,
MCBSP_MCR2_DEFAULT,
MCBSP_PCR_RMK(
0, //IDLEEN = 0
MCBSP_PCR_XIOEN_SP,
MCBSP_PCR_RIOEN_SP,
MCBSP_PCR_FSXM_EXTERNAL, //FSXM = 0;
MCBSP_PCR_FSRM_EXTERNAL,
MCBSP_PCR_CLKXM_INPUT, //CLKXM = 0
MCBSP_PCR_CLKRM_INPUT,
MCBSP_PCR_SCLKME_NO, //SCLKME = 0
0,
MCBSP_PCR_FSXP_ACTIVELOW, //FSXP = 0 The FSX pin is active low.
MCBSP_PCR_FSRP_ACTIVEHIGH,
MCBSP_PCR_CLKXP_RISING, //CLKXP = 0
MCBSP_PCR_CLKRP_FALLING //CLKRP = 0
),
MCBSP_RCERA_DEFAULT,
MCBSP_RCERB_DEFAULT,
MCBSP_RCERC_DEFAULT,
MCBSP_RCERD_DEFAULT,
MCBSP_RCERE_DEFAULT,
MCBSP_RCERF_DEFAULT,
MCBSP_RCERG_DEFAULT,
MCBSP_RCERH_DEFAULT,
MCBSP_XCERA_DEFAULT,
MCBSP_XCERB_DEFAULT,
MCBSP_XCERC_DEFAULT,
MCBSP_XCERD_DEFAULT,
MCBSP_XCERE_DEFAULT,
MCBSP_XCERF_DEFAULT,
MCBSP_XCERG_DEFAULT,
MCBSP_XCERH_DEFAULT
};
interrupt void ADC_DATA_INT(void);
void IniADC(void)
{
// Uint16 eventId;
// tmp_index = 0;
// eventId = IRQ_EVT_RINT0;
//eventId1 = IRQ_EVT_INT1;
/* Clear any pending McBSP0 rec interrupts */
// IRQ_clear(eventId);
//IRQ_clear(eventId1);
/* Place interrupt service routine address at */
/* associated vector location */
// IRQ_plug(eventId,&ADC_DATA_INT);
//IRQ_plug(eventId1,&ADC_FO_INT);
//初始化DSP的相关寄存器
hADC=MCBSP_open(MCBSP_PORT0,MCBSP_OPEN_RESET);
/*设置McBSP1*/
MCBSP_config(hADC,&ADC_Mcbsp0);
/* Enable INT5 McBSP rec interrupt */
// IRQ_enable(eventId);
MCBSP_start(hADC,
MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,
0x300);
MCBSP_start(hADC,
MCBSP_RCV_START,//MCBSP_XMIT_START|
0);
}
/*
interrupt void ADC_DATA_INT(void)
{
if(MCBSP_rrdy(hADC))
{
tmpadc[tmp_index++] = MCBSP_read16(hADC);
}
if(tmp_index>=1024)
{
tmp_index = 0;
}
}
*/
头文件如下:
#include
#include
#ifndef __DAC_H__
#define __DAC_H__
#define DAC_PORTA 0x00
#define DAC_PORTB 0x01
#define DAC_PORTC 0x02
#define DAC_PORTD 0x03
#define DAC_MAX_OUT 8200
extern void IniADC(void);
extern void IniDAC8164D(void);
/* TMS320VC5501/5502/5509/5510 DSP */
/* Multichannel Buffered Serial Port (McBSP) */
/* Reference Guide */
extern void IniAudioDAC(void);
extern void SendToDAC8164(Uint16 DAC_PORTX,Uint16 Value);
extern void SendToIF(Uint32 Value);
/*
* FUNCTION: SENDtoAUDIO_DAC
*
* PARAMETERS:
Value:输出的电压值
Gain:输出的增益系数,Q7
*
* DESCRIPTION:发送数据到DAC,最终发送的数据是
*
* RETURNS:
*
*/
extern void SENDtoAUDIO_DAC(Uint16 Value);
#endif