element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum arduino  DUE and SRF10
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 417 subscribers
  • Views 1095 views
  • Users 0 members are here
  • arduino
Related

arduino  DUE and SRF10

e14 Contributor
e14 Contributor over 13 years ago

i am trying to configure ARDUINO DUE and SRF10 ultrasonic sensor. i have my code ready but while running the code i am getting the error below. 

assertion "(address & 0x80) == 0" failed: file "../source/twi.c", line 261, function: TWI_StartWrite

Exiting with status 1

 

 

 

 

 

 

 

 

 

 

#include <Wire.h>

 

 

 

 

void setup()

{

  Serial.begin(9600);

  Serial.println("SFR10 test application");

  Wire.begin();                // join i2c bus (address optional for master)

  Serial.println("i2c initialized");

 

 

}

 

 

#define SFR10_ADDRESS 0xE0

 

 

int getDistance(void) {

  // 1. start measurement

  // write to command register (0x00) of SRF10

  Wire.beginTransmission(SFR10_ADDRESS); // transmit to device #112 (0x70)

                               // the address specified in the datasheet is 224 (0xE0)

                               // but i2c adressing uses the high 7 bits so it's 112

  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00) 

  Wire.write(byte(0x51));      // command sensor to measure in "inches" (0x50)

                               // use 0x51 for centimeters

                               // use 0x52 for ping microseconds

  Wire.endTransmission();      // stop transmitting

 

 

 

 

  // 2. wait until measurement is finished

   delay(70);                   // datasheet suggests at least 65 milliseconds

 

 

 

  // 3. read the value

 

  Wire.beginTransmission(SFR10_ADDRESS); // transmit to device #112

  Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)

  Wire.endTransmission();      // stop transmitting

 

 

  Wire.requestFrom(SFR10_ADDRESS, 2);    // request 2 bytes from slave device #112

 

 

  

  // (4.) make a conversion cm

  // already done

 

 

  // 5. return the value in cm

  int reading;

 

  if(2 <= Wire.available())    // if two bytes were received

  {

    reading = Wire.read();  // receive high byte (overwrites previous reading)

    reading = reading << 8;    // shift high byte to be high 8 bits

    reading |= Wire.read(); // receive low byte as lower 8 bits

   

  }

 

 

  return reading;

 

 

}

 

 

void loop()

{

  int distance;

 

  distance=getDistance();

  Serial.println(distance);   // print the reading

 

  delay(200);

  

}

  • Sign in to reply
  • Cancel
Parents
  • e14 Contributor
    e14 Contributor over 13 years ago

    according to the datasheet the default address is 0xE0 but its 8 bit so any how its not possible to read the data with that. i dont know how to handel this problem now. working since last 1 week on it but no result till now..image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 13 years ago in reply to e14 Contributor

    It may be 8-bit, but you're using a two-wire interface which I'm guessing is implemented as I2C. I2C uses a 7-bit address which people pad out with an extra bit to signify read/write operations - check the I2C specification online, for an explanation that explains this in detail.

    This is why you need to translate to a 7-bit address.

    'working but no result' isn't helpful to an engineer - is that what you're studying (Engineering)? I'm surprised you worked on this for a week with that assertion being reported, since a quick google search pasting in that error line would have helped you in 60 seconds.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • shabaz
    shabaz over 13 years ago in reply to e14 Contributor

    It may be 8-bit, but you're using a two-wire interface which I'm guessing is implemented as I2C. I2C uses a 7-bit address which people pad out with an extra bit to signify read/write operations - check the I2C specification online, for an explanation that explains this in detail.

    This is why you need to translate to a 7-bit address.

    'working but no result' isn't helpful to an engineer - is that what you're studying (Engineering)? I'm surprised you worked on this for a week with that assertion being reported, since a quick google search pasting in that error line would have helped you in 60 seconds.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • shabaz
    shabaz over 13 years ago in reply to shabaz

    Hi Junaid,

     

    If you disconnect the SRF device, does the arduino generate an error? If so, then this means that the SRF is at least responsing when you connect it back. That will confirm your communication.

    After your lines

    if(2 <= Wire.available())    // if two bytes were received

      {

        reading = Wire.read();  // receive high byte (overwrites previous reading)

        reading = reading << 8;    // shift high byte to be high 8 bits

        reading |= Wire.read(); // receive low byte as lower 8 bits

     

      }

     

    add the following:

    else

    {

      reading=0xffff;

    }

     

    Then, see what occurs. If you now get a different response, then you know that the if() statement is not executing, beacause of some upstream error. That will help narrow it down.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 13 years ago in reply to shabaz

    Also, according to the documentation, the address can be changed. If this was not purchased new, someone may have modified the address. If that's the case, you'd need to test all 16 possible addresses.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 13 years ago in reply to shabaz

    The datasheet link shows that when powered up with nothing sent to it, it flashes the led based on the address.

     

    That might be a start.

     

    Also a small note .. that posting in two seperate threads and asking the same question, isn't a good idea.

    You've done the correct thing by starting a new thread here with an appropriate title...

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube