Shop OBEX P1 Docs P2 Docs Learn Events
m41t00 I2C clock chip testing — Parallax Forums

m41t00 I2C clock chip testing

CapdiamontCapdiamont Posts: 218
edited 2008-08-06 13:06 in General Discussion
Problem is I'm not there to actually test the chip yet.

I've posted the data sheet. Interesting chip, seems to have an internal osc. Though it has connections for an external osc. An interesting side note, it has a output around 512hz. 512hz is perfect timing, any error of that is an error of timing. That can be corrected using the control bits. Makes me wonder if the SX can measure the difference to calculate the appropriate control bits for correction?

So on to the error. No external osc is used yet, using the sxkey usb. Using the same power supply on both. Doesn't matter if external circuity is used or not. The code seems to program, debug, just fine on the SX48 proto board. However on the SXtech board, it will program, debug up to the point of hitting the run/walk/step key on the debug screen, then unlike the sx48 protoboard, says "sleep".

The only code changes between the two is sx48 vs sx28 plus TURBO, STACKX, OPTIONX. I tried the sx28 without the TURBO, STACKX, OPTIONX and it did the same thing.


I figure pin 1 on the m41t00 is the bottom, left most one, with the pins on the top and bottom, reading the words right side up. Using a cr2032 battery for backup, SDA and SCL are each tied to VDD via 4.69kohm external resistors.
' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------

' tests clock chip m41t00 I2C
' init with most current time
' pauses Maxdelay time, then gets current time
' two subs 1)settime starts comm, sends byte 0, 0, sends info(8 bytes), stops comm
' 2)gettime starts comm, sends byte 0, starts, receieves info(8 bytes), stops comm
' RA.2=SDA
' zero byte, need to send before read or write = slave address bit 7 is read/write
' bit 7=1 is read, 0=write
' 1st byte: seconds register
'2nd byte: minutes register
'3rd byte: century/hours register
'4th byte: day register
'5th byte: date register
'6th byte: month register
'7th byte: years register
'8th byte: control register
' 

' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX 
IRC_CAL IRC_4MHZ
FREQ 4_000_000


' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
' PORT RA 4 bit reserve for serial on all programs, unused set to outout low
' port rb 8 bit, input
' port rc 8 bit, output
' port rd and re 8 bit, unused set to output, low
RAUnused PIN RA OUTPUT 'serial comms
RBUnused PIN RB INPUT PULLUP 'buttons
RCUnused PIN RC OUTPUT 'motor control
SDA PIN RA.2 INPUT 'clock chip SDA
SCL PIN RA.3 INPUT 'clock chip SCL

' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
'on delay time, wait period between on/off, word size
MaxDelay        CON     50
Debounce        CON     1
Pressed         CON     0
SlaveID     CON     $D0             ' clock chip m41t00 I2C
Ack         CON     0
Nak             CON     1



' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
'delaytemp, wait time counter, word size
DelayTemp VAR Word
TempVAR VAR Byte
Time VAR Byte(9)
' zero byte, need to send before read or write = slave address bit 7 is read/write

Loc VAR Time(0) 'addres of device
RW VAR Loc.7 ' bit 7=1 is read, 0=write
' 1st byte: seconds register
Seconds VAR Time(1)
'2nd byte: minutes register
Minutes VAR Time(2)
'3rd byte: century/hours register
Chours VAR Time(3)
'4th byte: day registerDate
Day VAR Time(4)
'5th byte: date register
Date VAR Time(5)
'6th byte: month register
Month VAR Time(6)
'7th byte: years register
Years VAR Time(7)
'8th byte: control register
Control VAR Time(8)
'mode, auto, unlocked, locked, inonly, outonly
'ModeTemp Var Byte
'SwitchTemp Var Bit
watch DelayTemp
watch TempVAR
'watch Loc
watch Seconds
watch Minutes
watch Chours
watch Day
'watch Date
'watch Month
'watch Years
'watch Control

' -------------------------------------------------------------------------
' INTERRUPT
' -------------------------------------------------------------------------

'ISR_Start:
' ISR code here

'ISR_Exit:
' RETURNINT ' {cycles}


' =========================================================================
PROGRAM Start
' =========================================================================

