ilpaso 0 Posted August 5, 2013 Share Posted August 5, 2013 Hi, I'm new with Energia but not with Arduino. I'm not able to communicate with HMC5883L throw I2C. The board is launchpad with msp430g2553 microcontroller. I read some threads about this issue but I didn't find a solution. #include <Wire.h>#define address 0x1E //0011110b, I2C 7bit address of HMC5883void setup(){ Serial.begin(9600); // start serial for output Wire.begin(); // join i2c bus (address optional for master) //Put the HMC5883 IC into the correct operating mode Wire.beginTransmission(address); //open communication with HMC5883 //Write CRA (00) Quote Link to post Share on other sites
Rei Vilo 695 Posted August 5, 2013 Share Posted August 5, 2013 Please find hint and answers that may help you at Need help using Energia's I2C library http://forum.43oh.com/topic/3941-need-help-using-energias-i2c-library/ I2C internal pull-up resistors http://forum.43oh.com/topic/3451-i2c-internal-pull-up-resistors/ I2C issues http://forum.43oh.com/topic/3154-i2c-issues/ Problem with I2C RTC DS1307 Module http://forum.43oh.com/topic/3872-problem-with-i2c-rtc-ds1307-module/ Quote Link to post Share on other sites
ilpaso 0 Posted August 5, 2013 Author Share Posted August 5, 2013 Hi Rei Vilo, thank you for your reply! I've already read these threads. These are my feedbacks. 1) With external pull-up (10K) resistors it doesn't work. 2) I changed the twi.c file and it doesn't work. It's strange because each of these threads has a different solution. Regards ilpaso Quote Link to post Share on other sites
Rei Vilo 695 Posted August 5, 2013 Share Posted August 5, 2013 Does it works with Arduino? Do you have a logic analyser to trace the signals? I've experienced issues with some I2C devices due to weak signal when using the 3.3V MSP430G2553. Using a lower than 10k? could improve signal. HMC5883L specification sheet mentions 2.2k? pull-up resistors. ilpaso 1 Quote Link to post Share on other sites
ilpaso 0 Posted August 6, 2013 Author Share Posted August 6, 2013 Hi Rei Vilo, Now it works with 4.7K pull-up risistors and the arduino sketch provided by Sparkfun (https://www.sparkfun.com/products/10530). It also works with your library "software I2C" in pins P2_3 and P2_4. I've only a problem: The magnetometer sends 6 bytes and this is the code: Wire.requestFrom(address, 6); if(6<=Wire.available()){ x = Wire.receive()<<8; //X msb x |= Wire.receive(); //X lsb z = Wire.receive()<<8; //Z msb z |= Wire.receive(); //Z lsb y = Wire.receive()<<8; //Y msb y |= Wire.receive(); //Y lsb } If I use the I2C software library it loses the last byte ("Y lsb"). If I change the first line of this code to "Wire.requestFrom(address, 7);" it works. Maybe is there a little bug in the library? Thank you ilpaso Quote Link to post Share on other sites
Rei Vilo 695 Posted August 7, 2013 Share Posted August 7, 2013 Thank you for pointing the bug. In the function uint8_t SoftwareWire::requestFrom(uint8_t address, uint8_t length) for (uint8_t i=0; i<length-1; i++) rxBuffer[i] = readI2C(false); should be for (uint8_t i=0; i<length; i++) rxBuffer[i] = readI2C(false); As an alternative, you can use size_t SoftwareWire::write(const uint8_t *data, size_t length) Quote Link to post Share on other sites
ilpaso 0 Posted August 7, 2013 Author Share Posted August 7, 2013 Thank you very much for your fantastic work! I would like to contribute more but I need more experience. :!!!: bye ilpaso Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.