Shop OBEX P1 Docs P2 Docs Learn Events
Help with reading i2c output — Parallax Forums

Help with reading i2c output

msiriwardenamsiriwardena Posts: 301
edited 2012-07-03 15:36 in Propeller 1
I am using a i2c pressure transducer to read pressures in cm.H20.The transducer I am using is MS4515DO - the Data sheet is attached.
I am using jm_i2c Object - the object and and my code is also attached.
I am able to display the text via PST as in the Demo - but I am unable to display the pressure reading.- the result displayed is "0".
I have tried using the 3 sets of i2c addresses as indicated in the Data sheet,but still unable to display the results.
I have also connected the capacitor accross the power and the pull-ups to the SCL and SDA(4.7k)

I have attached a scope to the SDA and SCL and both show activity ---> the transducer is functioning.

Please help me to solve this issue.This is my first attempt at using i2c bus.


Thank you.

Siri

Comments

  • msiriwardenamsiriwardena Posts: 301
    edited 2012-07-01 07:05
    I forgot to let you know that - I have connected the 2 pull up resistors (4.7K) to SCL and SDA and also the 100nF capacitor accros the power supply to the transducer.

    Thanks

    Siri
  • T ChapT Chap Posts: 4,223
    edited 2012-07-01 07:33
    It looks like you are trying to request data from the device by sending it a string:

    MS4515.putstr(EE, addr,@string3)

    where the string3 is

    string3 byte "Read_MR"

    You only should send a request by means of the address + 1 for a read, or + 0 for a write.

    So, instead of sending a string, just send the (address + 1) to read the device. Then read the data.


    For Data Fetch commands, the number of data bytes returned by the RBiciLite™ is determined by when the
    master sends the NACK and stop condition. For the Read_DF3 data fetch command (Data Fetch 3 Bytes; see
    example 3 in Figure 1.6), the sensor returns three bytes in response to the master sending the slave address
    and the READ bit (1): two bytes of bridge data with the two status bits as the MSBs and then 1 byte of
    temperature data (8-bit accuracy). After receiving the required number of data bytes, the master sends the
    NACK and stop condition to terminate the read operation. For the Read_DF4 command, the master delays
    sending the NACK and continues reading an additional final byte to acquire the full corrected 11-bit temperature
    measurement. In this case, the last 5 bits of the final byte of the packet are undetermined and should be
    masked off in the application. The Read_DF2 command is used if corrected temperature is not required. The
  • T ChapT Chap Posts: 4,223
    edited 2012-07-01 07:46
    I am not familiar with the I2C driver you are using. But here is an example using minimali2cdriver which is floating around here somewhere.

    Under CON an example of setting up the read or write value ( address + 0 or 1)
        TEMPICW              = %1001_110_0    'address + write 
        TEMPICR              = %1001_110_0 + 1   'address + read
    
    PUB ReadKP
         i2c2.i2cStart(i2cSCL2) 'start the transaction
         i2c2.i2cWrite(i2cSCL2, KPAaddrW)   ' sernd a write  (address + 0)
         i2c2.i2cWrite(i2cSCL2, 1)                '1 = 0-7 bits start read address
         i2c2.i2cstop(i2cSCL2)
         i2c2.i2cStart(i2cSCL2)
         i2c2.i2cWrite(i2cSCL2, KPAaddrR)              'start the read   
         readkeyvar := i2c2.i2cRead(i2cSCL2, 0)        'read first bit field 0 - 7
         readkeyvar |= i2c2.i2cRead(i2cSCL2, 0) << 8   'read second bit field 8 - 15
         readkeyvar[1] := i2c2.i2cRead(i2cSCL2, 1)        'read last 
         i2c2.i2cStop(i2cSCL2)
         'go(0,0)  'lcd use
         'ser.decf(3, readkeyvar, 2)
         if readkeyvar ==  $FFFF
         {use this to insure that if the KP fails or is unplugged
         that the programdoes notlock since I2C will be showing $FFFF}
           return  0
         return readkeyvar
    

    Just determine how much data you want to read in before stopping.

    Using the minimal i2c driver, you could just just readpage, set the read count to 4 bytes, and read in all the data the comes back, it will auto-ack and stop after the 5th byte. Then you can do what you want with the data that got stored in your array. I would suggest a byte for the incoming data under VAR like this:

    VAR Byte datain[3]

    You park the 4 data bytes here as the come in from Read Page, then parse as needed. I would start by first just trying to get the device to respond and display any raw data from the 4 bytes. After you are getting some data back, then start to work on parsing the 4 bytes into something usable. Don't try to parse first, just view any data.
  • msiriwardenamsiriwardena Posts: 301
    edited 2012-07-01 08:37
    T Chap,
    I have pull-ups on both SDA and SCL.The minimal i2c driveryou suggested assumes that the SDA and SCL are not pulled-up.
    Do I have to disconnect the the pull-ups.

    Thaks for the quick reply.

    Siri
  • T ChapT Chap Posts: 4,223
    edited 2012-07-01 08:43
    I use the minimali2cdriver with pullups 4.7k.
    PUB ReadTemp
         i2c1.i2cstart(i2cSCL1)                        'send new start condition for read
         I2C1.I2CWrite(i2cSCL1,TEMPICr)
         temp[0] := i2c1.i2cRead(i2cSCL1, 0)            'get byte 1
         temp[1] := i2c1.i2cRead(i2cSCL1, 0)             'get byte 2  
         temp[2] := i2c1.i2cRead(i2cSCL1, 0)             'get byte 3  
         temp[3] := i2c1.i2cRead(i2cSCL1, 1)             'get byte 4  
         i2c1.i2cstop(i2cSCL1)     ' stop
     
    

    Try something like the above.
  • msiriwardenamsiriwardena Posts: 301
    edited 2012-07-01 08:52
    T Chap,
    I will give it a try and let you know.

    Thanks,

    Siri
  • msiriwardenamsiriwardena Posts: 301
    edited 2012-07-01 10:06
    T Chap,

    When using "Minimali2cDrvers" Read Pub - PUB i2cRead(i2cSCL, ackbit) - what is the ackbit? because when I try to complie - error
    "Expected an expression" - highligting - "ackbit"
    When I replce the "ackbit" with "0" - it reads "255" but does not change with the pressure changes.

    Thanks for your help

    Siri
  • T ChapT Chap Posts: 4,223
    edited 2012-07-01 10:31
    Can you save and post the entire code you are testing again? You must have a 1 for ackbit on the last read. If only reading one byte, then the read would have a 1. The ackbit tells the driver when to respond with an ack meaning it does not intend to read anymore. Basically a 0 ackbit means 'lets keep reading'. A 1 means we are done.

    For a read, you must first start the driver as shown above with the correct SCL pin, after starting, for the read you send the SCL pin again, followed by the ACK bit. After the read of on or more bytes, you do the stop.
  • msiriwardenamsiriwardena Posts: 301
    edited 2012-07-02 07:42
    T Chap,
    I have attachesd the code I am using.
    If i use "1" or "0" for ack - result is "255" and no changes occur during pressure changes.

    Thanks for the help.

    Siri
  • T ChapT Chap Posts: 4,223
    edited 2012-07-02 08:25
    I did not study your device in great detail, there is some guesswork in my code. See if you can get this to provide a response:
      repeat
        term.str(string("In...... "))
    
        i2c.i2cstart(i2cSCL)                        'send new start condition for read
        I2C.I2CWrite(i2cSCL, (DeviceAddress + 1))    '<<<< change deviceAddress to your device actual address in CON
        buffer[0] := i2c.i2cRead(i2cSCL, 1)            'get byte 1   USE ACK = 1 ON THE LAST BYTE TO READ, 0 IF MORE
        'buffer[1] := i2c.i2cRead(i2cSCL, 0)             'get byte 2
        'buffer[2] := i2c.i2cRead(i2cSCL, 0)             'get byte 3
        'buffer[3] := i2c.i2cRead(i2cSCL, 1)             'get byte 4
        i2c.i2cstop(i2cSCL)     ' stop
        term.dec(buffer[0])
        term.tx(CLREOL)
        term.tx(CR)
    
    
        Waitcnt(80_000_000 + cnt)
    
  • msiriwardenamsiriwardena Posts: 301
    edited 2012-07-03 15:36
    T Chap

    Thanks for all your help.
    With the last peice of code igot the i2c to work.

    Thank you for the patience and great help.

    Siri.
Sign In or Register to comment.