A help with Write/Read a I2C memory


Closed Thread
Results 1 to 26 of 26
  1. #1
    Join Date
    Nov 2007
    Posts
    60

    Default A help with Write/Read a I2C memory

    Hello !

    My name is Eugen , from Romania - Bucharest . I am a new in use PBP . Please help me to know where I wrong . I have a Pic16F877 , and I wish to write a one or two texts as connstant , and variables as hours , minutes , seconds (these are not writes in my example), on a I2C memory type 24FC512 ,Read memory and display on a LCD with 2X16 lines:
    *****************************
    define LOADER_USED 1
    define OSC 4
    INCLUDE "Modedefs.bas"

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2

    SDA VAR PORTC.4
    SCL VAR PORTC.3

    J var word
    i var word

    c var byte

    I=0
    J=0

    ADCON1 = 7
    TRISB = 0

    start:


    DISABLE INTERRUPT

    FOR i = 0 TO 20
    I2cwrite SDA, SCL,$A0,I,["TEXT1",VARIABILA1,"TEXT2",VARIABILA2]
    pause 30
    NEXT i

    for J = 0 to 20
    i2cread SDA, SCL,$A0,J,[C]
    pause 30

    lcdout $FE,1
    LCDOUT $FE,$80,"INCERCARI"
    LCDOUT $FE,$C0+j ,c

    pause 400
    next J
    pause 400
    Enable
    goto start
    *****************************
    Thenk you very much !

  2. #2
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Instead of "TEXT1", use [#T,#E,#X,#T,#1...etc]

    Don't overwrite your buffer.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  3. #3
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JD123 View Post
    Instead of "TEXT1", use [#T,#E,#X,#T,#1...etc]

    Don't overwrite your buffer.
    Do not work .

    "I2cwrite SDA, SCL,$A0,I,[#T,#E,#X,#T,# ]" = "bad expression "

    Thanks !

  4. #4
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Oops, my bad... that's for serial stuff.

    Try:

    text var byte[5]
    test[4] = "T"
    test[3] = "E"
    test[2] = "X"
    test[1] = "T"
    test[0] = "1"

    I2cwrite SDA, SCL,$A0,I,[char test\5, {your other data to send} ]

    I don't know if the array is sent out lowest ([0]) or highest ([4]) first. Reverse array asignments if it comes out backwards.
    Last edited by JD123; - 27th March 2008 at 19:23.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I2cwrite SDA, SCL,$A0,I,[ "T" , "E" , "X" , "T" , "1" ].....
    should also work. (not 100% sure, haven't tried myself, but it should work)

    What you originally had was an embedded string, which PBP doesn't natively handle. ( "TEXT1" ). A byte array of characters as noted in the post preceeding can be used as a string, but is not really a 'string' as far as PBP is concerned.

  6. #6
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I2cwrite SDA, SCL,$A0,I,[ "T" , "E" , "X" , "T" , "1" ].....
    should also work. (not 100% sure, haven't tried myself, but it should work)

    What you originally had was an embedded string, which PBP doesn't natively handle. ( "TEXT1" ). A byte array of characters as noted in the post preceeding can be used as a string, but is not really a 'string' as far as PBP is concerned.
    I have tried again , and in other kinds , and do not work .

  7. #7
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=skimask;53213]I2cwrite SDA, SCL,$A0,I,[ "T" , "E" , "X" , "T" , "1" ].....
    should also work. (not 100% sure, haven't tried myself, but it should work)

    What you originally had was an embedded string, which PBP doesn't natively handle. ( "TEXT1" ). A byte array of characters as noted in the post preceeding can be used as a string, but is not really a 'string' as far as PBP is concerned.[/QUOTE

    I used this and not work .Read and display step by step only " T " ,first karakter .

    ........................................
    test var byte[5]
    test[4] = "T"
    test[3] = "E"
    test[2] = "X"
    test[1] = "T"
    test[0] = "1"

    ADCON1 = 7
    TRISB = 0
    TRISC = 0

    start:


    DISABLE INTERRUPT
    scriere:

    FOR i = 1 TO 20
    I2cwrite SDA, SCL,$A0,I,["T","E","S","T","1"]
    pause 30
    NEXT i
    ........................................
    Last edited by Eugeniu; - 27th March 2008 at 20:48.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eugeniu View Post
    I have tried again , and in other kinds , and do not work .
    Well, that code isn't going to work in a loop like that. Why would it?
    Get rid of the loop on the write.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi, something like the following will work.
    Code:
            EEP1    con %10100000 ' First EEPROM A<2:0>=Gnd
            
            Addr    var word
            ByteA   var byte
            ByteB   var byte
            
            PAUSE 50
         
                addr=0
                BYTEA="A"
                byteb="B"
                I2CWRITE SDA,SCL,EEP1,ADDR,[bYTEA," TEXT1",BYTEB," TEXT2"]
                PAUSE 10
                
           FOR ADDR=0 TO 13
                I2Cread SDA,SCL,EEP1,ADDR,[bYTEA]     
                hserout [BYTEA]
                next
        
            @ GOTO $
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    in your first example, try to change to..
    Code:
    <font color="#000000">        @ __CONFIG _XT_OSC &amp; _WDT_ON &amp; _PWRTE_ON &amp; _BODEN_ON &amp; _LVP_OFF                  
            <font color="#000080">DEFINE </font>OSC 4
            <font color="#000080">INCLUDE </font>&quot;Modedefs.bas&quot;
            
            <font color="#000080">DEFINE </font>LCD_DREG PORTB
            <font color="#000080">DEFINE </font>LCD_DBIT 4
            <font color="#000080">DEFINE </font>LCD_RSREG PORTB
            <font color="#000080">DEFINE </font>LCD_RSBIT 3
            <font color="#000080">DEFINE </font>LCD_EREG PORTB
            <font color="#000080">DEFINE </font>LCD_EBIT 2
            
            SDA <font color="#000080">VAR </font>PORTC.4
            SCL <font color="#000080">VAR </font>PORTC.3
            
            J <font color="#000080">VAR WORD
            </font>i <font color="#000080">VAR WORD
            
            </font>c <font color="#000080">VAR BYTE
            </font>variabila1 <font color="#000080">VAR BYTE
            </font>variabila2 <font color="#000080">VAR BYTE        
            </font>variabila1=&quot;A&quot;
            variabila2=&quot;B&quot;
            
            i=0
            J=0
            
            ADCON1 = 7
            TRISB = 0
    
    start:
    
            <font color="#000080">I2CWRITE </font>SDA, SCL,$A0,i,[&quot;TEXT1&quot;,variabila1,&quot; TEXT2&quot;,variabila2]
            <font color="#000080">LCDOUT </font>$FE,1
            <font color="#000080">LCDOUT </font>$FE,$80,&quot;INCERCARI&quot;
            <font color="#000080">LCDOUT </font>$FE,$C0
            
            <font color="#000080">FOR </font>J = 0 <font color="#000080">TO </font>12
                <font color="#000080">I2CREAD </font>SDA, SCL,$A0,J,[c]
                <font color="#000080">LCDOUT </font>c
                <font color="#000080">NEXT </font>J
    
            @   <font color="#000080">GOTO </font>$
    Last edited by mister_e; - 27th March 2008 at 21:23.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Well, that code isn't going to work in a loop like that. Why would it?
    Get rid of the loop on the write.
    Write code lines please , what have you in your mind .

    Corect my lines .

    Thank you !

  12. #12
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    in your first example, try to change to..
    Code:
        lcdout $FE,1
        LCDOUT $FE,$80,"INCERCARI"
        LCDOUT $FE,$C0
    
        for J = 0 to 20
            i2cread SDA, SCL,$A0,J,[C]
            LCDOUT c
            next
    In this situation the fist karakter is write in the same place , first possition .

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    no it works here, look at post #10
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Hi, something like the following will work.
    Code:
            EEP1    con %10100000 ' First EEPROM A<2:0>=Gnd
            ................................................................
        
            @ GOTO $
    I have write your code ..and display " ATEXT1 BTEXT2 " BUT NOT ALL TOGETHER -alternately . If will be remain all karakters on the display -ALL WILL BE OK !

    Addr var word
    ByteA var byte
    ByteB var byte

    PAUSE 50

    addr=0
    BYTEA="A"
    byteb="B"
    I2CWRITE SDA,SCL,$A0,ADDR,[bYTEA," TEXT1",BYTEB," TEXT2"]
    PAUSE 10
    reading:
    FOR ADDR=0 TO 13
    I2Cread SDA,SCL,$A0,ADDR,[bYTEA]



    lcdout $FE,1
    LCDOUT $FE,$80,"INCERCARI"
    LCDOUT $FE,$C0+addr ,ByteA ' HERE I WRITE " +ADDR " BECOSE HE WRITE IN THE SAME PLACE

    pause 300
    next
    pause 400
    Enable
    goto scriere
    Last edited by Eugeniu; - 27th March 2008 at 21:40.

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    POST #10, not #9

    anyways, look what your actual code do...
    Code:
    FOR ADDR=0 TO 13
    I2Cread SDA,SCL,$A0,ADDR,[bYTEA]
    
    lcdout $FE,1  ' it always clear your LCD and return to home
    LCDOUT $FE,$80,"INCERCARI" ' it always draw this line
    LCDOUT $FE,$C0+addr ,ByteA '  and finally here, it will only draw a single character, because you ALWAYS clear the WHOLE lcd with $FE,1
    
    pause 300
    next
    hence why i've move most LCDOUT BEFORE the FOR/NEXT loop.... twice.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    POST #10, not #9

    anyways, look what your actual code do...
    Code:
    FOR ADDR=0 TO 13
    I2Cread SDA,SCL,$A0,ADDR,[bYTEA]
    
          I understand that  : in this line " byTEA is a new variable where PBP put what read at "ADDR"  I have change with "C" and is the same .
    
    lcdout $FE,1  ' it always clear your LCD and return to home
    
          Aha , I will delete this line !! .....and WORK !! 
    
    LCDOUT $FE,$80,"INCERCARI" ' it always draw this line
    
          yes , I wish this .
    
    LCDOUT $FE,$C0+addr ,ByteA '  and finally here, it will only draw a single character, because you ALWAYS clear the WHOLE lcd with $FE,1
    
    pause 300
    next
    hence why i've move most LCDOUT BEFORE the FOR/NEXT loop.... twice.
    I understand , I have make changes in programs and now it work !

    Thank you very much for all help ! Have you only a happy days !

  17. #17
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Grreeeeeeeeeeeeeat! Enjoy!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  18. #18
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    "Have you only a happy days !"

    Quote of the day.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  19. #19
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    ah come on... read first post
    Quote Originally Posted by POST #1
    My name is Eugen , from Romania - Bucharest .
    Chances are that our friend is not English, and try to do it's best... as i do each days since i'm here.... and yes i do tons of mistakes here and there, in each and every of my over 4,800 posts.

    Time to raise Melanie's post once again
    http://www.picbasic.co.uk/forum/showthread.php?t=4583
    Last edited by mister_e; - 27th March 2008 at 22:10.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  20. #20
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    mister-e, tong-in-cheek, you know that. I would have stuck with helping him but my job called me away. Thanks for jumping in. It's best anyway, as I'm working on alot of I2C code right now and this kind of evolved into an LCD issue, which is not in the front of my mind.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  21. #21
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    You just provided one example for me and probably tons of other users + spelling mistake . Tongue-in-cheek... for me, French Quebecer, it doesn't mean anything... but thanks Wikipedia...
    Tongue-in-cheek is a term that refers to a style of humour in which things are said only half seriously, or in a subtly mocking way. It is related to satire and irony.
    I learn something new everyday Thanks!
    Last edited by mister_e; - 27th March 2008 at 22:41.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  22. #22
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    LOL!!! "tong", I just noticed that!
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  23. #23
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    sounded more chinese to me

    ni hao!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  24. #24
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Apologize for my english, please ! Do not be angry .

    Eugeniu

  25. #25
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Don't worry Eugeniu, there's a lot of people here, including me, who aren't english. We do our best and that's it. Your question was clear enough for me.

    Don't be afraid and don't give up!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  26. #26
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Don't worry Eugeniu, there's a lot of people here, including me, who aren't english. We do our best and that's it. Your question was clear enough for me.

    Don't be afraid and don't give up!

    Thank you , again ! My misyakes was very simple , for others , that "COLUMB EGG " but , I have lost a day , and my mind and eyes do not want to see they .

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  4. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55
  5. I need help with i2c memory
    By -c3- in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 23rd June 2005, 19:57

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