Jump to content
43oh

I2C scanner for 2553 & 5529


Recommended Posts

Still getting nowhere with the I2C scan address finder. So had a look at my working  I2C RTC (uses a PCF 8563) sketch.

After editing the 

    Wire.endTransmissio()

to

    i =   Wire.endTransmissio() 

found that it always returns a zero regardless of the I2C address in Wire.beginTransmission(I2C address).

 

After editing Wire.cpp in energia-0101E0012\hardware\Msp430\cores\Msp430 found it made no difference, in fact could renamed the file to WireXX.cpp and could still compile the sketch OK??. Also searched the hard drive for other Wire.cpp's and only found the arduino one in the arduino area.

 

Also found that when I try to add the Wire library by using the Energia drop down menu (sketch\Inport Library) I can select Wire but instead of  the #include <Wire.h> put in the sketch, I get a blank line inserted?

 

I no longer need the scan sketch to work as I have found all the address via datasheets, but would like to understand why the sketch works OK with an arduino lib but fails with a core energia lib

Grant

 

 

Link to post
Share on other sites

Fixed. For some reason Energia requires a Wire.write() before Wire.endTransmission() command. to get a valid returned value.

Have fun.

Grant

 

-----------------------------------------------------------------------

// I2C scanner for M430G2553
// Added  Wire.write(1);  for sketch to work.
// Grant Forest May 2014
#include <Wire.h>
uint8_t error, address;
void setup () {
    Serial.begin(9600);
    Serial.println("G'Day MyI2C_ScannerV1");
    Wire.begin();
}
void loop () {
  Serial.print(" Scanning...");
  for(address = 1; address < 127; address++ )
  {
    Wire.beginTransmission(address);
    Wire.write(1);  ///////////////////////////////////// sketch works ok when this line added
    error = Wire.endTransmission();
    if (error==0) {
      Serial.print("Found Address 0x");
      if (address<15) Serial.print('0');
      Serial.print(address,HEX);
      Serial.print(", ");
      }
  }   
   
  Serial.println();  
   
   delay(2000);
}

--------------------------------------------

Link to post
Share on other sites
  • 3 months later...

:biggrin:

Puh. That helped me out. Couldn't get my AM2315 temp/hum sensor to work with stellar pad and msp430g2553.

 

I just changed the Adafruit-Lib like this:

boolean Adafruit_AM2315::readData(void) {
  uint8_t reply[10];

  //Serial.println("Wake up the sensor");
  
  // Wake up the sensor
  Wire.beginTransmission(AM2315_I2CADDR);
  //  delay(3);
  Wire.write(1);
  Wire.endTransmission();
 
Thanks a lot !
Link to post
Share on other sites
  • 8 months later...

Hi, I experienced again the problem of getting forever 0 from wire.endtransmission on  msp430, I2C is not working and I discovered (filed as issue) wire directory on hardware msp430 wire was missing source and header files, please can someone point me where I can get the two files to cure trouble?

 Sign of missing source files and header is that when add library is invoked, IDE add an just an empty line.

 Edit May 14 2015: I copy'd files from cores as commented on github issue section, files are required at two location, how can build path be managed to include library files from multiple location?

Edited by RROMANO001
Link to post
Share on other sites

 Actual out of box experience:

     I am new to Energia so I am still in the learning curve knee but about wire these are some FAQ or FIXUP:

 

 First attempt was not working, using an LCD bought from ebay wiring was not same as library example so take care when you use these devices, I wrote a pin pulser to be able to identify how pin where connected using a multimeter or one LED with series resistor. (sketch attached as file on PCF 8574[A])

 

 Wire is present on folder CORE, is required on folder WIRE to be attached as library, I placed for now a symbolic_link to original files and it cure both compile and library add too. Some library probably where developed on winzz so it suffer capitalization too on Linux and I suppose also on OSX, again link solved this problem before ask to cure problem.

 

 during test for learning how library work I wrote a scanner very similar to one found on this thread to see what return as error, no timeout is on library, transaction get not locking but deadloking in case of unresponsive bus.

 When P1.6 is Low Wire Library forever return 0 as if transaction was ok if no write and lock if no ack come back from device. This require more debugging inspection than just reading code.

 Wire.endTransmission(stop) default to true as from source overloading, using () version forever generate <I2C stop>.

 

 On launchpad P1.6 is attached green LED, this disturb I2C transaction and system forever hang or return OK, Logic analyser was reading ok but I suppose internal threshold is more higher than 1.8 volt and 1.9 where not enough. Seen observing LED glow and also attaching scope to measure bus parameter.

Removing LED P1.6 Jumper scanner and other sketch I tested worked fine.

 

 LCD I bought on Ebay was not connected as from Library but I found was RS RW EN BL D4 D5 D6 D7, pulser can be useful to check how is connected, from china you get cheap items but at expense of our time.

 

More to come when I better know forum and Energia.

/*
  I2C Bit Pulse exerciser to identify pinout
 This sketch repeatedly pulse at 4 Second period every bit 5 time showing on serial console.

  example added 16 May 2015
 by Roberto Romano
 modified 
 by 
 
 This example code is in the public domain.

 */
 
#include <Wire.h>

#define I2CADDR 0x27

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);  // start serial for output
  Serial.println("I2C Pulser Begin");
  Wire.begin();        // join i2c bus (address optional for master)
}

int errnum;

void loop()
{
  // put your main code here, to run repeatedly:
  Serial.println();
  Wire.beginTransmission(I2CADDR);    // Set and test Slave device
  Wire.write(0);
  errnum=Wire.endTransmission();
  delay(5);
  Serial.print(" Errnum: ");
  Serial.print(errnum);
  if(errnum)
  else
  if(errnum)
    Serial.println(" -> I2C error!!!");
  else
  { // Wire OK
    Serial.println(" -> OK");
    for(int i=0;i<7;i++)
    { // bit scanner for loop
      Serial.print(" pulse on BIT: ");
      Serial.println(i);
      for(int j=0;j<5;j++)
      { // pulser loop
        Serial.print(" pulse High ");
        Serial.println(i);
        Wire.beginTransmission(I2CADDR);    // Set and test Slave device
        Wire.write(1<<i);
        errnum=Wire.endTransmission();
        delay(2000);
        Serial.print(" pulse Low ");
        Serial.println(i);
        Wire.beginTransmission(I2CADDR);    // Set and test Slave device
        Wire.write(0);
        errnum=Wire.endTransmission();
        delay(2000);
      } // pulser loop
    } // bit scanner for loop
  } // Wire OK
}
Link to post
Share on other sites
  • 11 months later...

Fixed. For some reason Energia requires a Wire.write() before Wire.endTransmission() command. to get a valid returned value.

Have fun.

Grant

 

-----------------------------------------------------------------------

// I2C scanner for M430G2553
// Added  Wire.write(1);  for sketch to work.
// Grant Forest May 2014
#include <Wire.h>
uint8_t error, address;
void setup () {
    Serial.begin(9600);
    Serial.println("G'Day MyI2C_ScannerV1");
    Wire.begin();
}
void loop () {
  Serial.print(" Scanning...");
  for(address = 1; address < 127; address++ )
  {
    Wire.beginTransmission(address);
    Wire.write(1);  ///////////////////////////////////// sketch works ok when this line added
    error = Wire.endTransmission();
    if (error==0) {
      Serial.print("Found Address 0x");
      if (address<15) Serial.print('0');
      Serial.print(address,HEX);
      Serial.print(", ");
      }
  }   
   
  Serial.println();  
   
   delay(2000);
}

--------------------------------------------

 

You are the true MVP, currently working on a project at uni and have been getting the same issue trying to scan for addresses.

 

Thanks for your great work!

Link to post
Share on other sites
  • 2 months later...

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...