Welcome
Username or Email:

Password:


Missing Code




[ ]
[ ]
Online
  • Guests: 14
  • Members: 0
  • Newest Member: omjtest
  • Most ever online: 396
    Guests: 396, Members: 0 on 12 Jan : 12:51
Members Birthdays:
One birthday today, congrats!
Vaxian (17)


Next birthdays
05/21 Dalus (34)
05/21 Kizmo (37)
05/22 Skynet (32)
Contact
If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.


Special Thanks To:
  • Aaron Holmes
  • Aaron Wheeler
  • Adam Horden
  • Alan Scrimgeour
  • Andre
  • Andrew Haynes
  • Anonymous000
  • asabase
  • Austin Weil
  • barney
  • Barry
  • Bert Hickman
  • Bill Kukowski
  • Blitzorn
  • Brandon Paradelas
  • Bruce Bowling
  • BubeeMike
  • Byong Park
  • Cesiumsponge
  • Chris F.
  • Chris Hooper
  • Corey Worthington
  • Derek Woodroffe
  • Dalus
  • Dan Strother
  • Daniel Davis
  • Daniel Uhrenholt
  • datasheetarchive
  • Dave Billington
  • Dave Marshall
  • David F.
  • Dennis Rogers
  • drelectrix
  • Dr. John Gudenas
  • Dr. Spark
  • E.TexasTesla
  • eastvoltresearch
  • Eirik Taylor
  • Erik Dyakov
  • Erlend^SE
  • Finn Hammer
  • Firebug24k
  • GalliumMan
  • Gary Peterson
  • George Slade
  • GhostNull
  • Gordon Mcknight
  • Graham Armitage
  • Grant
  • GreySoul
  • Henry H
  • IamSmooth
  • In memory of Leo Powning
  • Jacob Cash
  • James Howells
  • James Pawson
  • Jeff Greenfield
  • Jeff Thomas
  • Jesse Frost
  • Jim Mitchell
  • jlr134
  • Joe Mastroianni
  • John Forcina
  • John Oberg
  • John Willcutt
  • Jon Newcomb
  • klugesmith
  • Leslie Wright
  • Lutz Hoffman
  • Mads Barnkob
  • Martin King
  • Mats Karlsson
  • Matt Gibson
  • Matthew Guidry
  • mbd
  • Michael D'Angelo
  • Mikkel
  • mileswaldron
  • mister_rf
  • Neil Foster
  • Nick de Smith
  • Nick Soroka
  • nicklenorp
  • Nik
  • Norman Stanley
  • Patrick Coleman
  • Paul Brodie
  • Paul Jordan
  • Paul Montgomery
  • Ped
  • Peter Krogen
  • Peter Terren
  • PhilGood
  • Richard Feldman
  • Robert Bush
  • Royce Bailey
  • Scott Fusare
  • Scott Newman
  • smiffy
  • Stella
  • Steven Busic
  • Steve Conner
  • Steve Jones
  • Steve Ward
  • Sulaiman
  • Thomas Coyle
  • Thomas A. Wallace
  • Thomas W
  • Timo
  • Torch
  • Ulf Jonsson
  • vasil
  • Vaxian
  • vladi mazzilli
  • wastehl
  • Weston
  • William Kim
  • William N.
  • William Stehl
  • Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Forums
4hv.org :: Forums :: Computer Science
« Previous topic | Next topic »   

I2C confusion

Move Thread LAN_403
...
Thu May 10 2007, 01:17AM Print
... Registered Member #56 Joined: Thu Feb 09 2006, 05:02AM
Location: Southern Califorina, USA
Posts: 2445
Ok, I am working on the rev3 version of my GPS tracker, and this time I have (among countless other goodies) a 24FC512 I2C eeprom wired into a pic18f1220. Yes I do have the pullups (2k) on the data/clock lines. I am using mplab and using the c18 compiler, and am using it soft I2C libs.

So, on an I2C bus, you start out by pulling the SDA line low ('start bit') and then you pull the clock line low, change the data line to high/low (depending on if you are sending a high/low bit) let the clock float back high, change data, etc then you have an ack or a stop depending on what you are doing.

