Can i I2CWRITE array in parts?


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1

    Post Can i I2CWRITE array in parts?

    Hi, here is what i want, i have an array of 64 bytes long, and i want to write it to a memory using page mode (24lc256) because is faster, but the fact is that i want to write first 32 bytes to memory1 and secon 32 bytes to memory2.

    I can write the whole array, in the next example (manual stuff)

    '***********************************************
    '************************CODE EXAMPLE************
    '***********************************************
    a VAR BYTE [64]
    address VARD WORD
    SDA VAR PORTA.0
    SCL VAR PORTA.1

    loop:
    I2CWRITE SDA,SCL, $A0, address, [STR a/64]
    goto loop

    '***********************************************
    '***********************************************

    But i Would like something like

    '***********************************************
    '************SEUDOCODE
    '***********************************************
    a VAR BYTE [8]
    address VARD WORD
    SDA VAR PORTA.0
    SCL VAR PORTA.1

    loop:
    Write first 32 bytes to memory 1
    Write next 32 bytes to memory 2
    goto loop
    '***********************************************
    '***********************************************

    Both memories work fine already.

    thanks for any help

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Sure,

    [STR a\32] ' first 32
    [STR a(32)\32] ' last 32
    <br>
    DT

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel. If I may ask, where did you find this tip? I am curious because recently I had the same problem, and from Melabs, I was informed about this undocumented tip!

    It is very clever way to fill an array. Iliked it a lot!

    Ioannis

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hmm, Taxing my memory, ouch!

    Like most of what I know, it comes from trying to solve other peoples problems.

    As I recall, someone was trying to do the same thing by using a variable inside the parenthesis.

    Something like this...
    Code:
    A VAR BYTE[64]
    B var Byte
    
    B = 32
    
    HSEROUT [STR A(B)\32]
    It compiles just fine, but sure doesn't give the expected results.

    After searching through the macro files, It soon became apparent that array notation is handled differently, depending on whether a variable or a constant is used.

    If it's a variable, It takes the "Contents" of the array location and uses that as the address of the starting point of the data to send. (even if it's not an array)

    If it's a constant, It uses the constant as an offset into the array and uses that location as the starting point. (the expected result)

    This same behavior can be seen in other places too.

    Let's say you had stored a sequence of A/D ports in an array...
    Code:
    A VAR BYTE[7] ; [5,7,1,0,2,3,4]
    
    B = 3
    ADCIN  A(B), ADval  ; reads AN0
    ADCIN  A(3), ADval  ; attempts to read AN36 (depending on the location of var A)
                        ; obviously that won't work
    Calling meLabs, probably wouldn't have revealed that info.

    .
    DT

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    If it's a variable, It takes the "Contents" of the array location and uses that as the address of the starting point of the data to send. (even if it's not an array)

    If it's a constant, It uses the constant as an offset into the array and uses that location as the starting point. (the expected result)

    Calling meLabs, probably wouldn't have revealed that info.

    .
    Yes, although the use of array was a good tip, this thing about variables and constants was not cleared.

    Thanks Darrel.

    Ioannis

  6. #6


    Did you find this post helpful? Yes | No

    Lightbulb This kind of stuff is just great

    Thanks Darrel, Again, and Darrel Again and Darrel Again

    I´m becoming a big fan

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. PIC 18F4550 and MCP23017
    By DaveC3 in forum Code Examples
    Replies: 12
    Last Post: - 4th December 2010, 14:01
  3. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  4. WRITECODE stores wrong 14-bit word values in FlashMEM
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th June 2009, 04:35
  5. My I2CWRITE - timings and tricks
    By FinchPJ in forum Code Examples
    Replies: 5
    Last Post: - 3rd March 2008, 21:40

Members who have read this thread : 0

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