I am trying to use 531 to read and write ds 1302 dallas.but there are some questons.with the digital storage oscilloscope, we can get the the write singals. but no read ones.
this is part of the programs ,is there any thing wrong with the 531 fio set?
//****************************************************************************
#define FIO_RST_0UT_EN ((*pFIO_DIR)|= RST)
#define FIO_RST_H ((*pFIO_FLAG_D)|=RST)
#define FIO_RST_L ((*pFIO_FLAG_D)&=~RST)
#define FIO_SDA_0UT_EN ((*pFIO_DIR)|=SDA)
#define FIO_SDA_H ((*pFIO_FLAG_D)|=SDA)
#define FIO_SDA_L ((*pFIO_FLAG_D)&=~SDA)
#define FIO_SCL_0UT_EN ((*pFIO_DIR)|=SCL)
#define FIO_SCL_H ((*pFIO_FLAG_D)|=SCL)
#define FIO_SCL_L ((*pFIO_FLAG_D)&=~SCL)
#define FIO_SDA_IN ((*pFIO_DIR)&=~SDA)
#define FIO_SDA_INEN ((*pFIO_INEN)|=SDA)
#define FIO_SDA_INEN_RESET ((*pFIO_INEN)&=~SDA)
void delay1302(unsigned int dly)
{
for(;dly>0;dly--);
}
// write command and data to ds 1302
void DS1302_ByteWrite(uchar command,uchar Byte)
{
uchar n=0;
FIO_RST_0UT_EN;
FIO_SDA_0UT_EN;
FIO_SCL_0UT_EN;
delay(3);
FIO_RST_L;
delay1302(10);
FIO_RST_H;
delay1302(100);
for(n=0;n<8;n++)
{
delay1302(2);
if(command&0x01)
{
FIO_SDA_H;
}
else
{
FIO_SDA_L;
}
delay1302(25);
FIO_SCL_L;
delay1302(50);
FIO_SCL_H;
delay1302(25);
command>>=1;
}
for(n=0;n<8;n++)
{
delay1302(2);
if(Byte&0x01)
{
FIO_SDA_H;
}
else
{
FIO_SDA_L;
}
delay1302(25);
FIO_SCL_L;
delay1302(50);
FIO_SCL_H;
delay1302(25);
Byte>>=1;
}
FIO_SCL_L;
delay1302(40);
FIO_RST_L;
delay1302(100);
FIO_RST_H;
}
//write command to ds 1302 and read time
uchar DS1302_ByteRead(uchar command)
{
uchar i=0,n=0,readback=0;
FIO_RST_0UT_EN;
FIO_SDA_0UT_EN;
FIO_SCL_0UT_EN;
FIO_RST_L;
delay1302(10);
FIO_RST_H;
delay1302(100);
for(n=0;n<8;n++)
{
delay1302(2);
if(command&0x01)
{
FIO_SDA_H;
}
else
{
FIO_SDA_L;
}
delay1302(25);
FIO_SCL_L;
delay1302(50);
FIO_SCL_H;
delay1302(25);
command>>=1;
}
FIO_SDA_INEN;
FIO_SDA_IN;
delay1302(20);
FIO_SDA_INEN;
FIO_SDA_IN;
for(i=0;i<8;i++)
{
delay1302(2);
readback>>=1;
if((*pFIO_FLAG_D)&SDA)
{
readback|=0x80; }
delay1302(25);
FIO_SCL_L;
delay1302(50);
FIO_SCL_H;
delay1302(25);
}
FIO_SCL_L;
delay1302(100);
FIO_RST_L;
delay1302(100);
FIO_SDA_INEN_RESET;
FIO_SDA_0UT_EN;
return readback;
}