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

📄 tlv2548.c.bak

📁 c6713的源代码
💻 BAK
字号:
#include "IMU_GW.h"

extern unsigned short ADC_ready;


/*********************************************
FUNC	: delay()
DESC	: delay time
*********************************************/
void Delay( int Count )
{
	volatile int i = Count;
	while(i--);
}

/*********************************************
FUNC	: McBSP0_init()
DESC	: Initialize McBSP0 as SPI master
*********************************************/
void McBSP0_init()
{
	// Set SPCR XRST=RRST=0, reset transmit and receive port
	*(unsigned volatile int *)McBSP0_SPCR &= 0xFFFEFFFE;	
	*(unsigned volatile int *)McBSP0_PCR   = 0x00000A0C; // Set PCR 0x00000A09;
	*(unsigned volatile int *)McBSP0_RCR   = 0x000100A0; // Set RCR data length 16bit 0x00010040
	*(unsigned volatile int *)McBSP0_XCR   = 0x000100A0; // Set XCR data length 16bit 0x00010040
	*(unsigned volatile int *)McBSP0_SRGR  = 0x200000FF; // Set SRGR
	//*(unsigned volatile int *)McBSP0_SPCR |= 0x00001000; Set SPCR CLKSTP=10
	*(unsigned volatile int *)McBSP0_SPCR |= 0x00001800; // Set SPCR CLKSTP=11
	Delay(300);
	*(unsigned volatile int *)McBSP0_SPCR |= 0x00400000; // Set SPCR GRST=1
	*(unsigned volatile int *)McBSP0_SPCR |= 0x00010001; // Set SPCR XRST=RRST=1, enable transmit and receive
}
  
/*******************************************************************************
 FUNC	: McBSP0_rrdy()
 DESC	: Reads the RRDY status bit of the SPCR register. 
 ARGS	: void
 RET	: A 1 indicates the receiver is ready with data to be read. 
          A 0 indicates the receiver is not ready with data to be read. 
 *******************************************************************************/
unsigned short McBSP0_rrdy()
{
	unsigned short temp;
	temp = *(unsigned short *)McBSP0_SPCR;
	temp &= 0x02;
	return temp;
}
 
/*******************************************************************************
 FUNC	: McBSP0_write()
 DESC	: Write a 16bit value to the serial port data transmit register, DXR.
 ARGS	: cmd = 16bit data value
 RET	: void
 *******************************************************************************/
void McBSP0_write(unsigned short cmd)
{
	*(volatile unsigned short *)McBSP0_DXR = cmd;
}

/*******************************************************************************
 FUNC	: McBSP0_read()
 DESC	: Performs a direct 16bit read of the data receive register DRR.
 ARGS	: void
 RET	: 16bit data value
 *******************************************************************************/
unsigned short McBSP0_read()
{
	unsigned short tmp;
	while(McBSP0_rrdy()==0)
	{
	}
	tmp = *(unsigned short *)(McBSP0_DRR+2); 	
	return tmp;
}

/*******************************************************************************
FUNC	: ADC_read()
DESC	: Software Read routines for the TLV2548
ARGS	: channel - Select channelx command
RET	: void
*******************************************************************************/
void ADC_read(unsigned short channel)
{
	unsigned short temp=0,temp1;
	float tempF;
	McBSP0_write(channel);
	temp = McBSP0_read();
	temp1 = (temp>>4);
	tempF = (float)(temp1*(2.0/4095));
	//C_temp[ADC_readN] = temp1;
	//*(pAddr++) = tempF; 
	//ADC_readN++;
}


/*******************************************************************************
 FUNC	: ext6_isr()
 DESC	: EXT6 interrupt routine. Called when TLV2548 generates the INT pulse.
 ARGS	: void
 RET	: void
 *******************************************************************************/
interrupt void ext6_isr()
{
  	 //ADC_OK=1;
  	 //ADC_time++;
} 


/**********************************************
 FUNC	: ADC_init()
 DESC	: Initialize TLV2548 
 **********************************************/
 void ADC_init()
 {
 	unsigned short temp0,temp1;
    	
 	// Write CFR command 	
 	McBSP0_write(write_CFR);
 	Delay(20000);
 	 
    // Write command of Reading CFR register
 	McBSP0_write(read_CFR);
 	Delay(20000);
 	
 	// Get value of CFG register 
 	temp0 = McBSP0_read();
 	
 	temp0 = temp0 & 0x0C80; 
 	temp1 = (write_CFR) & 0x0C80;
 	
 	if( temp0 == temp1 ) 
 	{
 		ADC_ready=1;
 	}
 	else
 	{
 		ADC_ready=0;
 	} 	
 }

 
 
 


⌨️ 快捷键说明

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