I2C V6
Moderator: Benj
-
- Posts: 243
- Joined: Tue Nov 27, 2012 12:53 pm
- Location: Cambridge, UK
- Has thanked: 140 times
- Been thanked: 118 times
- Contact:
Re: I2C V6
Hi Brian.
Have you tried your code with a 'real' I2C EEPROM?
The only reason I ask is that reliance is placed on the EEPROM to auto-increment addresses for successive bytes when storing data. I'm not entirely sure whether FlowCode could be expected to simulate this automation, and notable that my original program gives the same result when checked in the console.
If not already tried, I would certainly suggest enabling the Console view and clicking on the I2C tab when running your program - least of-all to confirm that your read and write headers are correct when compared against the I2C EEPROM datasheet and what you're expecting to send.
All the best,
Brendan
Have you tried your code with a 'real' I2C EEPROM?
The only reason I ask is that reliance is placed on the EEPROM to auto-increment addresses for successive bytes when storing data. I'm not entirely sure whether FlowCode could be expected to simulate this automation, and notable that my original program gives the same result when checked in the console.
If not already tried, I would certainly suggest enabling the Console view and clicking on the I2C tab when running your program - least of-all to confirm that your read and write headers are correct when compared against the I2C EEPROM datasheet and what you're expecting to send.
All the best,
Brendan
LinkedIn Profile...
http://www.linkedin.com/in/brendantownsend
http://www.linkedin.com/in/brendantownsend
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Hi Guys
I was wondering would it be easier to use a 1 or 2Mb flash card instead if the EEPROM as this has loads of space. If so is there examples on how to use the FAT1 component.
Brian
I was wondering would it be easier to use a 1 or 2Mb flash card instead if the EEPROM as this has loads of space. If so is there examples on how to use the FAT1 component.
Brian
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Hi Guys
I have the saving onto SD Card Working like a dream just a bit slow for my application so i now need to use an EEprom I need to save 1000 tags onto the 24LC04b which is a 4 kilobyte EEprom. Now if my thinking is correct if I want to store 0B0159BF I split it ( 0B-01-59-BF) into 4 bites (4096 / 4 = 1024) so in theory i could save 1024 tags on this eeprom.
Please could someone tell me if I'm on the right track
Also is this the correct way to split and reassemble
number_in = 0B0159BF
Split0 = number_in & 0xFF
Split1 = (number_in >> 8 ) & 0xFF
Split2 = (number_in >> 16) & 0xFF
Split3 = (number_in >> 24) & 0xFF
MemReturn = Split0 | (Split1 << 8 )
MemReturn = MemReturn | (Split2 << 16)
MemReturn = MemReturn | (Split3 << 24)
I'm trying to understand what this does (& 0xFF) does it multiply with 255 also I'm not sure about this Split0 | ( Split1 << 8 ) I'm sure the ( Split0 << 8 ) means move 8 places to the left but really not sure also what this character (|) means ?
I have the saving onto SD Card Working like a dream just a bit slow for my application so i now need to use an EEprom I need to save 1000 tags onto the 24LC04b which is a 4 kilobyte EEprom. Now if my thinking is correct if I want to store 0B0159BF I split it ( 0B-01-59-BF) into 4 bites (4096 / 4 = 1024) so in theory i could save 1024 tags on this eeprom.
Please could someone tell me if I'm on the right track
Also is this the correct way to split and reassemble
number_in = 0B0159BF
Split0 = number_in & 0xFF
Split1 = (number_in >> 8 ) & 0xFF
Split2 = (number_in >> 16) & 0xFF
Split3 = (number_in >> 24) & 0xFF
MemReturn = Split0 | (Split1 << 8 )
MemReturn = MemReturn | (Split2 << 16)
MemReturn = MemReturn | (Split3 << 24)
I'm trying to understand what this does (& 0xFF) does it multiply with 255 also I'm not sure about this Split0 | ( Split1 << 8 ) I'm sure the ( Split0 << 8 ) means move 8 places to the left but really not sure also what this character (|) means ?
Last edited by jollybv on Thu Apr 14, 2016 5:16 am, edited 1 time in total.
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: I2C V6
Check the calculations help page for the name of the operator, then use Wikipedia or this page to find what it does.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Hi Kersing
Thanks for this it was very useful it has put me on a better understanding of how things work
Thanks for this it was very useful it has put me on a better understanding of how things work
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Hi guys
This is driving me mad I've been trying the whole afternoon to convert a hex decimal string number to an int e.g string variable (HexVal = "0B0159BF") must be Int (Number_In = 0x0B0159BF) so i can split it up into 4 bites and send it to I2C eeprom
Bite0 = number_in & 0xFF
Bite1 = (number_in >> 8 ) & 0xFF
Bite2 = (number_in >> 16) & 0xFF
Bite3 = (number_in >> 24) & 0xF
Please can somone Help
This is driving me mad I've been trying the whole afternoon to convert a hex decimal string number to an int e.g string variable (HexVal = "0B0159BF") must be Int (Number_In = 0x0B0159BF) so i can split it up into 4 bites and send it to I2C eeprom
Bite0 = number_in & 0xFF
Bite1 = (number_in >> 8 ) & 0xFF
Bite2 = (number_in >> 16) & 0xFF
Bite3 = (number_in >> 24) & 0xF
Please can somone Help
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: I2C V6
Hello,
Something like this should hopefully work. I've done this kind of thing before
And here is a bit of an explanation to my numbers.
length - number of characters to convert
idx = 2 - Starting position in the string
longvar = longvar * 16 - multiply the previous characters by the base - hex is base 16 - << 4 instead of * 16 may be more efficient.
if (hexstr[idx] >= 'A') - Are we dealing with a number or letter for the current character
longvar = longvar + 10 + (hexstr[idx] - 'A') - Add 10 plus the 0-5 for 'A'-'F'
longvar = longvar + (hexstr[idx] - '0') - Add 0-9 for '0'-'9'
Something like this should hopefully work. I've done this kind of thing before
Code: Select all
hexstr = "0x0B0159BF"
length = 8
idx = 2
longvar = 0
while (length)
{
longvar = longvar * 16
if (hexstr[idx] >= 'A')
longvar = longvar + 10 + (hexstr[idx] - 'A')
else
longvar = longvar + (hexstr[idx] - '0')
idx = idx + 1
length = length - 1
}
length - number of characters to convert
idx = 2 - Starting position in the string
longvar = longvar * 16 - multiply the previous characters by the base - hex is base 16 - << 4 instead of * 16 may be more efficient.
if (hexstr[idx] >= 'A') - Are we dealing with a number or letter for the current character
longvar = longvar + 10 + (hexstr[idx] - 'A') - Add 10 plus the 0-5 for 'A'-'F'
longvar = longvar + (hexstr[idx] - '0') - Add 0-9 for '0'-'9'
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Hi Ben
I have modified the I2c_eeprom_programing_example so that it only stores 4 bites of data but i seem to have a problem recombining the data all it does is give me 1153. What i have done is when reading back from the eeprom i send each bite via RS232 to check if it is reading the correct data and everything is the same as what I have written to the mem im using this formula to recombine the data but dose not seem to work. I really do not know what i'm doing wrong
MemReturn = Debug_Verify_Data[0] | (Debug_Verify_Data[1] <<
MemReturn = MemReturn | (Debug_Verify_Data[2] << 16)
MemReturn = MemReturn | (Debug_Verify_Data[3] << 24)
I have modified the I2c_eeprom_programing_example so that it only stores 4 bites of data but i seem to have a problem recombining the data all it does is give me 1153. What i have done is when reading back from the eeprom i send each bite via RS232 to check if it is reading the correct data and everything is the same as what I have written to the mem im using this formula to recombine the data but dose not seem to work. I really do not know what i'm doing wrong
MemReturn = Debug_Verify_Data[0] | (Debug_Verify_Data[1] <<
MemReturn = MemReturn | (Debug_Verify_Data[2] << 16)
MemReturn = MemReturn | (Debug_Verify_Data[3] << 24)
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: I2C V6
Hi,
Due to the 8 bit processor you need to force use of a 32 bit temporary register,
something like this (where UTemp is a long)
Due to the 8 bit processor you need to force use of a 32 bit temporary register,
something like this (where UTemp is a long)
Code: Select all
MemReturn = Debug_Verify_Data[0]
UTemp = Debug_Verify_Data[1]
MemReturn = MemReturn | (UTemp << 8)
UTemp = Debug_Verify_Data[2]
MemReturn = MemReturn | (UTemp << 16)
UTemp = Debug_Verify_Data[3]
MemReturn = MemReturn | (UTemp << 24)
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Thanks Leigh
This worked like a dream another question if i want to delete the whole memory is there some sort of a bulk Delete command or do i have to cycle through each bite and wright 255 into it
This worked like a dream another question if i want to delete the whole memory is there some sort of a bulk Delete command or do i have to cycle through each bite and wright 255 into it
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: I2C V6
I think there is a page write option, where you can write up to 32 bytes per I2C transaction.
Ben made some notes about this earlier in this thread.
Ben made some notes about this earlier in this thread.
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: I2C V6
Hi Guys
I think I'm on the right track hopefully I have made a small program I2C_EEPROM_Erase what this does is write 16 x 16 bites of 0xFF 1 Block. If i'm reading the data sheet right, on a write you can write 16 bites before a stop or it will rollover on 24LC04. This EEPROM has 2 blocks 2 * (256 * 8 ) now if i'm correct the control Bite for block 1 is 10100010 (0xa2), if i want do do the same send 16 x 16 bites to block 2 would the control bite be 10100000 (0xa0) ??
Another thing am i correct in using the word address for the place in mem to be stored e.g Start then (Control bite 10100010) (word address (10000 highbite) (lowbite 0000000) = mem location 16) followed by 1 - 16 bites of data to be stored then a stop
I think I'm on the right track hopefully I have made a small program I2C_EEPROM_Erase what this does is write 16 x 16 bites of 0xFF 1 Block. If i'm reading the data sheet right, on a write you can write 16 bites before a stop or it will rollover on 24LC04. This EEPROM has 2 blocks 2 * (256 * 8 ) now if i'm correct the control Bite for block 1 is 10100010 (0xa2), if i want do do the same send 16 x 16 bites to block 2 would the control bite be 10100000 (0xa0) ??
Another thing am i correct in using the word address for the place in mem to be stored e.g Start then (Control bite 10100010) (word address (10000 highbite) (lowbite 0000000) = mem location 16) followed by 1 - 16 bites of data to be stored then a stop