CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F46K22 and ds1307

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

18F46K22 and ds1307
PostPosted: Fri Mar 16, 2012 8:43 am     Reply with quote

Hi I have been trying to solve an issue regarding ds1307 but still no success,
here is the situation:

18F46K22, LCD and ds1307 , LCD is working fine I can write, no problem, I checked connections , power, 3v coin battery is connected to ds1307, crystal is 32768 hz , there are 4K7 resistors pulling up SDI/SDA and SCL/SCK ports.

when I run ds1307_init() system hangs.
I checked with oscilloscope and no signal goes out from PIN_C3 or PIN_C4 when power up , PIN_C3 is always up (5v) and PIN_C4 is always down (0v).

I use forum CCS driver for ds1307, when I remove ds137_init() it works,
CCS ver is 4.120

here is the code, thanks in advance.

Code:


#include <18F46K22.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(int=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=COM1)

/////////////////////////////////////////////////////////////////////////////


//#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,force_hw)
#use i2c(master,fast,sda=PIN_C4,scl=PIN_C3,restart_wdt,force_hw)

#ZERO_RAM


#include <flex_lcd.c>
#include <ds1307.c>

void main(){

   //setup_timer_4(T4_DISABLED,0,1);
   //setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

     
   ds1307_init();
   lcd_init();
   
   
   char k;
   lcd_putc("\fPrototipo...\n");

   
   
   while(TRUE){
   
 
      lcd_putc('*');     
     
      output_toggle (PIN_B5);
      delay_ms (500);
           
   }

}

Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 9:40 am     Reply with quote

First, look carefully at the top of the ds1307.c file. Note it sets up the I2C itself. You need to remove this, or your own setup. Two copies, 'asks for problems'.

Then look at what else is on the pins. Try disabling the ADC.

Then, _do not_ declare variables in the code after functions. This is _not_ legal in C. CCS 'accepts' it, and doesn't complain, but it results in memory areas getting corrupted. This is rapidly becoming something than needs to be in the FAQ. The legal syntax in C, is that variables _must_ be declared at the start of a function, or function block. Though you don't use 'k', put the declaration in the right place.

Just tweaked the code, with these changes, and it is putting data out on the I2C lines. Hangs after sending the address (since I don't have a DS1307 attached). Also changed the I2C setup to:

#USE I2C(MASTER,SLOW,I2C1,FORCE_HW)

Note the 'slow'. The DS1307, supports 100KHz _max_. This is the I2C slow speed, _not_ fast.

Best Wishes
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Mar 16, 2012 4:11 pm     Reply with quote

These are the top lines into my ds1307.c file
Code:

#define RTC_SDA  PIN_C4
#define RTC_SCL  PIN_C3
#use i2c(master,slow, i2c1, sda=RTC_SDA, scl=RTC_SCL)


Code:


#include <18F46K22.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(int=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=COM1)

///////////////////////////////////////////////

#include <time_reader.h>

#ZERO_RAM

#include <flex_lcd.c>
#include <ds1307.c>

void main(){

   //setup_timer_4(T4_DISABLED,0,1);
   //setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   SETUP_ADC(ADC_OFF);
   SETUP_ADC_PORTS(NO_ANALOGS);
     
   ds1307_init();
   lcd_init();
   
   lcd_putc("\fPrototipo...\n");
     
   while(TRUE){
           
      lcd_putc('*');     
     
      //output_toggle (PIN_B5);
      delay_ms (500);
   }
}


I tried all the variants, but no success. Thanks a lot.
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Solved
PostPosted: Sun Apr 01, 2012 1:28 pm     Reply with quote

Here is the trick I used to solve it.

I started trimming line by line in ds1307_init () function-.

to see which one make the uc stop. uncomment all, except the second line, write hex file. Uncomment second line, write hex, and VOILA!!! it works...
Don't know what could be affecting, but the trick worked...


Thanks a lot...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group