PDA

View Full Version : Can i I2CWRITE array in parts?



Josuetas
- 25th January 2007, 18:47
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

Darrel Taylor
- 25th January 2007, 20:32
Sure,

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

Ioannis
- 25th January 2007, 20:59
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

Darrel Taylor
- 25th January 2007, 23:01
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...
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...

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.

.

Ioannis
- 26th January 2007, 08:02
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

Josuetas
- 26th January 2007, 19:44
Thanks Darrel, Again, and Darrel Again and Darrel Again :D:D

I´m becoming a big fan