Hardware Reference
In-Depth Information
32 buf[0] = 0x00; /
Register 0x00
/
33 memcpy(buf+1,rtc,sizeof
rtc); /
Copy RTC info
/
34
35 iomsgs[0].addr = 0x68; /
DS1307 Address
/
36 iomsgs[0].flags = 0; /
Write
/
37 iomsgs[0].buf = buf; /
Register + data
/
38 iomsgs[0].len = sizeof
rtc + 1; /
Total msg len
/
39
40 msgset.msgs = &iomsgs[0];
41 msgset.nmsgs = 1;
42
43 return ioctl(i2c_fd,I2C_RDWR,&msgset);
44 }
45
46 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
47
Set the DS1307 real−time clock on the I2C bus :
48
49
./ds1307set YYYYMMDDHHMM[ss]
50
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
51 int
52 main(int argc,char
argv) {
53 ds1307_rtc_regs rtc; /
∗∗
8 DS1307 Register Values
/
54 char buf[32]; /
Extraction buffe r
/
55 struct tm t0, t1; /
Unix date / time values
/
56 int v, cx, slen;
57 char
date_format = getenv("DS1307_FORMAT");
58 char dtbuf[256]; /
Formatted date/time
/
59 int rc; /
Return code
/
60
61 /
62
If no environment variable named DS1307_FORMAT, then
63
set a default date/time format.
64
/
65 if ( !date_format )
66 date_format = "%Y−%m−%d %H:%M:%S (%A) " ;
67
68 /
69
Check command line usage :
70
/
71 if ( argc != 2 | | (slen = strlen(argv[1])) < 12 || slen > 14 ) {
72 usage: fprintf(stderr,
73 "Usage : %s YYYYMMDDhhmm[ss]\n",
74 argv[0]);
75 exit(1);
76 }
77
Search WWH ::




Custom Search