I2CRead & I2CWrite not working as expected


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    I set up I2C capture and it looks suspicious.
    The 1st entry at "data" is actually and address of the chip
    and 3rd entry - the address I'm sending to it for reading
    but I'm getting no response?

    Name:  i2ce.jpg
Views: 14109
Size:  102.4 KB

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,650


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    yet still another pointless snippet , with nothing defined


    I2CREAD DPIN,CPIN,$A0,B0,X

    you persist in using incorrect syntax , it should be

    I2CREAD DPIN,CPIN,$A0,B0,[X ]



    proper code, not snippet with undefined rubbish, its not hard
    Code:
    #CONFIG             __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    ;pic16f1825
    
    DEFINE OSC 32
    OSCCON=$70
    ANSELA=0
    ANSELC=0
    trisa.0=0
    DEFINE I2C_SLOW 1 
    ANSELA = 0
    a Var Byte
    addr Var word
    ar Var Byte
    
    
    SCL var Porta.2                     
    SDA var Porta.1
    lata.0=1
    DEFINE DEBUG_REG PORTA
    DEFINE DEBUG_BIT 0      ;  if not used for pwr  
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0     
    pause 2000
    Debug 13,10,"Start",13 ,10
    
    
    a=20
    addr=$200
    I2cwrite Sda,SCL,$a0 ,addr,[a]
    pause 10
    
    
    addr=$200
    I2CREAD Sda,SCL,$a0 ,addr,[ar ]
    debug 13,10,sdec ar
    end
    what a write looks like

    Name:  write.jpg
Views: 14459
Size:  73.7 KB

    what a read looks like

    Name:  read.jpg
Views: 14704
Size:  90.7 KB
    Last edited by richard; - 9th October 2021 at 09:18.
    Warning I'm not a teacher

  3. #3
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    Well, if there's syntax error, compiler should warn about it, right?

  4. #4
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    I tried to add brackets and now it starts working, but in the weird way.

    I2CWRITE DPIN,CPIN,$A0,B0,[127]
    Writes 127 into eeprom
    but if I substitute variable there, no matter, byte or word
    after reading, I'm getting zeroes.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,650


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    Quote Originally Posted by CuriousOne View Post
    Well, if there's syntax error, compiler should warn about it, right?
    no the compiler produces code to I2CREAD DPIN,CPIN from device $A0 @eeprom address B0,X then read nothing as asked for
    there is no error

    I tried to add brackets and now it starts working, but in the weird way.


    I2CWRITE DPIN,CPIN,$A0,B0,[127]
    Writes 127 into eeprom
    but if I substitute variable there, no matter, byte or word
    after reading, I'm getting zeroes.
    produce a compliable example that demonstrates the problem
    Warning I'm not a teacher

  6. #6
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    Code:
    DPIN Var PORTA.2       ' I2C data pin
    CPIN Var PORTA.1       ' I2C clock pin
    B0   Var word
    B1   Var byte
    B2   Var byte
    X var byte
    x=0
    
    
       For B0 = 0 To 15    
       b1=b2
         I2CWRITE DPIN,CPIN,$A0,B0,[99]  
         Pause 10        '
    pause 100 
       Next B0
    
    
    mainloop:
    
    
       For B0 = 0 To 15   
         I2CREAD DPIN,CPIN,$A0,B0,[X]  
         lcdout $fe, $1, dec b0, " ", dec X 
         pause 1000
       Next B0
     
       Goto mainloop
     
       End

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,650


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    Code:
    DPIN Var PORTA.2       ' I2C data pin
    CPIN Var PORTA.1       ' I2C clock pinB0   Var wordB1   Var byteB2   Var byteX var bytex=0   For B0 = 0 To 15       b1=b2     I2CWRITE DPIN,CPIN,$A0,B0,[99]       Pause 10        'pause 100    Next B0mainloop:   For B0 = 0 To 15        I2CREAD DPIN,CPIN,$A0,B0,[X]       lcdout $fe, $1, dec b0, " ", dec X      pause 1000   Next B0    Goto mainloop  
    End
    so we guess whats wrong then

    DPIN,CPIN are analog
    the chip[undefined] has no porta
    the vcc is too low
    the clock is too fast
    the lcd is not setup properly
    the config settings are incorrect
    the interrupt in the unseen part of the code is ruining the timing
    what's the point
    Last edited by richard; - 10th October 2021 at 08:38.
    Warning I'm not a teacher

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,650


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    this

    Code:
    '*    pic16f1825      :  eprom addr =$a0   
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32
    OSCCON=$70
    ANSELA=0
    ANSELC=0
    trisa.0=0
    DEFINE I2C_SLOW 1 
    ANSELA = 0
    B0   Var word
    X var byte
    SCL var Porta.2                     
    SDA var Porta.1
    lata.0=1
    DEFINE DEBUG_REG PORTA
    DEFINE DEBUG_BIT 0      ;  if not used for pwr  
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0     
    pause 2000
    Debug 13,10,"Start",13 ,10
    clear
    For B0 = 0 To 15 
     I2CWRITE sda,scl,$A0,B0,[99]  
     Pause 10        '
    Next B0
    pause 100
    mainloop:
        For B0 = 0 To 15   
         I2CREAD sda,scl,$A0,B0,[X]  
         debug 13,10, dec b0, " ", dec X 
        Next B0 
        pause 1000
    Goto mainloop
    end
    produces as expected this
    Code:
    Start
    
    
    0 99
    1 99
    2 99
    3 99
    4 99
    5 99
    6 99
    7 99
    8 99
    9 99
    10 99
    11 99
    12 99
    13 99
    14 99
    15 99
    Warning I'm not a teacher

Similar Threads

  1. I2cwrite - I2cread
    By savnik in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th July 2006, 01:12
  2. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th June 2006, 20:03
  3. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th June 2006, 18:32
  4. PFC8583 Connection and I2Cwrite I2cread!
    By uludere72 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 27th February 2006, 13:32
  5. I2CWRITE and I2CREAD
    By Tomas in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd April 2004, 02:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts