Accessing I2C EEPROM on Basic I/O shield?

Post Reply
kestreltom
Posts: 2
Joined: Tue Sep 23, 2014 3:43 pm

Accessing I2C EEPROM on Basic I/O shield?

Post by kestreltom » Fri Sep 26, 2014 2:37 pm

I am using a Max32 board with the Basic I/O shield to prototype a pwm vacuum actuator controller. The compiler is MPIDE ver. 0316 - the Chipkit hardware is new.

I am trying to resolve an EEPROM issue in which the sketch compiles and downloads successfully to the Max32 and most of the sketch runs fine, but when I attempt to save data to the EEPROM on the Basic IO shield nothing happens...

To help with debugging, I decided to load the IOShield_EEPROM_Demo that comes with the MPIDE package and downgraded MPIDE ver 0821 to ver 0316 because of known wire library issues. The demo sketch loads a sample ASCII file into the I2C EEPROM and reads it back on the serial port.

Code: Select all

/* Note: For chipKit Max users you must manually 
** connect SDA and SCL pins(20 and 21) to pins A4 and A5 of 
** IO Shield 
**
** Note: For chipKit Uno Users you must have Jumpers JP6 and JP8 
** set in the RG3 and RG2 positions
*/

#include <IOShieldEEPROM.h>
#include <Wire.h>

void setup()
{
  char buf[26];
  char single;
  int i;
  Serial.begin(9600);
  
  //Write the alphabet to the EEPROM
  //The data length is assumed in this example because the data
  //is a string. If you write an array numbers to EEPROM then the
  //length of the array must be provided.
  IOShieldEEPROM.writeString(0,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  
  //Read alphabet back and print to monitor
  IOShieldEEPROM.readString(0, buf, 26);
  Serial.print(buf);

  
  Serial.println();
  
  //Write a single character
  IOShieldEEPROM.write(20,'#');
  
  //Read all characters back
  IOShieldEEPROM.readString(0, buf, 26);
  Serial.print(buf);
  
  Serial.println();
  
  //Read back last letter
  single = IOShieldEEPROM.read(25);
  Serial.print(single);
}

void loop()
{
}
The code compiles and downloads to the Max32 without errors, but when I open Serial monitor / Putty, I get nothing... it is just blank.

I installed jumpers between pin 20 & 21 (SDA/SCL) on the Max32 and the SDA/SCL pins on J11 of the Basic IO shield. I have tried using the JP2 pullup jumpers supplied on the Basic IO, and I have also tried using 2k7 pullups on pins 20/21 of the Max32 . I have also tried connecting the jumpers to A4 & A5 on the Basic IO instead of the J11 pins to no avail. I do not think there is a hardware problem, because I have scoped the I2C clock and data pins and can see 0-3.3v pulses so I know that the I2C bus is functioning at least some of the time.

I also tried the supplied IOShield_Temp_Demo and have a similar issue, only in this case the serial monitor reads out " 0.00 C, 32.00 F " no matter how warm the ambient temperature is.

To help with debugging, I tried the following I2C scanner sketch:

Code: Select all

/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
                void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,HEX);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 1;
byte end_address = 127;

// standard Arduino setup()
void setup()
{
    delay(2000);
    Wire.begin();
    Serial.begin(9600);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,HEX);
    Serial.print(" to ");
    Serial.print(end_address,HEX);
    Serial.println("...Hex");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop() 
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}
The above code compiles and runs fine, and the serial monitor shows the following:
I2CScanner ready!
starting scanning of I2C bus from 1 to 7F...Hex
addr: 1 found! addr: 2 found! addr: 3 found! addr: 4 found!
addr: 5 found! addr: 6 found! addr: 7 found! addr: 8
addr: 9 addr: A addr: B addr: C
addr: D addr: E addr: F addr: 10
addr: 11 addr: 12 addr: 13 addr: 14
addr: 15 addr: 16 addr: 17 addr: 18
addr: 19 addr: 1A addr: 1B addr: 1C
addr: 1D addr: 1E addr: 1F addr: 20
addr: 21 addr: 22 addr: 23 addr: 24
addr: 25 addr: 26 addr: 27 addr: 28
addr: 29 addr: 2A addr: 2B addr: 2C
addr: 2D addr: 2E addr: 2F addr: 30
addr: 31 addr: 32 addr: 33 addr: 34
addr: 35 addr: 36 addr: 37 addr: 38
addr: 39 addr: 3A addr: 3B addr: 3C
addr: 3D addr: 3E addr: 3F addr: 40
addr: 41 addr: 42 addr: 43 addr: 44
addr: 45 addr: 46 addr: 47 addr: 48
addr: 49 addr: 4A addr: 4B addr: 4C
addr: 4D addr: 4E addr: 4F addr: 50
addr: 51 addr: 52 addr: 53 addr: 54
addr: 55 addr: 56 addr: 57 addr: 58
addr: 59 addr: 5A addr: 5B addr: 5C
addr: 5D addr: 5E addr: 5F addr: 60
addr: 61 addr: 62 addr: 63 addr: 64
addr: 65 addr: 66 addr: 67 addr: 68
addr: 69 addr: 6A addr: 6B addr: 6C
addr: 6D addr: 6E addr: 6F addr: 70
addr: 71 addr: 72 addr: 73 addr: 74
addr: 75 addr: 76 addr: 77 addr: 78
addr: 79 addr: 7A addr: 7B addr: 7C found!
addr: 7D addr: 7E addr: 7F
done
Is this is an I2C / wire library problem? Any ideas how to fix it?

tom21091
Posts: 26
Joined: Fri Jun 06, 2014 12:12 am

Re: Accessing I2C EEPROM on Basic I/O shield?

Post by tom21091 » Tue Jan 19, 2016 7:31 pm

Hi kestreltom,

I found this post looking through old unanswered posts and figured I'd pick it up. Sorry you never got an answer. I understand that MPIDE was having problems with its Wire libraries back then. I figure a more recent version of MPIDE should fix this problem. Have you been able to get this to work since then?

Tommy

kestreltom
Posts: 2
Joined: Tue Sep 23, 2014 3:43 pm

Re: Accessing I2C EEPROM on Basic I/O shield?

Post by kestreltom » Tue Jan 19, 2016 8:21 pm

Thanks Tommy,

No, I never got an answer to my problem. I eventually deduced that my Chipkit board was defective, returned it, and moved on with an Arduino Uno. After the Uno, I tried various Chinese copies including Mega 2560 clones and have even better luck with them.

tom21091
Posts: 26
Joined: Fri Jun 06, 2014 12:12 am

Re: Accessing I2C EEPROM on Basic I/O shield?

Post by tom21091 » Tue Jan 19, 2016 8:44 pm

Ah I'm sorry to hear that, but I understand. I think there were a lot of problems porting the Wire library over last year. I spent a lot of time battling with I2C on my chipKIT at the time. There's a much more robust TWI library (DTWI) that works now. I'm sorry you had so much trouble getting this to work. Since your departure, a lot of time has been put into fixing these libraries to make it as painless as possible.

Thanks for your response!

Tommy

Post Reply