Shop OBEX P1 Docs P2 Docs Learn Events
I2C and Breakout Board — Parallax Forums

I2C and Breakout Board

CenlasoftCenlasoft Posts: 265
edited 2009-10-24 00:38 in Propeller 1
Hello,
I am trying to learn I2C. I bought from sparkfun a DS1007 breakout board: http://www.sparkfun.com/commerce/product_info.php?products_id=9116

I read the datasheet and was confused. I want to use Spin to create a frequency generator (squarewave) to excite LC circuits. Is there a sample for me to start with? I know I can produce a squarewave from a prop pin, but I figure since I want to use my cool new breakout board, the prop would be perfect. Can someone tell me want part of the DS1007 datasheet data is needed for me to control and set the chip?
Thanks,
Curtis

Comments

  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2009-10-23 02:59
    @Curtis

    On the Sparkfun website there is a DS1007 code example in C that you can use as a template to translate to Spin
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-23 03:29
    Download the application note on the cog counters (AN001). It's on the Propeller Downloads webpage. There's also a frequency generator object in the Object Exchange. Another object is the "Basic I2C Driver" which has routines to handle I2C EEPROMs. There's also "i2cObjectV2" which has a wider variety of I2C device handlers.
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 16:22
    Hello,
    I tried the "i2cObjectV2" object and it worked for the eprom on my professional developers board. I put a similar eprom on the breadboard but it still used the on board eprom. Is there a way to use an extra eprom for data storage? Also I can only send my spin program to ram.
    Thanks,
    Curtis
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-23 16:38
    You can use any of the I2C drivers to access extra EEPROM. You'll need to post a detailed description of just how you're trying to connect your extra EEPROM.

    You should be able to send your Spin program to the on-board EEPROM. Exactly what's happening and what do you have connected on your PDB?
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 17:06
    Hello,

    I used the "i2cObjectV2" schematic for connecting the I2C devices. I connected pins 1-4 of the 32k eprom to ground and also pin 7. I connected pin 6 to pin 28 of the prop and pin 5 to pin 29 of the prop. I used two 4.7 k resistors to 3.3 v like in the "i2cObjectV2" schematic. I am trying to figure out how to use I2C and will be using it for stroage of data from the serial port. Just a test to see if it is useful and also to learn.

    Thanks,

    Curtis
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 17:07
    Hi,
    I forgot. Also pin 8 of the eprom to 3.3V.
    Thanks
    Curtis
  • JonnyMacJonnyMac Posts: 9,202
    edited 2009-10-23 18:28
    Once you have have the "Aha!" moment you're going to find that I2C is easier than you think it is now. That said, there is a point one can easily trip over -- page size within an EEPROM. This comes into play whenever were writing/reading more than one byte. If the multi-byte entity falls across a page boundary in an EEPROM you can have problems. Once you're aware of the boundary thing, it's easy to deal with. Page size depends on device, so you'll need to consult the docs for the EEPROM you're using.

    I've written my own I2C driver which, truthfully, is not dramatically different from others -- it just suits my particular style. Also, my code doesn't drive the clock line, so you must have a pull-up on the SCL pin (this is not built-in to all Propeller-based boards). You can find my I2C driver and demo here: http://obex.parallax.com/objects/528/

    Perhaps looking at another (even if only slightly-different) perspective will help you get to "Aha!" Also, most I2C product documentation is pretty good about explaining the protocol for the device.
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 18:52
    Hello,

    "Aha!" , I am beginning to see it. The schematic in the demo shows what I have on my Professional Development Board, my question is: is that the boot eeprom or the one I have on the board. Another question: it seems to work even though I have a 32k eeprom. Thanks, After I understand how to I2C to eeprom, I will try my hand at the DS1077 breakout board.

    Thanks again,

    Curtis
  • JonnyMacJonnyMac Posts: 9,202
    edited 2009-10-23 19:04
    I think the *stock* EEPROM on the PPDB is 32K; I swapped mine for a 64K. If you have a 32K the upper bit of the address is being ignored and the code is using address $0000 at the start, so...

    The program will work once after downloading to EEPROM. What happens is the program will be loaded into RAM and then run, corrupting the EEPROM. After it finishes if you press the reset button on the PPDB I'm sure you'll get bupkis. I guess this is another area to be careful of: if your EEPROM is smaller than the address range used in the code, you could truncate upper bits and overwrite something you don't want to.

    Since the program is very small you can change $8000 to $7000 and $8FFF to $7FFF -- this will work properly with the 32K EEPROM without corrupting the program space. I just gave that a try and it's fine (and is easily verified by looking at the memory use of the program [noparse][[/noparse]F8]).
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 19:20
    Hi,
    It seems to work with the corrections. I wanted to test if it was the 32k eeprom I put on the breadboard or the one on the PPB. I unhooked pin 28 and 29 from my eeprom on the breadboard and it still worked. How can I use an external eeprom to store data?
    Thanks,
    Curtis
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 19:23
    Corrections, I unhooked both pins 29 and 28 and it didn't work. I rehooked them and it worked. Curtis
  • JonnyMacJonnyMac Posts: 9,202
    edited 2009-10-23 19:34
    If you use the same general kind of EEPROM (24LC256, 24LC512) that's already on the PPDB you can set it's address to %001 (pins 0 - 2 are the address inputs) -- this will let you share the I2C lines of the boot EEPROM but give you external space; you can do this for up to seven "external" EEPROMs.

    I've attached a schematic of the Propeller Platform, a board a designed for my "Spin Zone" column in Nuts & Volts magazine. U2 is the boot EEPROM and is addressed at %000; U3 is a socket for an extra EEPROM and is addressed at %001. Keep in mind that you have to incorporate the device address into the Slave ID byte of the protocol.

    Post Edited (JonnyMac) : 10/23/2009 7:39:39 PM GMT
  • CenlasoftCenlasoft Posts: 265
    edited 2009-10-23 20:36
    Thanks Jon,
    I changed the "$A0" to "$A1". Is that what you mean? From your schematic, it looks like I am hooking it up that way by putting an eeprom on the PDB. The program gives me results on the terminal only when the external eeprom is connected to oins 28 and 29 of the PPB.
    Thanks,
    Curtis
  • photomankcphotomankc Posts: 943
    edited 2009-10-23 20:49
    No, $A0 AND $A1 both belong to the boot EEPROM. John's schematic will address the second EEPROM at $A2 and $A3. In I2C the read/write bit makes up the last bit of the address, so write is ($A2) and the read address is 1 greater ($A3). Most of the I2C drivers take care of this. You just have to set the base address correctly on the pins and provide the right base address to the functions.
  • JonnyMacJonnyMac Posts: 9,202
    edited 2009-10-24 00:38
    The correct way to get the EEPROM slave ID is:

    $A0 | (addr << 1)

    So, valid IDs would be $A0, $A2, $A4, $A6, $A8, $AA, $AC, $AE

    The LSB of the ID is used as the write (0) or read (1) bit.
Sign In or Register to comment.