Shop OBEX P1 Docs P2 Docs Learn Events
I2C Not Working — Parallax Forums

I2C Not Working

LowIQGeniusLowIQGenius Posts: 13
edited 2014-07-22 16:24 in Propeller 1
Hello all,

I'm trying to learn I2C communications on the propeller, but am having trouble getting it to work. I've loaded the EEPROM test code from the Learn folder (as described here: http://learn.parallax.com/propeller-c-simple-protocols/eeprom-test-code), but it reports "testStr = " without the "abcdef" part. I am using the Propeller Education Kit. Can anyone explain what may be going wrong? Thanks in advance!

Comments

  • RsadeikaRsadeika Posts: 3,837
    edited 2014-07-22 10:03
    Can anyone explain what may be going wrong?
    Yes, global warming. Seriously, you should start by posting the code that you are using, not a reference to some exiting code. Also, maybe a picture of how you have your PEK wired up, to start with...

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-07-22 10:12
    Does your Prop board have a 64KB EEPROM or just a 32KB EEPROM? If it's only 32KB that may be your problem.
  • LowIQGeniusLowIQGenius Posts: 13
    edited 2014-07-22 10:39
    Rsadeika wrote: »
    Yes, global warming. Seriously, you should start by posting the code that you are using, not a reference to some exiting code. Also, maybe a picture of how you have your PEK wired up, to start with...

    Ray

    Not sure what part I was unclear about... The code is found in the link, but here it is anyway:
    /*
      Test 24LC512 with I2C.c
      Test writes data to I2C EEPROM, then reads it back and displays it.   
    */
    
    #include "simpletools.h"                      // Include simpletools header
    
    i2c *eeBus;                                   // I2C bus ID
    
    int main()                                    // Main function
    {
      eeBus = i2c_newbus(28,  29,   0);           // Set up I2C bus, get bus ID
    
                                                  // Use eeBus to write to device
      i2c_out(eeBus, 0b1010000,                   // with I2C address 0b1010000,
              32768, 2, "abcdefg", 8);            // send 2 byte address of 32768
                                                  // and 8 byte data string.
    
      while(i2c_busy(eeBus, 0b1010000));          // Wait for EEPROM to finish
     
      char testStr[] = {0, 0, 0, 0, 0, 0, 0, 0};  // Set up test string
         
                                                  // Use eeBus to read from device
      i2c_in(eeBus, 0b1010000,                    // with I2C address 0b1010000,   
             32768, 2, testStr, 8);               // send 2 byte address of 32768
                                                  // & store data in 8 byte array.
    
      print("testStr = %s \n", testStr);          // Display result
    }
    

    And a perfect graphical representation of the wiring is given here:
    PEK Diagram.JPG
    632 x 330 - 99K
  • LowIQGeniusLowIQGenius Posts: 13
    edited 2014-07-22 10:47
    Dave Hein wrote: »
    Does your Prop board have a 64KB EEPROM or just a 32KB EEPROM? If it's only 32KB that may be your problem.

    I do only have the 32kb ic, but changing the starting address to one within range of my smaller EEPROM didn't help. After looking more at the tutorial, I'm thinking the problem may be that the code provided requires pullup resistors on the i2c lines... Do you happen to know if the primary (program memory) EEPROM uses the propeller's internal pullups by default?
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-07-22 10:52
    If you are using a 24LC256 it only has 32KB of memory. The test assumes a 24LC512 device, and it writes to memory location $8000. I believe this address will de-select the 24LC256 the way you have it wired. Try changing the 2 occurrences of 32768 to 32760, and see if that works.
  • LowIQGeniusLowIQGenius Posts: 13
    edited 2014-07-22 11:01
    I tried it with memory location 32512 (0x7f00) with no luck
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-07-22 11:10
    The program works OK on my QuickStart card. Does the EEPROM work OK if you load a program into it, such as a repeating "Hello World" program?
  • LowIQGeniusLowIQGenius Posts: 13
    edited 2014-07-22 11:15
    Yes, it works perfectly with non-i2c programs. Blinking lights, terminal output, etc. all work like a charm. I'm not too savvy regarding EEPROM, but is it possible that the entire 32kB has been reserved for program use, therefore blocking my ability to write to it?
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-07-22 11:26
    No, the EEPROM is not reserved only for program use. You can write freely write anywhere in the EEPROM.
  • Hal AlbachHal Albach Posts: 747
    edited 2014-07-22 11:27
    " I'm thinking the problem may be that the code provided requires pullup resistors on the i2c lines"

    Per the schematic on page 27 of the PEK manual, you should have a 10K resistor from SDA to 3.3V bus. Without this pullup, I2C more often than not, will not work. I would also suggest putting a 10K pullup on the SCL line.
  • mindrobotsmindrobots Posts: 6,506
    edited 2014-07-22 11:33
    I do only have the 32kb ic, but changing the starting address to one within range of my smaller EEPROM didn't help. After looking more at the tutorial, I'm thinking the problem may be that the code provided requires pullup resistors on the i2c lines... Do you happen to know if the primary (program memory) EEPROM uses the propeller's internal pullups by default?

    You should put pullups on the I2C lines. The Propeller has no internal pullups. All of the current boards (including Dave's QuickStart) have pullups. There were some early boards that I believe did not have pullups and also, the PEK doesn't specify pullups. I recall reading somewhere that the Propeller itself has no issue using the EEPROM for loading/booting without pullups but beyond those uses, it should have pullups. Worth a try - surely won't hurt anything.

    There is no way for it to "protect" the lower 32K from your program, so you can easily blow your toes off if you decide to write to the lower 32k and not knowing exactly what you are writing to. (Don't worry too much, F11 will give you your toes back!)
  • LowIQGeniusLowIQGenius Posts: 13
    edited 2014-07-22 14:30
    So, it looks like the missing pullup resistor on the CLK line is exactly what was causing the problem. It's strange that the recommended schematic for an education platform would omit such a necessary and easily overlooked component. Thanks for all the help!
  • Hal AlbachHal Albach Posts: 747
    edited 2014-07-22 14:59
    Glad to hear you got it working. Whenever I implement an I2C bus I always provide pullups on SDA AND SCL. I think you will find the original program's EEPROM address of 32768 (0x8000) will work but will actually use location 0x0000 because of address rollover. The 32KB EEPROM does not have the bit 15 address line (which provides for addresses beyond 32KB) and so all it sees are all zeroes for the address.
  • jazzedjazzed Posts: 11,803
    edited 2014-07-22 16:24
    So, it looks like the missing pullup resistor on the CLK line is exactly what was causing the problem. It's strange that the recommended schematic for an education platform would omit such a necessary and easily overlooked component. Thanks for all the help!


    The library allows for either driving the clock or pulling it down (pull up on SCL).
Sign In or Register to comment.