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

📄 at45db161.c

📁 使用STR710的IIC接口对PCF8563时钟芯片的测试程序.采用KEIL UV3编译.使用了MDK3.05操作系统.
💻 C
字号:
/*=========================================================================*
 * 项目:		
 * 文件:		.\src\bsp\at45db161.c
 * 描述:		at45db161的驱动程序
 * 编译:		
 * 版本:		0.1
 * 创建日期:	2007年6月21日
 * 最后修订:	
 * 函数列表:
 * 修改历史:		
 * 编译环境:	RVMDK 3.05 + RTL-ARM 3.05
 * ----------------------------------------------------------------------
 * 使用BSPI1,主模式,BSPI1的SSN脚接10K上拉电阻
 * AT45DB的片选CS脚接str710的P1。15
*=========================================================================*/
#include <71x_lib.h>

#define BSPI1_SO		0x10
#define BSPI1_SI		0x20
#define BSPI1_SCLK		0x40
#define BSPI1_SSN		0x80
#define AT45_CS			0x02

#define  AT45_Chip_Select_ENABLE  GPIO1->PD &= ~AT45_CS
#define  AT45_Chip_Select_DISABLE GPIO1->PD |=  AT45_CS
/*=============================================================================
 * 名称:			SC752Delay
 * 描述:			延时
 * 创建:			2007年6月22日
 * 最后修订:		
 * 调用:			None
 * 输入参数:		延时时间
 * 返回值:			None
 * 特殊说明:		RVMDK 3.05 + RTL-ARM 3.05
 *=============================================================================*/
void AT45Delay( u32 n )
{
	while ( n-- )
 	;
}
/*=============================================================================
 * 名称:			init BSPI1 for AT45DB161
 * 描述:			初始化BSPI1
 * 创建:			2007年6月20日
 * 最后修订:		
 * 调用:			None
 * 输入参数:		None
 * 返回值:			None
 * 特殊说明:		RVMDK 3.05 + RTL-ARM 3.05
 *=============================================================================*/
void initAT45DB161(void)
{

	GPIO_Config (GPIO0, BSPI1_SO | BSPI1_SI | BSPI1_SCLK, GPIO_AF_PP);
	GPIO_Config (GPIO1, AT45_CS, GPIO_OUT_PP);
	GPIO_Config (GPIO0, BSPI1_SSN, GPIO_IN_TRI_CMOS);
	AT45_Chip_Select_DISABLE;
/* -------------------------------------------
Configue BSPI1 as a Master
------------------------------------------- */
  /* Initialize BSPI1 */
	BSPI_Init ( BSPI1 ) ;
	BSPI_ClockDividerConfig ( BSPI1, 6); // Configure Baud rate Frequency :-->APB1/8 
	BSPI_Enable ( BSPI1, ENABLE );	 //Enable BSPI1 */
	BSPI_MasterEnable ( BSPI1, ENABLE);//Configure BSPI0 as a Master */
	BSPI_ClkActiveHigh( BSPI1, DISABLE);//Configure the clock to be active high */
	BSPI_ClkFEdge( BSPI1, DISABLE);	//Enable capturing the first Data sample on the first edge of SCK */
	BSPI_8bLEn( BSPI1, ENABLE);	//Set the word length to 8 bit */
//	BSPI_TrFifoDepth(BSPI1, 1);	//Set tx fifo 1 word
//	BSPI_RcFifoDepth(BSPI1, 1);	//Set rx fifo 1 word
}

/*=============================================================================
 * 名称:			SEND and receive data from AT45DB
 * 描述:			以8位方式从AT45DB发送和接收数据
 * 创建:			2007年6月20日
 * 最后修订:		
 * 调用:			None
 * 输入参数:		需要发送的8位数据
 * 返回值:			接收到的8位数据
 * 特殊说明:		RVMDK 3.05 + RTL-ARM 3.05
 *=============================================================================*/
u8 BPSI_DataSendReceive(u8 data)    
{
	u8 temp;
	while(BSPI1->CSR2&BSPI_RFNE)
	temp = BSPI1->RXR;
	while(!(BSPI1->CSR2&BSPI_TFE));    /*  Wait until the Transmit FIFO is empty */
	BSPI1->TXR = data<<8;              /*  Send data to Transmit buffer */
	while(!(BSPI1->CSR2&BSPI_RFF));    /*  Wait until the end of transmission */
	temp = (BSPI1->RXR)>>8;            /*  Read the received data */
	return temp;                     
}
/*=============================================================================
 * 名称:			Reset AT45DB
 * 描述:			复位AT45DB
 * 创建:			2007年6月20日
 * 最后修订:		
 * 调用:			None
 * 输入参数:		None
 * 返回值:			None
 * 特殊说明:		RVMDK 3.05 + RTL-ARM 3.05
 					at45->cs:str710->p1.15
 *=============================================================================*/
void AT45_Reset(void)
{
	AT45_Chip_Select_DISABLE;
	os_dly_wait (8);
	AT45_Chip_Select_ENABLE; //select dataflash
}

u8 AT45_Read_REG(u8 reg)
{
	u8 tmp;
	AT45_Chip_Select_ENABLE;
	BPSI_DataSendReceive(reg);
	tmp = BPSI_DataSendReceive(0x0);
	AT45_Chip_Select_DISABLE;

	return tmp;
}

/*=============================================================================
 * 名称:			Wait for AT45DB ready
 * 描述:			等待AT45DB进入就绪状态
 * 创建:			2007年6月20日
 * 最后修订:		
 * 调用:			None
 * 输入参数:		None
 * 返回值:			None
 * 特殊说明:		RVMDK 3.05 + RTL-ARM 3.05
 *=============================================================================*/
void AT45_Ready(void)
{
	u8 tmp = 0x00;

	while(!(tmp & 0x80))
	{
	   tmp = AT45_Read_REG(0xd7);
	}
}
/*=============================================================================
 * 名称:			Detect AT45DB
 * 描述:			检测AT45DB
 * 创建:			2007年6月20日
 * 最后修订:		
 * 调用:			None
 * 输入参数:		None
 * 返回值:			AT45DB的状态寄存器中的容量位,根据容量可确定AT45DB型号
 * 特殊说明:		RVMDK 3.05 + RTL-ARM 3.05
 *=============================================================================*/
u8 Detect_AT45DB(void)
{
	u8 temp;

	AT45_Ready(); //wait until dataflash is ready
	temp = AT45_Read_REG(0xD7);

	return (temp>>2)&0x0f;
}

⌨️ 快捷键说明

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