I2C RTC Problem with Pic18f46k22


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2012
    Posts
    64

    Default I2C RTC Problem with Pic18f46k22

    I have been using DS1307 Real Time Clocks for some time now without problems. I am attempting to port a program I wrote a while back from a 18f4620 to a 18f46k22 and I can't seem to get the I2C RTC to communicate. The only thing I can see different should be the speed of the micro running at 16MHz instead of 8MHz.
    I did try adding "DEFINE I2C_SLOW 1" without any luck. Any suggestions?

    Thanks,

    Jim Black

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    I have played with the ds1307 clock modules a few times.
    Are you using one of the modules you can get from ebay or one of the hobby houses that include the battery on the pcb??

    I found that it did not seem to start up reliably every time. Have you tried to remove the battery and reset it??

    I am now using the DS2417 one wire RTC with pretty good success.

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    I am using just the DS1307 (No ready-made module). I am using the surface mount SOIC package. I have used these plenty of times in the past. I don't recall if I ever used them on a pic running faster that 8MHz before though. Since I am using a PCB that I laid out I don't have much choice of selecting another RTC, but I can try changing the Micro to a 18f4620 (Same pinout as the 18f46k22). I just don't have any to try right now.

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    Did you define OSC 16 in your code?

    Al.
    All progress began with an idea

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    I would start by checking the comfigurations of the pins being used to connect the one wire devices. There are quite a few new configuration registers compared to the 4620. I have converted a lot of code from the 4620 to 46K22. Look at the data sheet. Your code should be compatable 100%. Just look at the config's.
    Dave Purola,
    N8NTA
    EN82fn

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    I too use the Ds1307 in a few of my projects, most of which are based on an 18F4580. These are running at 40Mhz (10 Mhz xtal with OSC set to 40 and HS_PLL in the config), and on occasion these would either display 10:10 for time and date regardless of being either breadboarded or on a plug in module for the Easypic development board. I often found that changing the 37 khz crystal resolved the issue, or connecting a LED and suitable resistor between the SQW pin and GND so it pulsed at 1 sec intervals would somehow cause the chip to communicate to the PIC

  7. #7
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    Al,

    I did:
    DIFINE OSC 16
    OSCCON = %11111111


    I also tried:
    DEFINE OSC 8
    OSCCON = %11101111



    Quote Originally Posted by aratti View Post
    Did you define OSC 16 in your code?

    Al.

  8. #8
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    I haven't tried changing the crystal. I will give that a try tomorrow.

    Quote Originally Posted by Scampy View Post
    I too use the Ds1307 in a few of my projects, most of which are based on an 18F4580. These are running at 40Mhz (10 Mhz xtal with OSC set to 40 and HS_PLL in the config), and on occasion these would either display 10:10 for time and date regardless of being either breadboarded or on a plug in module for the Easypic development board. I often found that changing the 37 khz crystal resolved the issue, or connecting a LED and suitable resistor between the SQW pin and GND so it pulsed at 1 sec intervals would somehow cause the chip to communicate to the PIC

  9. #9
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    I believe I got all the registers I needed to set. I have the RTC on pins D6 and D7 (Both set to output):
    SDA VAR Portd.6 ' RTC I2C serial clock line
    SCL VAR Portd.7 ' RTC I2C serial data line
    TRISD=%00000010

    'MPASM CONFIG
    @ __config _CONFIG1H, _FOSC_INTIO67_1H & _FCMEN_OFF_1H & _PRICLKEN_ON_1H & _IESO_OFF_1H
    @ __config _CONFIG2L, _PWRTEN_OFF_2L & _BOREN_OFF_2L & _BORV_285_2L
    @ __config _CONFIG2H, _WDTEN_OFF_2H & _WDTPS_32768_2H
    @ __config _CONFIG3H, _CCP2MX_PORTB3_3H & _PBADEN_OFF_3H & _MCLRE_INTMCLR_3H
    @ __config _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    @ __config _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
    @ __config _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __config _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
    @ __config _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    @ __config _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
    @ __config _CONFIG7H, _EBTRB_OFF_7H

    All interrupts and ADC's are disabled also.


    Quote Originally Posted by Dave View Post
    I would start by checking the comfigurations of the pins being used to connect the one wire devices. There are quite a few new configuration registers compared to the 4620. I have converted a lot of code from the 4620 to 46K22. Look at the data sheet. Your code should be compatable 100%. Just look at the config's.

  10. #10
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    Dave,

    You were correct, and it was a register I shouldn't have missed... ANSELx registers. I guess the 4620 default was digital I/O since it ran fine in the past on that micro. I would have guessed the 46k22 would have defaulted to digital as well since everything else that required digital I/O worked. I had one other small issue where the speed difference in processors was going too fast for voltage to drain on a pin that I am using for both input and output, but a very small delay was all that was needed there. Everything is working now.

    Thanks to all who offered suggestions! I tried them all.

    Jim

    Quote Originally Posted by Dave View Post
    I would start by checking the comfigurations of the pins being used to connect the one wire devices. There are quite a few new configuration registers compared to the 4620. I have converted a lot of code from the 4620 to 46K22. Look at the data sheet. Your code should be compatable 100%. Just look at the config's.

  11. #11
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: I2C RTC Problem with Pic18f46k22

    Yes, I have found there are quite a few new functions added to the "K22" series of processors. You have to keep in mind the programmable alternate pins as well as the power control modules. Disabling unused functions saves a lot of power.
    Dave Purola,
    N8NTA
    EN82fn

Similar Threads

  1. PIC18F46K22 config issue
    By LGabrielson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2012, 04:20
  2. I2C RTC Help
    By isaac in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th February 2012, 12:32
  3. RTC Problem using DS1302
    By gavo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2010, 19:48
  4. I2C with 8564 RTC
    By suded in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st July 2008, 04:20
  5. RTC Problem
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th March 2006, 06:13

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts