Hi,

I'm tryng to connect PCF8563 real time clock to Iris using I2C. 
http://www.datasheetcatalog.com/datasheets_pdf/P/C/F/8/PCF8563.shtml
I'm not sure how to read and write time values.
Here is a tutorial how to do it with bus pirate: 
http://hackaday.com/2009/06/26/parts-i2c-real-time-clock-calendar-pcf8563/
And here is another example from 
http://www.nxp.com/acrobat_download/applicationnotes/AN_pcf8563-73-83-93_real_time_clock.pdf


Setting the clock is a straight forward procedure, setting first the mode and
then the actual time: e.g Friday, July 16 1999, 2’45 pm

        Binary          Hex,addr,comments

        generate I2C-bus start condition
1 0 1 0  0 0 1 W        A2              slave address
0 0 0 0  0 0 0 0        00              word address 0, next bytes are data
0 0 0 0  0 0 0 0        00      00      control/status1, no test modes or POR 
override
0 0 0 0 0 0 0 0 00 01 control/status2, no alarm/timer flags and interrupts
0 0 0 0  0 0 0 0        00      02      setting seconds clear the voltage low 
detector
0 1 0 0  0 1 0 1        45      03      setting minutes
0 0 0 1  0 1 0 0        14      04      setting hours to 14
0 0 0 1  0 1 0 1        16      05      setting days  to 16
0 0 0 0  0 1 0 1        03      06      setting weekdays to Friday
1 0 0 0  0 1 1 1        07      07      setting month to 7 and century bit to 1
1 0 0 1  1 0 0 1        99      08      setting years to 99
1 0 0 0  0 0 0 0        80      09      alarm values reset to 00
1 0 0 0  0 0 0 0        80      0A      alarm values reset to 00
1 0 0 0  0 0 0 0        80      0B      alarm values reset to 00
1 0 0 0  0 0 0 0        80      0C      alarm values reset to 00
1 0 0 0 0 0 0 0 00 0D setting frequency out to 32768Hz e.g. for tuning
0 0 0 0  0 0 0 0        00      0E      timer switched off
        generate I2C-bus stop condition

How to do it in TinyOS 2? Here's what I did:

---------NodeC.nc-----------------------------
module NodeC {
.........
        uses interface Boot;
        uses interface AMSend as Send;
        uses interface Leds;
        
        uses interface Resource;
        uses interface I2CPacket<TI2CBasicAddr> as I2C;
.......

        uint8_t buffer[4];              // write
        uint8_t rbuffer[4];             // read

.....
        event void Boot.booted() {
                
                call Resource.request();        // RTC i2c
        }


        event void Resource.granted() {
                buffer[0] = 0xA2;
                buffer[1] = 0x00;
                buffer[2] = 0xF;
                buffer[3] = 0x00;
        
                // Init time
if (call I2C.write(I2C_START | I2C_STOP, 0xA2, sizeof(uint8_t), &buffer[0]) == SUCCESS) {
                }
                // write to control status 1
if (call I2C.write(I2C_START | I2C_STOP, 0x00, sizeof(uint8_t), &buffer[0]) == SUCCESS) {
                }
                // init seconds to 15
if (call I2C.write(I2C_START | I2C_STOP, 0x02, sizeof(uint8_t), &buffer[2]) == SUCCESS) {
                }
                
                // Read time
if (call I2C.write(I2C_START | I2C_STOP, 0xA3, sizeof(uint8_t), &buffer[0]) == SUCCESS) {
                        call Leds.led2On();
                }
if (call I2C.read(I2C_START | I2C_STOP, 0x02, sizeof(uint8_t), &rbuffer[0]) == SUCCESS)
                //      call Leds.led1On();
                
                dateAndTime = rbuffer[0];
        }

async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {
                
        }
async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {
                call Leds.led2On();
        }

I'm confused about addresses. I2C write address is 0xA2 and read address 0xA3.

How to just send 0xA2 to I2C like in pseudo code:
1 0 1 0  0 0 1 W        A2              slave address                           
                                (how to send it)?
0 0 0 0  0 0 0 0        00              word address 0, next bytes are data
0 0 0 0 0 0 0 0 00 00 control/status1, no test modes or POR override (how this should be sent - it's little different from first line?)

Do I have to always send data to address 0xA2 and seconds address must be also in buffer[2] when I want to init it to for example 15?
Should I call:
buffer[2] = addr + init value (02+0xF)
call I2C.write(I2C_START | I2C_STOP, 0xA2, sizeof(uint8_t), &buffer[2]) == SUCCESS)

Any hints how PCF8563 should be used with TinyOS2 on Iris mote?


Andres Vahter

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to