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

📄 tlv2548.c

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

extern unsigned short tlv2548_ready;
extern unsigned short tlv2548_readN;    
extern unsigned long int  tlv2548_totalNdx; 
extern unsigned short C_temp[ADC_SIZE];
extern float  T0;
extern float  T1;
//extern volatile float* pAddr1;
//extern volatile unsigned short* pAddr1;
/*********************************************
FUNC	: delay()
DESC	: delay time
*********************************************/
//延时
void Delay( int Count )
{
	volatile int i = Count;
	while(i--);
}

/*********************************************
FUNC	: McBSP0_init()
DESC	: Initialize McBSP0 as SPI master c6713的spi设定固有模式
*********************************************/
void McBSP0_init()
{
	// Set SPCR XRST=RRST=0, reset transmit and receive port
	//把McBSP0_SPCR地址里的值的最后1位置0
	*(unsigned volatile int *)McBSP0_SPCR &= 0xFFFEFFFE;
	//发送和接收复位	
	*(unsigned volatile int *)McBSP0_PCR   = 0x00000A0C; 
	//读的数据的长度
	*(unsigned volatile int *)McBSP0_RCR   = 0x000100A0; // Set RCR data length 32bit 
	//写的数据的长度
	*(unsigned volatile int *)McBSP0_XCR   = 0x000100A0; // Set XCR data length 32bit 
	//时钟
	*(unsigned volatile int *)McBSP0_SRGR  = 0x20000027; // Set SRGR CLK=200M/40
		*(unsigned volatile int *)McBSP0_SPCR |= 0x00001800; // Set SPCR CLKSTP=11
	Delay(300);
	*(unsigned volatile int *)McBSP0_SPCR |= 0x00400000; // Set SPCR GRST=1
	//第1位和第5位分别是XRST和RRST,置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. 
 *******************************************************************************/
 //DESC:从SPCR寄存器的RRDY状态位读
 //RET: 1表示接收方准备好读数据了 0表示没准备好
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
 *******************************************************************************/
 //把读到的16位的数据写到DXR的地址里
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
 *******************************************************************************/
 //从DRR的地址里读一个16位数据
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
*******************************************************************************/
//选择2548的通道
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[tlv2548_readN] = temp1;
	//*(pAddr1++) = tempF;
	//*(pAddr1++) = temp1;
	//T0 = (tempF*1000-424)/(6.25);
	T1 = T1+tempF; 
	tlv2548_readN++;
	if(tlv2548_readN%10==0)
	{
		T0=T1/10.0;
		T1=0.0;
	}
	if(tlv2548_readN >= ADC_SIZE)            
	{
		tlv2548_readN = 0;      
	}
}


/*******************************************************************************
 FUNC	: ext6_isr()
 DESC	: EXT6 interrupt routine. Called when TLV2548 generates the INT pulse.
 ARGS	: void
 RET	: void
 *******************************************************************************/
 //中断6触发2548
interrupt void ext6_isr()
{
	//tlv2548_ready=1;
	tlv2548_totalNdx++;
} 


/**********************************************
 FUNC	: ADC_init()
 DESC	: Initialize TLV2548 
 **********************************************/
 //初始化2548
 void ADC_init()
 {
 	unsigned short temp0,temp1;
    	
 	// Write CFR command 
 	//把write_CFR写道那个地址里	
 	McBSP0_write(write_CFR);
 	Delay(20000);
 	 
    // Write command of Reading CFR register
    //把read_CFR写道那个地址里	
 	McBSP0_write(read_CFR);
 	Delay(20000);
 	
 	// Get value of CFG register
 	//从 McBSP0_DRR+2地址里面读数据到temp0
 	temp0 = McBSP0_read();

 	temp0 = temp0 & 0xC800; 
 	temp1 = (write_CFR) & 0x0C80;
 	
 	if( temp0 == temp1 ) 
 	{
 	 	//看 McBSP0_DRR+2地址里面的数据& 0x0C80 是不是等于 (write_CFR) & 0x0C80
 		tlv2548_ready=1;
 	}
 	else
 	{
 		tlv2548_ready=0;
 	} 
 	tlv2548_totalNdx=0;
 }

 
 
 


⌨️ 快捷键说明

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