Jump to content
43oh

I2C - SRF10 and Stellaris/MSP430


Recommended Posts

I have had some problems in using srf10 and energia, because with msp430 and the stellaris, can only measure values ??below 110 cm, and values ??between 60 cm and 110 cm, are unstable.
here is my code for the stellaris. for msp430 is the same by removing only the functions setmodule of stellaris.

 

#include <Wire.h>
TwoWire Wire1;
void setup()
{
  Wire1.setModule(1);
  Wire1.begin();       
  Serial.begin(9600); 
}
byte highByte = 0x00;                             // Stores high byte from ranging
byte lowByte = 0x00;  
int reading = 0;
  int range = 0; 
void loop()
{
  
  Wire.beginTransmission(120);             // Start communticating with SRF08
  Wire.write(0x00);                             // Send Command Byte
  Wire.write(0x51);                                // Send 0x51 to start a ranging
  Wire.endTransmission();
  
  delay(100);                                     // Wait for ranging to be complete
  
  Wire.beginTransmission(120);             // start communicating with SRFmodule
  Wire.write(0x02);                           // Call the register for start of ranging data
  Wire.endTransmission();
  
  Wire.requestFrom(120, 2);                // Request 2 bytes from SRF module
  while(Wire.available() < 2);                    // Wait for data to arrive
  highByte = Wire.read();                      // Get high byte
  lowByte = Wire.read();                       // Get low byte

  range = (highByte << 8) + lowByte;              // Put them together
  
    Serial.print(range);
   Serial.println(); 

  delay(25);               
}

also made ??some changes in the wire library of stellaris, to this work. was only a change of frequency, they are this:
 

line 242

 

before:
wire.cpp

 ROM_I2CMasterInitExpClk(MASTER_BASE, ROM_SysCtlClockGet(), false);//max bus speed=400kHz for gyroscope

 

after:

wire.cpp

 ROM_I2CMasterInitExpClk(MASTER_BASE, ROM_SysCtlClockGet()/1.4, false);//max bus speed=400kHz for gyroscope

where is the error?

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