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

📄 digipot_test.c

📁 ADI Blackfin BF51X 範例程式
💻 C
字号:
/*******************************************************************
Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential.  By using this software
you agree to the terms of the associated Analog Devices License Agreement.

Project Name:  	Power_On_Self_Test

Hardware:		ADSP-BF518F EZ-Board

Description:	This file performs the digipot setup and test on the EZ-Board.
*******************************************************************/


/*******************************************************************
*  function prototypes
*******************************************************************/
void Reset_TWI(void);
void TWI_MasterMode_Write(unsigned short DeviceAddr, unsigned char *TWI_Data_Pointer, unsigned short Count, unsigned short TWI_Length);
void TWI_MasterMode_Read(unsigned short DeviceAddr, unsigned char *TWI_Data_Pointer, unsigned short Count);


/*******************************************************************
*  global variables and defines
*******************************************************************/
#define DIGIPOT_ADDRESS 0x18	/* upper 7 bits = 0x18, write = 0x30, read = 0x31 */
#define RDAC_STEP_VALUE_1_4 0x03	/* step value 3 gives us 1.4V */

unsigned char WriteRDAC[] = { 0x00, RDAC_STEP_VALUE_1_4 };	/*  */
unsigned char StoreRDAC[] = { 0xc0 };						/*  */
unsigned char ReadRdacPrefix[] = { 0x00 };					/*  */
unsigned char ReadEepromPrefix[] = { 0x20 };				/*  */


/*******************************************************************
*   Function:    PROGRAM_DIGIPOT
*   Description: This programs the digipot on the EZ-Board.
*******************************************************************/
int PROGRAM_DIGIPOT(void)
{
	Reset_TWI();		/* reset the TWI interface */

	/* write the RDAC register */
	TWI_MasterMode_Write( DIGIPOT_ADDRESS, WriteRDAC, 1, 2);
	asm("nop;");
	asm("nop;");
	asm("nop;");
	asm("nop;");

	/* store the RDAC value in digipot EEPROM */
	TWI_MasterMode_Write( DIGIPOT_ADDRESS, StoreRDAC, 1, 1);

	return 1;
}

/*******************************************************************
*   Function:    CHECK_DIGIPOT
*   Description: This verifies the digipot has been programmed on the EZ-Board.
*******************************************************************/
int CHECK_DIGIPOT(void)
{
	unsigned char rdac = 0x00;		/* stored RDAC value */
	unsigned char eeprom = 0x00;	/* stored EEPROM value */

	Reset_TWI();		/* reset the TWI interface */

	/* read RDAC and EEPROM */
	TWI_MasterMode_Write( DIGIPOT_ADDRESS, ReadRdacPrefix, 1, 1);
	TWI_MasterMode_Read( DIGIPOT_ADDRESS, &rdac, 1);

	TWI_MasterMode_Write( DIGIPOT_ADDRESS, ReadEepromPrefix, 1, 1);
	TWI_MasterMode_Read( DIGIPOT_ADDRESS, &eeprom, 1);

	/* both values should match the RDAC value that we program */
	if ( (RDAC_STEP_VALUE_1_4 == rdac) && (RDAC_STEP_VALUE_1_4 == eeprom) )
		return 1;
	else
		return 0;
}



⌨️ 快捷键说明

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