This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF24LE1 IIC problem

hello,we want to use NRF24LE1 IIC to communicate with NFC cards.

firstly,we choose NRF24LE1 IIC(hardware),but it is failed.
then,we use simulation of IIC(software) to communicate with NFC cards successfully,
but real-time performance does not meet the requirement.
so,we should dubug NRF24LE1 IIC(hardware) again.

we have watched the wave of IIC timing(hardware) by a oscillograph,
and found the timing is not correct.

please give me some advise,thank you very much!

the code is as follows:


main program:

CLKCTRL = 0x28;//配置时钟
CLKLFCTRL = 0x01;

IIC_init();//IIC初始化

writebyte(0,0xA5);

rbuffer[0] = readbyte(0);

subprogram:

#define READY (W2CON1&0X01) //if ready ==1,not ready==0
#define ACK (W2CON1&0X02 ) //1;no ack and 0 ack
#define EN2WIRE() W2CON0|=0x01; //enable 2 wire
#define DISABLE2WIRE() W2CON0&=0xFE;
#define STOP() W2CON0|=0x20;
#define START() W2CON0|=0x10;
#define FREQSEL(x) W2CON0|=(x<<2); //1 100K 2 400K
#define MODE(x) W2CON0&=(0xff-0x02);W2CON0|=x; //master or slave


void IIC_init()
{
EN2WIRE(); //使能2-wire

FREQSEL(1);//100KHz

MODE(MASTER);//主模式

W2CON1|=0x20; //屏蔽所有的中断

}

unsigned char readbyte(unsigned int addr)
{
unsigned char byte;

START();
W2DAT=(unsigned char)(slaveaddr+0);//write from slave
while(ACK);
W2DAT=addr;
while(ACK);
START();
W2DAT=(unsigned char)(slaveaddr+1);//read from slave
while(ACK);
while(!READY);
byte=W2DAT;
STOP();
return byte;
}


void writebyte(unsigned int addr,unsigned char dat)
{
unsigned char byte=dat;
START();
W2DAT=(unsigned char)(slaveaddr+0);//write
if(!ACK) //IF ACK
W2DAT=addr;
if(!ACK)
W2DAT=byte;
STOP();
}

Parents Reply Children
No Data
Related