Jump to content
43oh

i2c / Wire Library Causes Program to Halt


Recommended Posts

You may recall my last issue, dealing with an External EEPROM.  I picked up a simple external EEPROM IC just to see which way I liked better.  The i2c connection to the EEPROM seems convenient, but, I can't seem to get it to work.  Whenever I include the Wire.h library, the program seems to halt.  Test code as follows:

#include <Wire.h>

byte ADR_EEPROM = 0x50;
byte EEPROM_RSP = 0x00;
void setup() {
  // put your setup code here, to run once:
  pinMode(P1_0, OUTPUT);
  pinMode(P1_7, INPUT_PULLUP);
  pinMode(P1_6, INPUT_PULLUP);
  
  Serial.begin(9600);
  Wire.begin();
  delay(15);
  
  //eepromWrite(0,0,125);
  delay(5);
  
  EEPROM_RSP = eepromRead(0,0);
}

void loop() {
  // put your main code here, to run repeatedly: 
  digitalWrite(P1_0, HIGH);
  delay(1000);
  digitalWrite(P1_0, LOW);
  delay(1000);
}

void eepromWrite(byte highAddress, byte lowAddress, byte data)
{
  Wire.beginTransmission(ADR_EEPROM);
  Wire.write(highAddress);
  Wire.write(lowAddress);
  Wire.write(data);
  Wire.endTransmission();
}

byte eepromRead(byte highAddress, byte lowAddress)
{
  Wire.begin(ADR_EEPROM);
  Wire.write(highAddress);
  Wire.write(lowAddress);
  Wire.endTransmission();
  
  Wire.requestFrom(ADR_EEPROM, 1);
  
  while( ! Wire.available() )
  {
  }
  
  return Wire.read();
}

 

For me, commenting out anything dealing with the Wire library causes the LED to turn on and off, otherwise the LED remains off.

Link to post
Share on other sites

So, I took a bit of a break, but, I've been able to determine that it stalls on the first attempt to Wire.write().

 

I'm not entirely sure what that means...  Is the address wrong?  Is it simply unable to send data over the i2c pins?

Link to post
Share on other sites

Removing pinMode(P1_7, INPUT_PULLUP); and pinMode(P1_6, INPUT_PULLUP); is the right thing to do. Both SDA and SCL need a pull-up of around 10k. 

What's the EEPROM that you are using?

I did try using external pullup resistors, but only 4.7k at most.  Specifically, I'm using the 24AA128-I/P from Microchip.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...