Jump to content
Rei Vilo

[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

Share this post


Link to post
Share on other sites

Thanks for noticing me. That's really strange.

 

It seems the square is a problem for some browsers.

 

However, it comes from the standard Mac keyboard.  I'll use the standard 2 and not the square.

Share this post


Link to post
Share on other sites

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:

Share this post


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

Share this post


Link to post
Share on other sites

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.

I think I will make a thing to solve this problem :)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

After quite a bit of testing, I think that I have some improvements for the version of software i2c in this thread.

 

The changes that I made are:

Support for Wire.endTransmission(false);

 

Also I added support clock stretching during i2c reads.

 

 

SoftwareSerial.zip

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×