多主机IIC总线控制(IICCON):
IIC控制总线状态(IICSTAT):
IIC总线地址(IICADD):
IIC发送,接收总线寄存器(IICDS)
IIC总线控制寄存器:
源码如下:
void Rd24C080(U32 slvAddr,U32 addr,U8 *data)
{
_iicMode = SETRDADDR;
_iicPt = 0;
_iicData[0] = (U8)addr;
_iicDataCount = 1;
rIICDS = slvAddr;
rIICSTAT = 0xf0; //MasTx,Start
//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(_iicDataCount!=-1);
_iicMode = RDDATA;
_iicPt = 0;
_iicDataCount = 1;
rIICDS = slvAddr;
rIICSTAT = 0xb0; //MasRx,Start
rIICCON = 0xaf; //Resumes IIC operation.
while(_iicDataCount!=-1);
*data = _iicData[1];
}
void Wr24C080(U32 slvAddr,U32 addr,U8 data)
{
_iicMode = WRDATA;
_iicPt = 0;
_iicData[0] = (U8)addr;
_iicData[1] = data;
_iicDataCount = 2;
rIICDS = slvAddr; //0xa0
rIICSTAT = 0xf0; //MasTx,Start
//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(_iicDataCount!=-1);
_iicMode = POLLACK;
while(1)
{
rIICDS = slvAddr;
_iicStatus = 0x100;
rIICSTAT = 0xf0; //MasTx,Start
rIICCON = 0xaf; //Resumes IIC operation.
while(_iicStatus==0x100);
if(!(_iicStatus&0x1))
break; //When ACK is received
}
rIICSTAT = 0xd0; //Stop MasTx condition
rIICCON = 0xaf; //Resumes IIC operation.
Delay(1); //Wait until stop condtion is in effect.
//Write is completed.
}
void Test_Iic(void)
{
unsigned int i,j,save_E,save_PE;
static U8 data[256];
Uart_Printf('nIIC Test(Interrupt) using AT24C02n');
save_E = rGPECON;
save_PE = rGPEUP;
rGPEUP |= 0xc000; //Pull-up disable
rGPECON |= 0xa00000; //GPE15:IICSDA , GPE14:IICSCL
pISR_IIC = (unsigned)IicInt;
rINTMSK &= ~(BIT_IIC);
//Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx clock=IICCLK/16
// If PCLK 50.7MHz, IICCLK = 3.17MHz, Tx Clock = 0.198MHz
rIICCON = (1<<7) | (0<<6) | (1<<5) | (0xf);
rIICADD = 0x10; //2440 slave address = [7:1]
rIICSTAT = 0x10; //IIC bus data output enable(Rx/Tx)
rIICLC = (1<<2)|(1); // Filter enable, 15 clocks SDA output delay added by junon
Uart_Printf('Write test data into AT24C02n');
for(i=0;i<256;i++)
Wr24C080(0xa0,(U8)i,i);
for(i=0;i<256;i++)
data[i] = 0;
Uart_Printf('Read test data from AT24C02n');
for(i=0;i<256;i++)
Rd24C080(0xa0,(U8)i,&(data[i]));
//Line changed 0 ~ f
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
Uart_Printf('%2x ',data[i*16+j]);
Uart_Printf('n');
}
rINTMSK |= BIT_IIC;
rGPEUP = save_PE;
rGPECON = save_E;
}
void main()
{
Test_Iic();
}
上一篇:ARM中的---汇编指令
下一篇:S3C2440时钟体系
推荐阅读最新更新时间:2024-11-09 23:08
设计资源 培训 开发板 精华推荐
- LTC3520EUF 演示板,具有 400mA 降压功能的 600mA 降压-升压
- LTC3713 的典型应用 - 低输入电压、高功率、无感同步降压 DC/DC 控制器
- 基于TP5400芯片的4节18650电池并联扩展板
- OSC_TEST
- 2021大学生电子设计竞赛E题国二作品(数字模拟信号混合传输收发机)
- LT1172IS8、5V/1.25A 正降压转换器的典型应用
- NB3W1200LMNGEVB、HCSL 推挽输出评估板
- stm32f411 micropython开发板
- 在 AD9279 的 I/Q 输出之后使用 ADA4897-1ARJZ-R2 作为滤波器、I/V 转换器、电流加法器和 ADC 驱动器的典型应用电路
- MC33074DR2G 有源带通滤波器运算放大器的典型应用