Post Go back to editing

blackfin bf 531  with dallas ds 1302

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;
}

Parents
  • I will take your word that the write is working.  But I don't really understand how you are verifying the read.  Going through your code above, it appears to me like you send the read command out and then get to this piece of code:

      FIO_SDA_INEN;
      FIO_SDA_IN;

    This code reconfigures the GPIO pin to be an input and enables the input buffer, which is correct.  However, it then proceeds immediately to this code:

      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);
    }

    This code reads the FIO_FLAG_D register before issuing another clock pulse to the DS1302, which means the DS1302 has received the read command but has not yet begun responding, so I think the check for SDA being set is being issued too soon.  You need to clock out another pulse to the DS1302 and then read the FIO_FLAG_D register to see a response.

Reply
  • I will take your word that the write is working.  But I don't really understand how you are verifying the read.  Going through your code above, it appears to me like you send the read command out and then get to this piece of code:

      FIO_SDA_INEN;
      FIO_SDA_IN;

    This code reconfigures the GPIO pin to be an input and enables the input buffer, which is correct.  However, it then proceeds immediately to this code:

      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);
    }

    This code reads the FIO_FLAG_D register before issuing another clock pulse to the DS1302, which means the DS1302 has received the read command but has not yet begun responding, so I think the check for SDA being set is being issued too soon.  You need to clock out another pulse to the DS1302 and then read the FIO_FLAG_D register to see a response.

Children
No Data