Go Down

Topic: Use SPI Flash Chip as Sd Card (Read 511 times) previous topic - next topic

akash614

hi Guys


i have seen a project based on SD Card but in my usage it is risky as just you can open and steal and go through it

so i saw this SPI Flash Chip which has smaller amount of storage like mb so i choose to go for it but i wanna use same function of an sd card on SPI Flash Chip as well but have no luck

like reading writing files erasing and everything

please help me in this by providing a library or some piece of code

GoForSmoke

SD card has a controller that makes it act as a drive.

Flash card does not, it's far more primitive. You have to code where your data is for both reads and writes.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

akash614

SD card has a controller that makes it act as a drive.

Flash card does not, it's far more primitive. You have to code where your data is for both reads and writes.
but which is the right library to use

i used serialFlash library and cant understand this part  SerialFlash Library

Code: [Select]
unsigned int n;
          n = f.read(buf, 256);
          ff.write(buf, n);

does the write function erase everything and write to file or just add to the existing file

and what is this buf 256 is it the size of file or flash chip or something else

GoForSmoke

I haven't messed with flash chips but they do have to be written a sector at a time. First all the bits are set and then the sector 0's are set as the new data bytes are written.

You need to get the datasheet for the flash chip you bought to be sure.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

ShermanP

You could also consider obfuscating or encrypting the data written to the SD card.  At the most basic level, you could just XOR each byte with a constant byte.  That would make the data not easily readable, but it wouldn't take much to break it.  A more formal encryption method might be TEA or XTEA, for which there are probably Arduino libraries.

dave-in-nj

You can solder an sd card and hardwire to an Esp8266 or other 3.3 voltage chip.
Then glue it to the board.

Esp8266 also has more memory.

GoForSmoke

Yah, to get all those PCDOS file commands free you can pot (seal in epoxy) a wired and tested microSD with heatsink (metal washer or actual w/fins little heatsink) on one face to prevent heat buildup.

I once bought some custom shape SD's and they died of heat when copying big files and likely because of voltage-divider leveling 5V to 3V heat was insulated by the deco body with no heatsink.

But writing to serial flash might be easier and faster. You get the hard parts straight once in functions that make it easier to read/write.  For example, the functions (or C++ class for better packaged code) would operate on a buffer and automatically write a 128 byte page to the flash when the sketch fills the buffer.

You can address the whole storage space of the flash using unsigned longs and it's all made of 128 byte pages.

Your serial flash has a limited number of re-writes compared to EEPROM.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

akash614

You could also consider obfuscating or encrypting the data written to the SD card
i already used fingerprint in my project so i cant add another level of code as lack of space
You can solder an sd card and hardwire to an Esp8266 or other 3.3 voltage chip.
Then glue it to the board.

Esp8266 also has more memory.
i would like it to function as a keyboard also so only atmega32u4
Yah, to get all those PCDOS file commands free you can pot (seal in epoxy) a wired and tested microSD with heatsink (metal washer or actual w/fins little heatsink) on one face to prevent heat buildup.

I once bought some custom shape SD's and they died of heat when copying big files and likely because of voltage-divider leveling 5V to 3V heat was insulated by the deco body with no heatsink.
i have same problem the chip already soldered on pcb and has pads to program it but what do i do of 3.3v devices attached to vcc

can i turn off usb communication of atmega32u4 by disconnecting the UVCC or VBUS Pins so it does not interupt communication with another usb device on same port

GoForSmoke

You have to put a circuit or chip between 5V and SD.

The 74HC4050 hex buffer will convert 5V to 3V on 6 channels, buy a few and they're < 50 cents each.

You can use a diode to block the 5V coming through, when that wire is LOW it will drain voltage from the 3.3V side of the diode. You give the 3.3V side 3.3V through a 10-20K resistor to pull the SD pin up when the 5V side is HIGH and keeping the 3.3V pullup voltage from draining away. 
You would need 1 for each line the 5V transmits on (MOSI,SCLK,SEL) and none for lines the SD talks back on (MISO).

The chip is a little cleaner and can level 2 SPI devices but 3 diodes and 3 resistors are a lot cheaper and you may already have those.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

akash614

You have to put a circuit or chip between 5V and SD.

The 74HC4050 hex buffer will convert 5V to 3V on 6 channels, buy a few and they're < 50 cents each.

You can use a diode to block the 5V coming through, when that wire is LOW it will drain voltage from the 3.3V side of the diode. You give the 3.3V side 3.3V through a 10-20K resistor to pull the SD pin up when the 5V side is HIGH and keeping the 3.3V pullup voltage from draining away.  
You would need 1 for each line the 5V transmits on (MOSI,SCLK,SEL) and none for lines the SD talks back on (MISO).

The chip is a little cleaner and can level 2 SPI devices but 3 diodes and 3 resistors are a lot cheaper and you may already have those.
i will try this instead of using these i will before hand program the chip on board and later solder remaining 3.3v device

can i power off usb communication from pc by having a relay on VBUS and 5V+ and have it turn on when necessary

I am using on ATMega32U4 and not any other ATMega Chips as i need to use few keyboard commands

GoForSmoke

A relay? Really? Switching that takes more current than the chip would use in a long time.

For DC, transistors are far more efficient, only electrons move. Read up on MOSFETs. MOS is the type of semiconductor, FE is for field-effect and T is for transistor. 

The older BJ-Transistors (BJTs) had to have a little current on the control pin to get more current to flow through the other 2 pins, they heat up which limits their use for power switching. OTOH a BJT can be used as an electronic valve/volume control.
 

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

GoForSmoke

Arduinos have an in-system chip program header capable of loading hex files to your chip.

The Teensy 2.0 and the Arduino Micro (may be out of production) both have that USB chip.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

akash614

A relay? Really? Switching that takes more current than the chip would use in a long time.

For DC, transistors are far more efficient, only electrons move. Read up on MOSFETs. MOS is the type of semiconductor, FE is for field-effect and T is for transistor. 

i am actually using a MOSFET IRF5305PBF to Control it along with 10K and 100 ohm Resistors so i am interupting the communication between pc and MCU

Arduinos have an in-system chip program header capable of loading hex files to your chip.

The Teensy 2.0 and the Arduino Micro (may be out of production) both have that USB chip.
But i first need to burn the bootloader for which i need to use SPI Connection then program the chip and use it as a keyboard device is it ok

GoForSmoke

Arduino can run a PS2 keyboard directly.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

akash614

Arduino can run a PS2 keyboard directly.

sorry for late reply

i will be using a usb device connected on arduino board turned on and off by MCU & Mosfet and when on the MCU PC communication needs to be cut as it should not interfere in the signal of other causing it to breakdown

and i surely need the keyboard

or else can we read and write data to flash drive of random

Go Up