In SX Microcontrollers, SX/B Compiler and SX-Key Tool, mumcs01 wrote: So I'm trying to get a M41t82 Real-time clock to work. Its basically like a DS1307 except it supports I2C. I havent used the I2CRead/Write in SX/B yet. But here is my attempt. (Code Below). My problem is I can't seem to clear the Halt Bit (HT) or Oscillator fail bit. I want to verify my code is okay before I look at the hardware, Though I can't imagine my simple hardware setup is bad. Keep in mind, I'm clearing entire bytes in the code below, (Example. the halt bit is in $0C.6 , but I'm just writing zeros to all of register 0Ch, as I'm not using the other bits in the register for anything... I don't think this is a problem. [code] ' Blink1.sxb DEVICE SX28, OSCHS2,TURBO,STACKX,OPTIONX FREQ 50_000_000 Led Pin RA.0 RS485Out Pin RA.1 Relay Pin RA.3 RtcSda Pin RC.6 RtcScl Pin RC.7 Program Setup_Time ' Constants RtcId CON $D0 Ack CON 0 Nak CON 1 ' Variables temp VAR Byte ' Subroutines Start SUB Read_Time SUB Setup_Time: 'Set and clear the Stop Bit i2cstart RtcSda temp = RtcId temp.0 = 0 i2csend rtcsda, temp i2csend rtcsda, $01 i2csend rtcsda, %10000000 i2cstop rtcsda pause 500 i2cstart RtcSda temp = RtcId temp.0 = 0 i2csend rtcsda, temp i2csend rtcsda, $01 i2csend rtcsda, $00 i2cstop rtcsda pause 500 Start ' Clear the byte with the halt bit i2cstart RtcSda temp = RtcId temp.0 = 0 i2csend rtcsda, temp i2csend rtcsda, $0C i2csend rtcsda, 0 i2cstop rtcsda pause 500 ' Clear the Oscillator Fail Flag i2cstart RtcSda temp = RtcId temp.0 = 0 i2csend rtcsda, temp i2csend rtcsda, $0F i2csend rtcsda, 0 i2cstop rtcsda pause 500 return Start: High Led Pause 500 Low Led Read_Time Goto Start ' Get the second from 01h and display them ' Using RS485 to display output. Read_Time: i2cstart RtcSda temp = RtcId temp.0 = 0 i2csend rtcsda, temp i2csend rtcsda, $01 i2cstart RtcSda temp = RtcId temp.0 = 1 i2csend rtcsda, temp i2cRecv rtcsda, temp, Nak i2cstop rtcsda Serout RS485Out, T9600, temp return [/code] Any ideas. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=301673 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)