how to find sn for my flash memory
Hello!
I don't get it. Let's clarify things.
What do you mean by "map the scanned barcode"? You want to check
if the bar code has already been stored, right? So basically you use the
barcode as an address and you store a bit at this address?
Let's make it clear: you have one MCU, one Atmel flash.
You scan a barcode, you get 0xC0 01 67. What are these spaces. You
meant 0x00C00167, right?
As suggested above, you should divide by 8 (right shift by 3 may be faster).
Let's suppose you have functions to write and also read a single byte to flash
defined as uint8 read_at(uint32 where) and write_at(uint32 where, uint8 what).
- use 2 variables add(21 bits) and val
add = (code >> 3) & 0x001FFFFF; // AND with a 21 bit value, just in case
val = (uint8)(code & 0x00000007); // AND with 0x07 for the 3 last bits.
then transform it to get one bit at the position indicated by val
bitval = 1<<val;
Now if you write val at add, you would do:
write_at(add, bitval).
But id you have 2 values in a sequence (for instance if your codes are
0x00000018 and 0x00000019), you should write bit 0 of byte 3 and bit
1 of byte 3. (0x18 is 00011000 in binary, therefore 00000011 when shifted
by 3).
The solution (supposing you have already written the 0x00000018 code bit:
orgbitval = read_at(3); // Get the value already stored
bitval = orgbitval | (1 << val); // Stores 0x01 | 0x02 = 0x03 in my example
write_at(3, bitval);
Then you will have 2 consecutive bits and the value 0x03 will be written at
byte 3.
That's it! Have fun!
Dora.
jabidof said:
Sure
Imagine you scan a barcode and your MCU gets the following code in HEX:
0xC0 01 67
Now you have an external flash memory IC with 16Mbits of data.
The goal is to map the barcode just scanned (i.e. 0xC0 01 67) to a unique memory address of the flash IC and store a bit there.
Did I make it clearer?