This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430-SMBUS: SMBus library compatabilty MLX90615

Part Number: MSP430-SMBUS
Other Parts Discussed in Thread: MSP430G2553, MSP430WARE

Hi,

I'm trying to write a program to read temperature values from a MLX90615 sensor. However, when trying to use TI's SMBus library I'm not getting expected results.

My question relates to the compatabilty of SMBus libray when using repeated start condition. 

MLX90615's datasheet states expected protocol: 

However, from TI's website:

As you can see the packet format is different, mainly missing stop bytes and ack bytes. Can anyone say if documentation on "int8_t SMBus_masterReadByteWord" is wrong? Or does this mean I need to write my own implementation? 

  • Hi Sam,

    What MSP430 device are you using?

    Thanks,

    Mitch
  • Hi,

    I'm using the MSP430g2553.
  • Hi Sam,

    Sorry for the delayed response. I believe this is a typo in our documentation. Our library is compliant with the SMBus spec. If you follow the protocol in the documentation (link attached) you should not have issues.

    smbus.org/.../smbus20.pdf

    Thanks,

    Mitch
  • Hi Mitch,

    Can you link me any posts on how to implement this library? I've found several design documents which offer no indication on how to use the library- they give high level overview. I've downloaded the other example files but they're not intutive and hard to follow.

    What I want to know is : What needs to be done for setup? What need to be done to read 2 bytes and PEC via SMBus?

    I've really tried to do this myself but I find the documentation somewhat useless.

    Regards, 

    Sam

  • Hi Sam,

    Sorry again for the late reply - I just returned from being out of town.

    Here is a link to SMBus software examples for the MSP430G2553 device. You should find 2 read examples (one for slave mode, one for master). It looks like PEC can also be enabled and disabled in the software.

    dev.ti.com/.../

    You can also navigate to the same examples within CCS by navigating to:

    View > Resource Explorer > Software > MSP430Ware > Libraries > SMBusLib > Example Projects > MSP430G2xx3
    You will be able to directly import any example into CCS from here.

    Please let me know if you have any more questions.

    -Mitch
  • Hey Mitch,

    Finally managed to get a basic implementation working! Really pleased, however I've ran into a small issue.

    I want to communicate via SMBus, using the read word command [ SMBus_masterReadByteWord() ]. I need this to include PEC within the packet. When analysing this via logic analyser everything gets ACK'd bar the PEC packet  - this means a failure.

    I've checked the packet though and the PEC seems valid [ Packet: /0xB6/0x27/0xB7/0x9D/0x3B/0x73  ]. By my calculations this PEC is correct and therefore should get ACK'd after the PEC before the packet stop bit.

    As this repeatedly fails and the packet clearly seems valid it makes me think i've not enabled PEC within the SMBus library. The questions i'd like help with are:

    1) Is PEC enabled with    "#define SMB_PEC_SUPPORTED 1" , "#define SMB_DEFAULT_PEC_ENABLED " or simply by calling "SMBus_enablePEC(SMBMaster)"

    2) I'm unsure on SMB_MAX_PAYLOAD_SIZE. I'm unsure if this is defined in bytes or bit. Also unsure if PEC will be included in the payload size. So currently unsure what this would be for reading 2 bytes followed by a PEC. If in bytes it could be 2 or 3 and bits would be 16 or 24. Maybe this is affecting the read method?

    Any help over this matter would be greatly appreciated. Really close to an implementation, just need to figure out how to properly set up the PEC.

    Regards,

    Sam

  • Hey Sam,

    Glad to hear you are making progress! In regards to your questions:

    1. PEC is enabled by "#define SMB_DEFAULT_PEC_ENABLED". When this is defined, "SMBus_enablePEC(SMBMaster)" is called. PEC should be enabled by default, and you should not have to make any changes to the software to enable PEC.

    2. SMB_MAX_PAYLOAD_SIZE is defined to be 32 bytes. PEC is not included in the payload size.


    It looks like you are doing everything correctly. I was hoping you could answer a couple of questions:

    1. Can you tell me the state of sSMBMaster and sSMBState after you run the SMBus_masterReadByteWord() function?
    2. Can you send me screenshots of the logic analyzer results?
    3. Do you get any errors from the library?

    Thanks,

    Mitch
  • Hey,

    So we have some slightly weird behaviour i'd like to mention before i answer the questions. First is that I get redefinition errors for the MCLK_MHZ value even though I can't find the decleration anywhere. I want to run on 1MHz but it's defaulting to 8MHz (not an issue for the example but still seems strange).

    This is what we're defining: 

    #define SLAVE ADDRESS
    #define SMB_DEFAULT_PEC_ENABLED
    static uint8_t Resp_Buff[SMB_MAX_PACKET_SIZE +4] 

    We have stepped through the program and the SMBus_enabledPEC(SMBus) is getting called. 

    So the state of the sSMBusMaster and sSMBState is SMB_RET_OK. This however fails on SMBus_getRxPayloadAvailable(&sSMBMaster) - the reply is then set to -1 and fails.

    We're not getting any errors from the library bar the weird define for MCLK_MHZ.

    I will attach picture of the logic trace - this makes me think there could be an issue with the clock speed as clearly the clock isn't particularity steady.

    I really don't understand what SMB_MAX_PAYLOAD_SIZE is, or why its defined to be 32. I've i'm sending a readByteWord command then surely the PAYLOAD must be 2 [as I'm looking for 2 bytes of data - LSB/MSB and PEC doesn't count]. I can't seem to redefine the SMB_MAX_PAYLOAD_SIZE either.

    I think this is either an issue with the clock or it's an issue due to entering wrong packet sizes and the library is waiting for data that's not coming/ not waiting long enough.

    Thanks for all the help so far, we're close but again any help would be great - appreciate it.

    Regards,

    Sam

  • Hey Sam,

    Thanks for the info.

    SMB_MAX_PAYLOAD_SIZE is defined to be 32 bytes because the SMBus specification states that the read byte count and the write byte count cannot exceed 32 bytes. Think of the SMB_MAX_PAYLOAD as a buffer. Your 2 byte PAYLOAD is acceptable because you are within the 32 byte limit. You can look at page 32 and 33 in the link below if you would like to read more info about it.

    smbus.org/.../smbus20.pdf


    I'm not sure which software example you are pulling from, but it looks like you will want to implement these changes for your use case:
    1. Make sure you set cmd = 0x27 (referring to line 84 in SMB_MASTER01_ReadByte_Echo project in main.c)
    2. Make sure SLAVE_ADDRESS is defined appropriately (referring to line 61 in SMB_MASTER01_ReadByte_Echo project in main.c)
    3. Make sure the SMBus_masterReadByteWord command expects 2 bytes (referring to line 110 in SMB_MASTER01_ReadByte_Echo project in main.c)
    4. Change the comparison from "!= 1" to "!=2" (referring to line 128 in SMB_MASTER01_ReadByte_Echo project in main.c) This could be the reason you are getting a failure here (the default SW checks for 1 byte, but you are sending 2 bytes)

    Also, the reason you are getting the redefinition error is because MCLK_MHZ is a predefined symbol. In order to change this, right click on the project and go to properties > Build > MSP430 Compiler > Predefined Symbols.

    Please let me know if any of the suggestions above help.

    Thanks,

    Mitch
  • Hi Mitch,

    Think I know the issue here. Looking at the document you linked to; page 30 right at the bottom. Also in "SMBus made simple" by TI page 3/4.

    I think we are actually expecting a NACK after the PEC. This however is not very clear. I'm getting conflicting information from different TI resources so not sure what to trust.

    Is there anyway you can confirm that this is actually expected behaviour?

    Regards,

    Sam

  • Hi Sam,

    Good catch! Yes, it looks like the NACK after the PEC is expected (as seen in the picture below from the SMBus Made Simple document)

    However, you will still need to fix the fail that occurs on SMBus_getRxPayloadAvailable(&sSMBMaster). The suggestions I made earlier regarding this should help.

    Thanks,

    Mitch

  • Hi Mitch,

    Honestly thank you so much for all the support. That's it working now.

    The issue was point 4 on your list, it should be waiting for 2 bytes

    So pleased it's all working now, thanks again all the best.

    Sam

**Attention** This is a public forum