Ported to 18F4550...why it doesn't work?
Quote:
Originally Posted by
Santana
This code now whats thanks to you bruce
when the main time match the alarm time an interupt is generated on INTA (PIN 3)
my led goes low then back high .
Attempted to adapt your code to the 18F4550 as listed below. Interestingly, the LED I have on Pin3 is low all the time and doesn't go high when the time should be matching the A1 alarm time. Can't figure out why this is or why the alarm doesn't work. Would you please take a look at my code & see if you can see where I am going wrong? Thanks! Will list code in another post since this one exceeds character limits.
Made changes...new code still doesn't work w/ DS1337
Quote:
Originally Posted by
BobK
I only have a few minutes before I need to go to work but I use the DS1337 quite a bit and this is all I use to set the time information and to display it. Nothing else and it works great. I will check back tonight when I get home.
Thanks, BobK. I studied your code you posted and made some changes in my code to reflect what I saw. I have listed my latest code below. Also added a DEFINE OSC 48 statement that was pointed out to me by someone else as needed since I am using 48 MHz CPU clock derived from the 96 MHz clock for a USB interface I will also be adding to this code at later time.
I also notice an anomally in my breadboard setup of the DS1337 circuit when I connect my oscilloscope to the SQW/INTB output:
1) When power is applied to the DS1337 circuit but the code is erased from my controlling 18F4550 MCU, I see a 32.7787kHz clock signal on my oscilloscope at the SQW output of the DS1337.
2) When I then program the 18F4550 the clock signal on SQW output disappears (flat line at 0 volts).
This appears to be opposite to what should be happening. The clock should appear at SQW when the MCU is programmed, time has been set and DS1337 is clocking....this isn't happening.
I also checked the INTA output to see if the Alarm1 was happening 30 seconds after programming and setting the DS1337 time, and it isn't happening either.
Any ideas what may be causing all this?
Code:
Include "Modedefs.Bas"
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
DEFINE OSC 48
;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
'**--SETUP FOR USING 2x16 LCD THAT IS INSTALLED IN EASYPIC6----------
'( commented out during testing of DS1337 operations)
'********************************************************************
' LCD DEFINES FOR USE WIH 2x16 LCD..commented out during testing
' DEFINE LCD Control Constants **
'====================================
'I CON 254 ' Control Byte
'Clr CON 1 ' Clear the display
'Line1 CON 128 ' Point to beginning of line 1
'Line2 CON 192 ' Point to beginning of line 2
'**-------------SETUP FOR USING DS1337 Real Time Clock------------------
' Setup Hardware for uart
' ==================
DEFINE HSER_BAUD 115200
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1
' Aliased Variables for CLock
' ====================
Alarm1 VAR PORTB.4 ' Output of Alarm1 signal
Alarm2 VAR PORTB.5 ' Output of Alarm2 signal
DS_SCL VAR PORTB.1 ' I2C clock pin
DS_SDA VAR PORTB.0 ' I2C data pin
RTC CON %11010000 ' RTC device write address(byte addressing)
'contrl CON %00011001 ' Sets RS1 & RS2,
' clears INTCN to enable Alarm1 & 3.2768kHz
' outputs separately.
' -------------- RTC Address definitions
SecReg CON $00 ' seconds address (00 - 59)
' MSB of SecReg must be set to a 0 to enable RTC
MinReg CON $01 ' minutes address (00 - 59)
HourReg CON $02 ' hours address (01 - 12) or (00 - 23)
DayReg CON $03 ' day address (1 - 7)
DateReg CON $04 ' date address (01 - 28/29, 30, 31)
MonthReg CON $05 ' month address (01 - 12)
YearReg CON $06 ' year address (00 - 99)
'Alarm 1 Address definitions
'=================
Alm1sec CON $07 ' Alarm 1 seconds address (00 - 59)
Alm1min CON $08 ' Alarm 1 minutes address (00 - 59)
Alm1hr CON $09 ' Alarm 1 hours address (01 - 12) or (00 - 23)
Alm1Day CON $0A ' Alarm 1 day address (1 - 7)
'Alarm 2 Address definitions
'==================
Alm2min CON $0B ' Alarm 2 minutes address (00 - 59)
Alm2hr CON $0C ' Alarm 2 hours address (01 - 12) or (00 - 23)
Alm2Day CON $0D ' Alarm 2 day address (1 - 7)
' Alias of Clock register addresses
'========================
ContReg CON $0E ' CONTROL register address
StatusReg CON $0F ' STATUS register address
' Clock Variables
'=========
sec VAR BYTE ' seconds
MINs VAR BYTE ' minutes
hr VAR BYTE ' hours
day VAR BYTE ' day
date VAR BYTE ' date
mon VAR BYTE ' month
yr VAR BYTE ' year
'ALARM1 VARIABLES
'==============
A1sec VAR BYTE ' seconds
A1MINs VAR BYTE ' minutes
A1hr VAR BYTE ' hours
A1day VAR BYTE ' day
'ALARM2 VARIABLES
'==============
A2MINs VAR BYTE ' minutes
A2hr VAR BYTE ' hours
A2day VAR BYTE ' day
' Initialize Hardware
' -------------------
'Set registers
TRISA =%00000000
TRISB =%00000000
TRISC =%00000000
TRISD =%00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
INTCON2.7 = 0
' Initialize Display ' commented out during DS1337 testing
'Pause 1000 ' Delay to let LCD start up
'LCDOut I,CLR:Pause 50 ' Clear Display
'LCDOut I,Line1+2," RTC TEST " ' Display "RTC TEST" on 1st line
'Pause 500
'LCDOut I,Line2+2,"..Power On.. !!" ' Display "Power on" on 2nd line
'PAUSE 1000
GoSub SetTimeAndDate
' Main Program Loop
' -----------------
Main:
' Read the current time and ALARM settings from the DS1337
I2CRead DS_SDA, DS_SCL, RTC, SecReg,[sec,MINs,hr,day,date,mon,yr]
Pause 20
I2CREAD DS_SDA, DS_SCL, RTC, Alm1sec,[A1sec,A1MINs,A1hr,A1day]
Pause 20
'I2CRead DS_SDA, DS_SCL, RTC, Alm2min,[A2MINs,A2hr,A2day] ' No Alarm2 during test
'PAUSE 20
' Display Time and ALARM2 settings on the LCD display 'No LCD during test
GoTo Main
End ' Insure program stops if reaches here
' START LIST OF SUBROUTINES
'***********************
'DisplayTest: 'Commented out during test of DS1337 code
'============
'LCDOut I,CLR:Pause 50 ' Clear Display
'LCDOut I,Line1+2," TEST " ' Display "TEST" on 1st line
'PAUSE 500
'LCDOut I,Line2+2,"..Power On.. !!" ' Display "Power on" on 2nd line
'Pause 1000
'RETURN
SetTimeAndDate:
'============
' Initialize clock variables to 0
yr=0:date =0:mon =0:day=0:hr=0:MINs=0:sec=0
A1sec=0:A1MINs=0:A1hr=0:A1Day=0
A2MINs=0:A2hr=0:A2day=0
' The BCD constants below set the RTC to: 19:20:30 on 06-02-2008
yr=$08
mon=$06
date=$02
day=$01
hr=$19
MINs=$20
sec=$30
'Define ALARM1 FOR 19:21:00 & to alarm when hours, minutes, & secs match.
' This requires AIM1=AIM2=AIM3=0 and AIM4=1
' (A1xxx + $80 or A1xxx + 128d sets bit 7 in AIM1,A1M2,A1M3,A1M4)
A1hr = $19 ' for AIM1 = 0
'Bit6 must be 0 for 24 hour clock
A1MINs = $21 'for AIM2 = 0
A1sec = $00 'for AIM3 = 0
A1day = $01 + $80 '$01 + $80 = $81 = 129d = $10000001 for AIM4 = 1
'DY/_DT Bit6 = 0 for using Day of month alarm
'Define ALARM2 FOR 19:22:00 'Commented out during DS1337 testing of 1Hz
'A2hr=$19
'A2MINs=$22
'A2day=$01 'DY/_DT Bit6 = 0 for using Day of month alarm
'Set the main Time
I2CWrite DS_SDA, DS_SCL, RTC, SecReg,[sec,MINs,hr,day,date,mon,yr]
Pause 20
'Set the Alarm1 Time
I2CWrite DS_SDA, DS_SCL, RTC,Alm1sec,[A1sec,A1MINs,A1hr,A1day]
Pause 20
'Set the Alarm2 Time ' Alarm2 Commented out during testing
'I2CWrite DS_SDA, DS_SCL, RTC,Alm2min,[A2MINs,A2hr,A2day,contrl]
'Pause 20
'I2CRead DS_SDA, DS_SCL, RTC, Alm2min,[A2MINs,A2hr,A2day]
' Clear STATUS and set CONTROl registers
I2CWrite DS_SDA,DS_SCL,RTC,StatusReg,[$00] ' Clear STATUS register
PAUSE 20
I2CWrite DS_SDA, DS_SCL, RTC, ContReg,[%00011001]' Starts the oscillator, sets the SQW/OUT, enables INTA
Pause 20
Return
I2C/LCD conflict on PortB on EasyPic6
Quote:
Originally Posted by
BobK
Hi Jellis,
I finally got a chance to look at your program. You have the pins of PortB setup for the LCD and you are also using PortB4. & 5 for the RTC alarms and PortB.0 and 1 for the I2C connections. You need to change them and set the RTC connections on a different Port.
BobK
Yes, I am aware of that. It is because the development board I am using (EasyPic6) hardwires PortB RB0/RB1 to the LCD that the board uses, thus making a conflict with the RB0/RB1 pins that are used by my 18F4550 MCU for the I2C interface to the DS1337. That is why I am commenting out all of the LCD related code in this test version, which unfortunately makes it difficult to troubleshoot the DS1337 clock operations without being able to see the outpus on the LCD. I am therefore using my oscilloscope to check the DS1337 pins during ops as my only way to troubleshoot...awkward!
I have another LCD on order (two weeks delivery from Bulgaria) that will permit me to connect it as an external LCD to the EasyPic6 that will resolve this pin conflict, but in mean time I am still trying to troubleshoot code and get the clock working. Any suggestions how to troubleshoot without LCD??
One thing I am wondering....I have the DS1337 circuit with pullup resistors and capacitor installed on an Archer Universal Breadboard with wire connections to the EasyPic6 for the I2C interface and the ALarm1 input....would this be possible cause for the clock not working due to extra capacitance from wiring/breadboard hookup? I wanted to get code working before reducing everything to an integrated PCB.
I will try your contrl suggestion. Thanks for advice!
Would like to receive the photo
Quote:
Originally Posted by
BobK
Do you have a crystal with a capacitance load of 6pf? If not, the clock won't be very accurate.
I am ordering one with 6pf capacitance now...the one I have been using has 27pf capacitance and I still haven't been able to get the DS1337 to run no matter what CONTROL word I send it. Even wit %00000000, which is no alarms and 32.768kHa on the SQW output, I don't see anything on the SQW output pin or an indication that the clock is running. Frustrating! Hopefully with a LCD I will make some progress in the troubleshooting.
Quote:
Yea it is kind hard to see if the RTC is working without a display. I have a serial LCD that I plug into my clock boards. The clocks run without the LCD but I only plug it in when I'm checking the times and testing the clock. I built a test program into it that lets me change the alarm times to one and two minutes from the current times and at the completion of the test it restores the alarm times to their normal settings and reboots the system. I've had 80 of them in service for almost 3 years now.
I just tried to get a picture of the board to send to you but the limits were exceded. If you send me your email address I'll send you a picture.
I am ordering a serial serial LCD (delivery in 2 weeks) to resolve the Pin conflicts in my EasyPic6 with the I2C interface (RB0/RB1) from the 18F4550 MCU. Your test program sounds very interesting. How do you initiate the MCU to run just the test program instead of the application program?...is it when you plug something into that the MCU senses like an external PC to MCU serial cable or a USB cable? I would like to consider doing something similar in our application. Would definitely like to see the photo you offer...send to my email at [email protected].