Hi All.
This one has been plaguing me for 2 evenings now.
I have a Pic18F2420, and a DS1377 RTC.
The DS1377 is running fine (its default is to have sqw output at the Crystal frequency (which is 32.768Khz. I confirmed that this output is spot on with a frequency counter.
I have connected it to my PIC micro, and can scope data on the I2C Clock and data lines, (Analogue scope, so just catch a blip of it, but I can see that it is a clocked signal).
But I cannot get the RTC to change its SQW output to be anything other than the default.
I have even tried to make the bar EOSC register high, to shutdown the oscillator, but nothing, nada.
I have even tried it on 2 different breadboards, as well as a prototyping board, with the same results. It is like the RTC chip is ignoring me.
Please can you check over my code, and see if anything obvious stands out. I have set the PIC18f2420 Oscconbits for the oscillator to run direct off the builtin 8mhz oscillator.
Thanking you all in advance ...
/*
* File: BigClock1.c
* Author: Peter
*
* Created on 15 March 2015, 18:29
*/
// PIC18F2420 Configuration Bit Settings
// 'C' source line config statements
#include <p18F2420.h>
// CONFIG1H
#pragma config OSC = INTIO67 // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
#pragma config BORV = 3 // Brown Out Reset Voltage bits (Minimum setting)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)
#include <stdio.h>
#include <stdlib.h>
#include <p18f2420.h>
#include <timers.h>
#include <delays.h>
#include <i2c.h>
#include "xlcd.h"
void DelayFor18TCY( void )
{
Nop();Nop();Nop();Nop();Nop();Nop();
Nop();Nop();Nop();Nop();Nop();Nop();
}
void DelayPORXLCD (void)
{
Delay1KTCYx(60); // Delay of 15ms
return;
}
void DelayXLCD (void)
{
Delay1KTCYx(20); // Delay of 5ms
return;
}
void ds1307_write(unsigned char reg, unsigned char data)
{
unsigned char stat;
IdleI2C(); /* wait for an idle bus */
StartI2C(); /* send START bit */
while (SSPCON2bits.SEN); /* wait till START is sent */
WriteI2C(0xd0); /* DS1377 WriteI2C address */
AckI2C(); /* Slave ACK */
WriteI2C(reg); /* Slave register address */
AckI2C();
WriteI2C(data); /* data */
AckI2C();
RestartI2C();
while (SSPCON2bits.PEN); /* wait till STOP is sent */
}
void ds1307_read(unsigned char reg, unsigned char *data)
{
unsigned char i;
IdleI2C();
StartI2C();
while (SSPCON2bits.SEN);
WriteI2C(0xd1);
AckI2C();
WriteI2C(0x00);
AckI2C();
StartI2C();
while (SSPCON2bits.SEN);
WriteI2C(0xd1);
AckI2C();
*data = ReadI2C();
StopI2C();
while (SSPCON2bits.PEN);
}
void ds1307_init(void)
{
ds1307_write(0xE0, 0xFF); //SETTING BIT 7 (BAR EOSC) SHOULD TURNOFF
}
void main(void) {
OSCCONbits.IRCF0=1; //8Mhz
OSCCONbits.IRCF1=1;
OSCCONbits.IRCF2=1;
ADCON1 = 0x0f;
LATA=0x00;
LATB=0x00;
LATC=0x00;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0xFF; //Port C is in
Delay10KTCYx(20);
while( BusyXLCD() );
OpenXLCD( FOUR_BIT & LINES_5X7);
WriteCmdXLCD( BLINK_OFF & CURSOR_OFF);
WriteCmdXLCD( SHIFT_DISP_LEFT );
putrsXLCD("DISPLAY IS ON");
OpenI2C(MASTER, SLEW_OFF); /* I2C Master */
SSPADD = 0x13; /* 100khz @ 8MHz */
ds1307_init();
while(1);
}