[Tinyos-help] Connecting PCF8563 RTC to Iris
Michael Schippling
schip at santafe.edu
Fri Jul 31 09:06:20 PDT 2009
I'm just now working with the T1 I2C stuff so some
of this may be relevant...First, isn't the address
bit shift think fun? I'm sure there's a good reason
for it, but I can't think of any...
readPacket, if it's like T1, sends the start and
slave addr (with the read bit set), samples the
input for the specified number of bytes, and then
sends a stop. I have yet to grok the ack part, but
that seems to be part of the hdw protocol and not
anything softwareish. If you need to exec a command
before reading, such as selecting a register, that
is a separate 'transaction' done with a previous
writePacket. Each packet operation has a done()
method that you need to catch before continuing.
I found a fairly good example of the pattern in
the Moteworks TaosPhoto sensor code, or in T1:
tinyos-1.x/tos/sensorboards/micawb/TaosPhotoM.nc
What your device returns for each type of request
should be described in it's spec sheet.
MS
Andres Vahter wrote:
> I got little furher.
> Now I know that 7 bit address must be used. Instead of 0xA2, 0x51 must
> be used. I2C component shifts it to left and adds R/W bit.
>
>
>
> module NodeC {
> uses interface Boot;
> uses interface Resource;
> uses interface I2CPacket<TI2CBasicAddr> as I2C;
> ................
> uint8_t i2cState=0;
> uint8_t buffer[17];
> ................
>
> event void Boot.booted() {
> call Resource.request(); // RTC i2c
> }
> event void Resource.granted() {
> buffer[0] = 0x00; // word address 0, next bytes are data,
> memory address is auto incremented
> buffer[1] = 0x00; // 00 control/status1, no test modes or
> POR override
> buffer[2] = 0x00; // 01 control/status2, no alarm/timer
> flags and interrupts
> buffer[3] = 0x02; // 02 setting seconds clear the
> voltage low detector
> buffer[4] = 0x05; // 03 setting minutes
> buffer[5] = 0x14; // 04 setting hours
> buffer[6] = 0x03; // 05 setting date
> buffer[7] = 0x06; // 06 setting day of week
> buffer[8] = 0x04; // 07 setting century and months
> buffer[9] = 0x09; // 08 setting years
> buffer[10] = 0x80; // 09 setting minute alarm
> buffer[11] = 0x80; // 0A setting hour alarm
> buffer[12] = 0x80; // 0B setting day alarm
> buffer[13] = 0x80; // 0C setting weekday alarm
> buffer[14] = 0x83; // 0D setting weekday alarm
> buffer[15] = 0x00; // 0E timer control
> buffer[16] = 0x00; // 0F timer
>
> i2cState = 0;
> call I2C.write(I2C_START | I2C_STOP, 0x51, 17, buffer); // 0xA2
> >> 1
>
> }
> async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t
> length, uint8_t* data) {
>
> // page 16 fig 15.
> if(i2cState == 0){
> buffer[0] = 0x02; // seconds - register address
> i2cState = 1;
>
> call I2C.write(I2C_START, 0x51, 1, &buffer[0])
>
>
> }
> else if(i2cState == 1){
> buffer[0] = 0x00; // not needed - how to send no data?
> i2cState = 2;
>
> call I2C.read(I2C_START | I2C_STOP, 0x51, 1, &buffer[0])
> }
> }
> async event void I2C.readDone(error_t error, uint16_t addr, uint8_t
> length, uint8_t* data) {
> uint16_t val;
> val = data[3];
>
> ..................
> }
>
>
> I have a question about I2C.readDone *data value. What it contains?
> It doesn't return only requested register value?
> I can see that data[3] contains seconds, data[4] minutes etc - it
> contains the same values what I initalized in Resource.granted() event .
> Why it is so, why doesn't it contain just what I have requested?
> Actually I think my reading logic is faulty.
>
> According to
> http://www.datasheetcatalog.com/datasheets_pdf/P/C/F/8/PCF8563.shtml page
> 16 fig 15. master must send no data after slave read address.
> Can I do it with I2CPacket.read? As I can see it can not send no data to
> slave read address.
>
> Read sequence ( page 16 fig 15 ):
> START | SLAVE ADDRESS Write(0xA2) || ack || WORD ADDRESS || ack || SLAVE
> ADDRESS Read (0xA3) || ack || DATA | STOP
>
> How do to that reading part - should I use lower level I2C components or
> is it possible to do it with I2CPacket?
>
>
> Andres Vahter
More information about the Tinyos-help
mailing list