'Pgm_ID:
' DATA "time", 0



' -------------------------------------------------------------------------
' Subroutines / Jump Table
' -------------------------------------------------------------------------
Settime SUB 0
Gettime SUB 0
Inittime SUB 0
Delayloop SUB 0

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
' initialization code here
'Inittime


Main:
DO
Delayloop
Gettime
LOOP

' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------
SUB Inittime 'runs for 1st time, sets varables
  Loc = SlaveID
  Seconds = 0
  Minutes = 4
  Chours = 22
  Day = 5
  Date = 17
  Month = 7
  Years = 8
  Control = 0
  Settime  ' send the varables to clock chip
ENDSUB 

SUB Settime ' send varables to clock chip
  'settime starts comm, sends byte 0, 0, sends info(8 bytes), stops comm
  RW = 0  
  I2CSTART SDA
  'I2CSEND Pin, ByteVal {, AckVar} 
  I2CSEND SDA, Loc
  I2CSEND SDA, 0
  I2CSEND SDA, Seconds
  I2CSEND SDA, Minutes
  I2CSEND SDA, Chours
  I2CSEND SDA, Day
  I2CSEND SDA, Date
  I2CSEND SDA, Month
  I2CSEND SDA, Years
  I2CSEND SDA, Control
  I2CSTOP SDA
ENDSUB

SUB Gettime ' get time from chip
  'gettime starts comm, sends byte 0, starts, receieves info(8 bytes), stops comm
  I2CSTART SDA
  'I2CSEND Pin, ByteVal {, AckVar} 
  RW = 0 'write 1st
  I2CSEND SDA, Loc
  I2CSTART SDA
  RW = 1
  I2CSEND SDA, Loc 'now set up to read
  'I2CRECV Pin, ByteVar, AckVal 

  I2CRECV SDA, Seconds, Ack
  I2CRECV SDA, Minutes, Ack
  I2CRECV SDA, Chours, Ack
  I2CRECV SDA, Day, Ack
  I2CRECV SDA, Date, Ack
  I2CRECV SDA, Month, Ack
  I2CRECV SDA, Years, Ack
  I2CRECV SDA, Control, Ack
  I2CSTOP SDA
ENDSUB

SUB Delayloop 'pause for a bit or while
  PAUSE MaxDelay
ENDSUB


Post Edited (Capdiamont) : 7/19/2008 4:34:37 PM GMT

