I2C eeprom and DS1307 @40MHz problem


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    PBP uses macros to set the correct register bank when you use pinxx=0,
    pinxx=1, etc, so bank switching shouldn't be an issue, but read-modify-write
    can cause you a lot of headaches.

    If you have pinxx=0, pinxx=1, etc, in a row, then you'll have problems with
    read-modify-write. Especially running at higher oscillator speeds like 40MHz.

    If you change pin aliases from say pinCS var PORTC.4 to pinCS var LATC.4
    that will help eliminate r-m-w glitches for the 18F series.

    Example from your code;

    Pin aliases
    ctrlA VAR PORTC.0
    ctrlB VAR PORTC.1
    ctrlC VAR PORTC.2
    ctrlD VAR PORTC.3

    Then farther down you set/clear portc pins in succession;
    ctrlA = 1
    ctrlB = 0
    ctrlC = 1
    ctrlD = 0

    This uses bsf and bcf on port pins, and can definitely cause you grief with
    read-modify-write.

    If you change your pin aliases to point to LAT registers, you should never
    have problems with read-modify-write.

    ctrlA VAR LATC.0
    ctrlB VAR LATC.1
    ctrlC VAR LATC.2
    ctrlD VAR LATC.3

    Then it will set/clear portc LAT pins, and not read the port first, modify the
    value, and write it back. This writes to port latch registers VS directly to the
    port pins. Just be sure you setup TRIS registers first.

    So this is now OK to do without read-modify-write issues;
    ctrlA = 1
    ctrlB = 0
    ctrlC = 1
    ctrlD = 0

    If you use HIGH & LOW commands, PBP inserts a ton of extra code, so this
    can definitely save on code space. If you do use HIGH & LOW, then do NOT
    use HIGH or LOW commands with LAT registers.

    PBP uses an offset (from the port register physical address) to figure out
    where the TRIS register is, and it doesn't point to the TRIS reg if you use
    HIGH & LOW commands with LAT registers.

    So stuff like HIGH LATC.4 or HIGH pinCS (if it's aliased pinCS var LATC.4) is
    not a good idea. It's not going to automatically make the pin an output by
    clearing TRISC.4, and it's going to clear some other register bit at the wrong
    offset address.

    Places where you have stuff like this;
    PORTG.0 = 0
    PORTG.1 = 0
    PORTG.2 = 0, etc, I would also change to LATG.0=0, LATG.1=0, etc, but only
    if I couldn't just write directly to the whole port at once with PORTG = ?.

    On 14-bit core, if you need to write to port pins in succession, you're almost
    always better off using HIGH pin.x, LOW pin.x, etc, since you don't have LAT
    registers on these, and the additional code inserted helps eliminate r-m-w
    glitches.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,166


    Did you find this post helpful? Yes | No

    Default

    Sorry, I did not see that this was about 18F series.

    I just expressed my experience on 16F PIC's using directly pin control.

    Well descibed Bruce!

    Ioannis

Similar Threads

  1. ds1307 i2c
    By tamertokgoz in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th June 2008, 15:26
  2. i2c PBP questions
    By TimV in forum General
    Replies: 14
    Last Post: - 5th February 2007, 17:58
  3. ds1307 from f877 to f452 not work
    By microkam in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th July 2005, 00:02
  4. Reducing the number of writecycles on EEPROM
    By NavMicroSystems in forum General
    Replies: 4
    Last Post: - 3rd February 2005, 11:43

Members who have read this thread : 0

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

Posting Permissions

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