att.c

来自「LPC213X对ATT7026芯片的读写程序」· C语言 代码 · 共 109 行

C
109
字号
/****************************************Copyright (c)**************************************************

**--------------File Info-------------------------------------------------------------------------------
** File name:			Att.c
** Last modified Date:  2007-07-19
** Last Version:		1.0
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Created by:			
** Created date:		2007-07-19
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			
** Modified date:		2006-07-19
** Version:
** Descriptions:		
**
********************************************************************************************************/
#include "Att.h"
#include "i2c1int.h"
#include "Func.h"



 
uint32 AttRead(uint8 reg)  
{
 uint32 data,t;
 IO0CLR= SCK1;
 Delay(1);
 IO1CLR=ADCS;
 Delay(1);
 data = SSP_SendData(reg);
 Delay(3);
 t = SSP_SendData(0);
 data = (t<<16)&0xff0000;
 t = SSP_SendData(0);
 data +=  (t<<8)&0xff00;
 t = SSP_SendData(0);
 data += t;
 Delay(1);
 IO1SET = ADCS;
 IO0CLR= SCK1;
 
 return(data);
}

void AttWrite(uint8 reg,uint32 data)
{
 uint8 dum;
 IO0CLR= SCK1;
 Delay(1);
 IO1CLR=ADCS;
 Delay(3);
 dum=SSP_SendData(reg|0x80);  
 dum=SSP_SendData(0xff&(data>>16));
 dum=SSP_SendData(0xff&(data>>8));
 dum=SSP_SendData(0xff&data);
 IO1SET = ADCS;
 IO0CLR= SCK1;
 
} 

/********************************************************************************************************
** 函数名称:MSPI_Init()
** 函数功能:初始化SPI接口,设置为主机。
** 入口参数:无
** 出口参数:无
*********************************************************************************************************/
void  SSP_Init(void)
{  
	PINSEL1 = (PINSEL1 & (~(0x3F << 2))) | (0x2a << 2) ;
    SSPCR0 = (0x00 << 8) |              // SCR  设置SPI时钟分频???
             (0x01 << 7) |              // CPHA 时钟输出相位,仅SPI模式有效 
             (0x00 << 6) |              // CPOL 时钟输出极性,仅SPI模式有效
             (0x00 << 4) |              // FRF  帧格式 00=SPI,01=SSI,10=Microwire,11=保留
             (0x07 << 0);               // DSS  数据长度,0000-0010=保留,0011=4位,0111=8位,1111=16位

    SSPCR1 = (0x00 << 3) |              // SOD  从机输出禁能,1=禁止,0=允许
             (0x00 << 2) |              // MS   主从选择,0=主机,1=从机
             (0x01 << 1) |              // SSE  SSP使能,1=允许SSP与其它设备通信
             (0x00 << 0);               // LBM  回写模式
    SSPCPSR = 54; //0x36;         
//    SSPIMSC = 0x07;//0x04;                     // 中断屏蔽寄存器
    SSPICR  = 0x03;                     // 中断清除寄存器
   
}

/********************************************************************************************************
** 函数名称:SSP_SendData()
** 函数功能:向SPI总线发送数据。
** 入口参数:data   待发送的数据
** 出口参数:返回值为读取的数据
********************************************************************************************************/
uint8  SSP_SendData(uint8 data)
{  
    SSPDR = data;
    while( (SSPSR&0x10)!=0);		// 等待SPIF置位,即等待数据发送完毕
   
    return(SSPDR);
}




⌨️ 快捷键说明

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