Comments

  • CapdiamontCapdiamont Posts: 218
    edited 2008-07-21 05:18
    Ok continuing on. Looks like it wants MSB 1st. I think built in SX/B does LSB?
  • CapdiamontCapdiamont Posts: 218
    edited 2008-07-21 14:07
    That idea may need to be scrapped. I've changed it a bit, made RW the loc.0 bit. Seem to get ACK's now. Reading it doesn't seem to be right though. Not getting expected readings. Seems to after a bit come back with 255 for readings.

    ' -------------------------------------------------------------------------
    ' Device Settings
    ' -------------------------------------------------------------------------
    
    DEVICE SX48, OSC4MHZ ', TURBO, STACKX, OPTIONX 
    IRC_CAL IRC_4MHZ
    FREQ 4_000_000
    
    
    ' -------------------------------------------------------------------------
    ' IO Pins
    ' -------------------------------------------------------------------------
    ' PORT RA 4 bit reserve for serial on all programs, unused set to outout low
    ' port rb 8 bit, input
    ' port rc 8 bit, output
    ' port rd and re 8 bit, unused set to output, low
    RAUnused PIN RA OUTPUT 'serial comms
    RBUnused PIN RB INPUT PULLUP 'buttons
    RCUnused PIN RC OUTPUT 'motor control
    SDA PIN RA.2 INPUT 'clock chip SDA
    SCL PIN RA.3 INPUT 'clock chip SCL
    
    ' -------------------------------------------------------------------------
    ' Constants
    ' -------------------------------------------------------------------------
    'on delay time, wait period between on/off, word size
    MaxDelay        CON     50
    Debounce        CON     1
    Pressed         CON     0
    SlaveID     CON     $D0             ' clock chip m41t00 I2C
    Ack         CON     0
    Nak             CON     1
    
    
    
    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    'delaytemp, wait time counter, word size
    DelayTemp VAR Word
    TempVAR VAR Byte
    Time VAR Byte(10)
    ' zero byte, need to send before read or write = slave address bit 7 is read/write
    
    Loc VAR Time(0) 'address of device
    RW VAR Loc.0 ' bit 0 or is it 7?=1 is read, 0=write
    ' 1st byte: seconds register
    Seconds VAR Time(1)
    '2nd byte: minutes register
    Minutes VAR Time(2)
    '3rd byte: century/hours register
    Chours VAR Time(3)
    '4th byte: day registerDate
    Day VAR Time(4)
    '5th byte: date register
    Date VAR Time(5)
    '6th byte: month register
    Month VAR Time(6)
    '7th byte: years register
    Years VAR Time(7)
    '8th byte: control register
    Control VAR Time(8)
    '9th byte ack received
    AckVar Var Time(9)
    AckBit VAR BIT
    'mode, auto, unlocked, locked, inonly, outonly
    'ModeTemp Var Byte
    'SwitchTemp Var Bit
    watch DelayTemp
    watch TempVAR
    watch Loc
    watch Seconds
    watch Minutes
    watch Chours
    watch Day
    watch Date
    watch Month
    watch Years
    watch Control
    watch AckVar
    ' -------------------------------------------------------------------------
    ' INTERRUPT
    ' -------------------------------------------------------------------------
    
    'ISR_Start:
    ' ISR code here
    
    'ISR_Exit:
    ' RETURNINT ' {cycles}
    
    
    ' =========================================================================
    PROGRAM Start
    ' =========================================================================
    
    'Pgm_ID:
    ' DATA "time", 0
    
    
    
    ' -------------------------------------------------------------------------
    ' Subroutines / Jump Table
    ' -------------------------------------------------------------------------
    Settime SUB 0
    Gettime SUB 0
    Inittime SUB 0
    Delayloop SUB 0
    
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    
    Start:
    ' initialization code here
    'Inittime
    
    
    Main:
    DO
    'Delayloop
    Gettime
    LOOP
    
    ' -------------------------------------------------------------------------
    ' Subroutine Code
    ' -------------------------------------------------------------------------
    SUB Inittime 'runs for 1st time, sets varables
      Loc = SlaveID
      Seconds = 0
      Minutes = 55
      Chours = 4
      Day = 2
      Date = 21
      Month = 7
      Years = 8
      Control = 0
      Settime  ' send the varables to clock chip
    ENDSUB 
    
    SUB Settime ' send varables to clock chip
      'settime starts comm, sends byte 0, 0, sends info(8 bytes), stops comm
      RW = 0  
      I2CSTART SDA
      'I2CSEND Pin, ByteVal {, AckVar} 
      I2CSEND SDA, Loc
      I2CSEND SDA, 0
      I2CSEND SDA, Seconds, AckBit
      AckVar.0 = AckBit
      I2CSEND SDA, Minutes, AckBit
      AckVar.1 = AckBit
      I2CSEND SDA, Chours, AckBit
      AckVar.2 = AckBit
      I2CSEND SDA, Day, AckBit 
      AckVar.3 = AckBit
      I2CSEND SDA, Date, AckBit
      AckVar.4 = AckBit
      I2CSEND SDA, Month, AckBit
      AckVar.5 = AckBit
      I2CSEND SDA, Years, AckBit
      AckVar.6 = AckBit
      I2CSEND SDA, Control, AckBit
      AckVar.7 = AckBit
      I2CSTOP SDA
    ENDSUB
    
    SUB Gettime ' get time from chip
      'gettime starts comm, sends byte 0, starts, receieves info(8 bytes), stops comm
      I2CSTART SDA
      'I2CSEND Pin, ByteVal {, AckVar} 
      RW = 0 'write 1st
      I2CSEND SDA, Loc
      I2CSTART SDA
      RW = 1 ' now read
      I2CSEND SDA, Loc 'now set up to read
      'I2CRECV Pin, ByteVar, AckVal 
    
      I2CRECV SDA, Seconds, Ack
      I2CRECV SDA, Minutes, Ack
      I2CRECV SDA, Chours, Ack
      I2CRECV SDA, Day, Ack
      I2CRECV SDA, Date, Ack
      I2CRECV SDA, Month, Ack
      I2CRECV SDA, Years, Ack
      I2CRECV SDA, Control, Ack
      I2CSTOP SDA
    ENDSUB
    
    SUB Delayloop 'pause for a bit or while
      PAUSE MaxDelay
    ENDSUB
    
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-21 17:13
    I don't know if this will be helpful, but I've attached a DS1307 program that works -- you might learn something from it, or just switch to the DS1307 (unless that other chip has a specific feature you need).
  • CapdiamontCapdiamont Posts: 218
    edited 2008-07-21 18:36
    very interesting actually, you used two constants for the address, one for read, and one for write. Seems to confirm what i did by changing bit 0 of address byte. Maybe I just need to work on the reading code more?
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-21 20:45
    If the device is really I2C compatible it should be very easy to use; other than one kind of wonky specialty device (Wii nunchuck), I've never had any trouble with I2C and tend to favor it as a connection scheme. You might want to compare my code to the DS1307 data sheet to see how I implement things, then transfer that knowledge to your chip.
  • CapdiamontCapdiamont Posts: 218
    edited 2008-08-04 02:38
    finally did some looking, differences in the register maps.

    no extra memory in my time chip.
    one has bit 7 as CH/clock halt the other ST/Stop.
    24hour only, thus hour byte is different, bit 0-3 are the same hours, but bit 4,5 are the 10 hours on mine, bit 4 is 10 hours on 1307. on mine bit 6 is cb/century bit, bit 7 is ceb, century enable bit.
    control byte is also different. Other than that they seem to go in the same order.
    mine has bits 0-4 as calibration, then bit5=S/sign for negative positive calibration, bit 6=FT/frequency test bit, bit 7=out/output level

    still working through your program vs the data sheet. I don't always have time to play, so much going on.
  • CapdiamontCapdiamont Posts: 218
    edited 2008-08-06 01:55
    I lost my reply. Grumble.

    I tried your program, i figured, at least I'd be able to get serial output. It didn't work. Using parallax usb2ser. I know it is working perfectly, I use it almost weekly, sometimes more.

    ra.0----pin 2
    ra.1----22kOhm---pin3
    nothing else connected, had pin 5 connected to VSS, didn't seem to help.

    I figured out, that my pins were reversed, and the sx can't transmit through the 22k resistor. I figured that out with txtest.bs2 code. Now the pc doesn't receive what I expect the sx to transmit.
    ' -------------------------------------------------------------------------
    ' Device Settings
    ' -------------------------------------------------------------------------
    
    DEVICE          SX48, OSC4MHZ ', TURBO, STACKX, OPTIONX
    FREQ            4_000_000
    
    
    ' -------------------------------------------------------------------------
    ' IO Pins
    ' -------------------------------------------------------------------------
    TX        PIN    RA.0 OUTPUT        ' serial to PC
    RX        PIN    RA.1 INPUT
    SDA        PIN    RA.2 INPUT        ' uses external pull-up
    SCL        PIN    RA.3 INPUT
    
    ' -------------------------------------------------------------------------
    ' Constants
    ' -------------------------------------------------------------------------
    
    
    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    
    
    ' -------------------------------------------------------------------------
      INTERRUPT
    ' -------------------------------------------------------------------------
    
    'ISR_Start:
      ' ISR code here
    
    'ISR_Exit:
     ' RETURNINT ' {cycles}                                 
    
    
    ' =========================================================================
      PROGRAM Start
    ' =========================================================================
    
    Pgm_ID:
      DATA  "SX/B Template", 0
    
    
    ' -------------------------------------------------------------------------
    ' Subroutines / Jump Table
    ' -------------------------------------------------------------------------
    
    
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    
    Start:
      ' initialization code here
    
    Main:
      ' main code here
    SEROUT TX, T38400, "B"
    
      GOTO Main
    
    
    
    
  • CapdiamontCapdiamont Posts: 218
    edited 2008-08-06 01:58
    looks like both time chips use the same address DOh
  • CapdiamontCapdiamont Posts: 218
    edited 2008-08-06 13:06
Sign In or Register to comment.