EDIT: Turns out that wasn't the problem

After looking at the write bit function again, there was a ! before SCLK_PIN angry The exact code...
if ( !SCLK_PIN )              // test if clock is low
    {                             // if it is then ..
      if ( Clock_test( ) )        // wait on clock for a short time
      {
        return ( -1 );            // return with error condition      
      }
    }

    else

If SCLK_PIN is high, why is this returning a -1? I tried removing that exclamation mark, and I got some beautiful I2C data on the bus smile

Now normally this wouldn't be too big of a problem, just remove that exclamation mark, BUT this code is literally 'mission critical' so I would rather do this the right way... I also plan to publish it, so I am trying to avoid modifying the libs more than I have to... I can't imagine the headache that someone would have when they were trying to use the code and it it is doing the opposite of what it should...

edit2: the [code] tags don't seem to like this code either...
if ( !SCLK_PIN ) // test if clock is low
{ // if it is then ..
if ( Clock_test( ) ) // wait on clock for a short time
{
return ( -1 ); // return with error condition
}
}
Back to top
Conundrum
Mon May 14 2007, 04:00PM
Conundrum Registered Member #96 Joined: Thu Feb 09 2006, 05:37PM
Location: CI, Earth
Posts: 4059
Have you considered that the library might have an errata?
its not unheard of.

-A
Back to top
...
Mon May 14 2007, 10:31PM
... Registered Member #56 Joined: Thu Feb 09 2006, 05:02AM
Location: Southern Califorina, USA
Posts: 2445
turns out it was a mix of both problems with the library (one function and one function only was referencing to file that comes with the compiler while the rest were referencing to the header file that you use to configure the whole mess) and that I had the a/d configured incorrectly so the pin always showed as a 0 when poled angry

I ran into another problem, that the fastest eeprom I could find on an i2c buss has a write time of about 5ms, which caps write speed to about 200B/s, and I plan to save about a KiB/s. So, I am making a raid array of 8x 512kb chips... I call it the EEPROMRAIDARRAYFH (Electronically Erasable Programmable Read Only Memory Redundant Array of Inexpensive Disks From Hell) shades
Back to top
Conundrum
Sun May 20 2007, 11:24PM
Conundrum Registered Member #96 Joined: Thu Feb 09 2006, 05:37PM
Location: CI, Earth
Posts: 4059
bwahaha :) i was toying with the idea of building a parallel array of 24C256s for this purpose. In my case it was to parallel-store voice samples in realtime with direct D-A conversion.

-A

Beware:- Sellers on Ebay may be scammers in sheep's clothing...
Back to top
...
Tue Jul 24 2007, 10:34PM
... Registered Member #56 Joined: Thu Feb 09 2006, 05:02AM
Location: Southern Califorina, USA
Posts: 2445
Just in case anyone somehow stumbles across this thread when searching for I2C help...
When using the hardware I2C module in a PIC (instead of the software one I was using), you must follow each write/read/etc with a IdleI2C();, or the module will not respond to anything angry
don't ask...
Back to top
Carbon_Rod
Thu Jul 26 2007, 10:05PM
Carbon_Rod Registered Member #65 Joined: Thu Feb 09 2006, 06:43AM
Location:
Posts: 1155
Also note,

1.) Not all i2c chips are internally page mapped the same.

2.) Some can be over clocked to 400kbs (Microchip), to deal with issue 1 page boundaries simply avoid multi-byte block writes and stick to single byte writes.

3.) The exaggerated start/end bit do not have to be a standard period, i2c usually allows the same clock for the staggered signal as long as DATA shift is centered on the CLK period.

4.) Use your own macro defined ports and mask operations, the bit operator macros are often compiler specific inline functions and cause problems.

5.) If you use an IRQ enabled core -- keep in mind the stack may be handled differently on each mcu. Therefore, I often recommend if you are going to bit-bang a signal make sure its the only one on that port (see read-modify-write errata.)

6.) Declare your global constants and port buffer vars in main.c as:
volatile static
(This can help track down ISR problems...)

Cheers,
Back to top

Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Go to:

Powered by e107 Forum System
 
Legal Information
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.