Jump to content
43oh

[Energia Library] Software I2C Master for MSP430G2553


Recommended Posts

Rei, your posts are great but of all the posters on this site, your titles give my android browser the most fits. You seem to use strange characters in your titles. When I click on your post links from the "New Content View" it sends my mobile browser and web server into a death spiral ending in me not being able to read the post because of excessive redirects.

 

Not sure if this is a redirect issue. Obviously it is problem for the mobile only as I can read this fine on chrome versions running on a mac/linux or windows.

 

This might have something to do with it, not sure  http://www.webmasterworld.com/apache/4331495.htm

 

So please keep up the posts but if you can, can you avoid funny characters in the title?

 

Thanks,

 

-rick

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

Thank you for reviewing my code and identifying the bugs.

 

I hope to release a new version with the fixes you kindly suggested.  :smile:

 

 

If you want to save ~6KB of memory, get rid of the float and replace

void loop() {
    delay(2000);
    float temp = tc75_read();         // Read temperature in 1/256 C degrees
    Serial.print("Temperature: ");
    Serial.print(temp/256,1);         // Print result with 1 decimal
    Serial.println(" C");       
}

by

void loop() {
    delay(2000);
    int32_t temp = tc75_read()*10/256;         // Read temperature in 10x C degrees
    Serial.print("Temperature: ");
    Serial.print(temp/10, DEC);         // Print integer part
    Serial.print(".");         // Print decimal separator
    Serial.print(temp%10, DEC);         // Print  decimal part, 1 decimal
}

 Now, one tricky question: how to handle sub-zero temperatures?   :huh:

Link to post
Share on other sites

If you want to save ~6KB of memory, get rid of the float and replace...

You are right, the floating point arithmetic is a waste of memory and CPU time. On the other hand it makes Energy sketches a little more readable.

 

 

 Now, one tricky question: how to handle sub-zero temperatures?   :huh:

Good question, but I don't expect sub-zero temperature in my room. :rolleyes:

But merely changing the return type of function tc75_read(void) from uint16_t to int16_t should do the trick.

 

Istvan

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

Rei,

 

Thanks for sharing the library, I do have one question.

 

I'm trying to use Soft I2C to read a Si7005 sensor because my normal USCI_B0 port is consumed by a RF boosterpack.

 

Here is a function that I use to read a register:

uint16_t i2cRead(unsigned char address,unsigned char reg){
  int data = 0;
  Wire.beginTransmission(address);
  Wire.write(reg);
  Wire.endTransmission();
  Wire.requestFrom(address, 1);
  while (Wire.available() < 1);
  data = Wire.read();
  return data;
}

When I invoke:

i2cRead(_address,0x00)

I get this:

 

SoftI2C%20example.png

 

I've found that this does not function properly when I compare to the communication on my Electric Imp that looks like this:

ElectricImpExample%202x.png

 

I think that the difference is the Stop bit between the write and subsequent read.

 

I did find this Arduino example:

https://github.com/jjalling/Arduino-Si7005/blob/master/Si7005.cpp

 

specifically they are using the following Wire command:

Wire.endTransmission( false ); // We don't want to release the bus - this is important!

This is not supported by your library so I tried to add it (and failed):

uint8_t SoftwareWire::endTransmission(uint8_t sendStop)
{
    uint8_t result = 0;
    startI2C(txAddress, I2C_WRITE);
    result += writeI2C(txBuffer, txBufferLength);
    //stopI2C();
    txBufferIndex = 0;
    txBufferLength = 0;
    transmitting = 0;
    return result;
}

All I did was overload endTransmission and commented out the stopI2C call.

 

After I run this, it gets really weird:

2014-08-18%20at%205.17%20PM%202x.png

 

So I'm just curious if you have any thoughts on the matter.  The github author did note that it was really important not to release the bus.

 

My next step will be to remove the RF booster pack and try with a standard Wire interface.

Link to post
Share on other sites
  • 1 month later...
  • 1 month later...

Hi,

 

thanks for this library.

 

I got one question regarding sending the address.

When I try sending address 0x80 I see 0x00 on the logic analyzer.

Sending 0x40 gives 0x80

Sending 0x20 gives 0x40 ...

 

Has any one observed this behavior?

What could be wrong?

 

I'm using an FR5969 Launchpad to interface an SHT21 temp sensor (standard address is 0x80).

 

Best regards,

ArcticSaturn

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