Indirect Adressing

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
User avatar
psf
Posts: 45
Joined: Mon Jun 25, 2007 9:44 pm
Location: Italia
Has thanked: 6 times
Been thanked: 2 times

Indirect Adressing

Post by psf »

I should ude this feature to read a large amount of data from external eeprom:
I want to read 50 position of memory so if I use the I2CreceiveBYTE macro and I save the returnvalue to variable POS0, i must repeat the same thing 50 times.
There is a specific way to create a loop and auto increment the returnValue varibale to POS1,POS2,POS3....POS49 .(external memory address increment is automatic)
In asm I could increment the FSR reg having the first memory address (POS0 ADDRESS). In flowcode I suppose the memory address of a variable may change if I add another var (looking into asm build file they are in a strange order NOT sequential and NOT alphabetical).
Thanks

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

When communication with an external EEPROM via I2C, you do not need to send the internal EEPROM address each time. But it would be useful to store the data in some kind of array. Here's an example that may help:

Code: Select all

Idx= 0
MI2C_Init()
MI2C_Start()
MI2C_Transmit_Byte(0x24)                    [address on I2C bus; R/W=0]
MI2C_Transmit_Byte(0x00)                    [start of internal EEPROM address]
MI2C_Restart()
MI2C_Transmit_Byte(0x25)                    [address on I2C bus; R/W=1]
Loop while Idx < 50
  If (Idx = 49)
    MyArray[Idx] = MI2C_Receive_Byte(1)     [1 = last byte]
  Else
    MyArray[Idx] = MI2C_Receive_Byte(0)     [0 = still receiving]
  End If
  Idx = Idx + 1
End Loop
MI2C_Stop()
This example uses a variable "Idx" which is used as an index to an array, and an array "MyArray[50]" to hold the data. Both variables are BYTEs, and the array is 50 bytes long.

At the end of this, your array should contain the values that were stored in the EEPROM between addresses 0 and 49.

User avatar
psf
Posts: 45
Joined: Mon Jun 25, 2007 9:44 pm
Location: Italia
Has thanked: 6 times
Been thanked: 2 times

Post by psf »

Thanks, now I learnt to use arrays!

Post Reply