平台是2440,编译器是MDK,现在在做裸机的IIC读写AT24C02,但是总是不发生中断
代码如下
#include <string.h>
#include "2440addr.h"
#include "2440lib.h"
#include "def.h"
#include "IIC.h"
static U8 _iicData[IICBUFSIZE];
static volatile int _iicDataCount;
static volatile int _iicStatus;
static volatile int _iicMode;
static int _iicPt;
//===================================================================
// SMDK2440 IIC configuration
// GPE15=IICSDA, GPE14=IICSCL
// "Interrupt mode" for IIC block
//===================================================================
//******************[ Test_Iic ]**************************************
void Test_Iic(void)
{
unsigned int i,j,save_E,save_PE;
static U8 data[256];
Uart_Printf("\nIIC Test(Interrupt) using AT24C02\n");
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] 地址不是 000 吗?为什么这里配置为0001000呢 只要后三位是0应该就行了。
rIICSTAT = 0x10; //IIC bus data output enable(Rx/Tx) (模式没有进行配置)
rIICLC = (1<<2)|(1); // Filter enable, 15 clocks SDA output delay added by junon (应该是5clocks)
Uart_Printf("Write test data into AT24C02\n");
for(i=0;i<256;i++) //这里进行了256次写操作,也就是函数Wr24C080(0xa0,(U8)i,i);每次只进行一个数据的写操作。
Wr24C080(0xa0,(U8)i,i); //slvaddr, addr, data
//而且从i从0递增到255也能够看出,写数据的地址是从EEPROM的最低地址0进行写直到,256
for(i=0;i<256;i++)
data[i] = 0;
Uart_Printf("Read test data from AT24C02\n");
for(i=0;i<256;i++)
Rd24C080(0xa1,(U8)i,&(data[i]));