Dears all, there is some fault in following procedure. Function returns
value, but with same number. I check circuit with osciloskop, I put to code
output about reading DS1302(LED signal), it looks good. But I´m not sure
with bit shifts there. Do you have any idea what could be wrong?


unsigned char read_DS1302 (unsigned char adresa)
{
unsigned char cc1, data;
init_DS1302();
data=0;
RESET = 1; // start communication
for (cc1=0; cc1<8; cc1++) // send command BYTE
{
if ((adresa&0x01) == 1) SDO = 1;
else SDO = 0;
adresa = adresa >> 1; // bit shift right
SCLK = 0;
delay_us(1);
SCLK = 1;
delay_us(1);
SCLK=0;
}


SDA_M = 0; // SDA like input
data = 0;
for (cc1=0; cc1<8;cc1++) // data transfer
{
SCLK = 0;
delay_us(2);
data = data|(unsigned char)SDI;
LED = !(unsigned char)SDI;
data>>1;
SCLK = 1;
delay_us(2);
}
SDO =0; // end communication
SCLK = 0;
RESET =0;
return data;
}
-- 
View this message in context: 
http://www.nabble.com/read-data-between-DS1302-and-ATMEGA8-tp21761333p21761333.html
Sent from the AVR - General mailing list archive at Nabble.com.



_______________________________________________
AVR-chat mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-chat

Reply via email to