View previous topic :: View next topic |
Author |
Message |
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Fri Jun 05, 2020 6:12 pm Post subject: remove a sd card with the power on |
|
|
Hello,
I would like to be able to remove an sd card while the supply is on.
I opened and closed the files correctly
I take it out, read the card and reinstall it.
but when I try to make a new record, I get errors.
is there any way to avoid this?
many thanks
I cant give a sample of program it is tooooo (realy !) big
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
mmarlette
Joined: 30 Nov 2007 Posts: 311 Location: Delano, MN
|
Posted: Sun Jun 07, 2020 2:32 pm Post subject: |
|
|
Duval JP,
Use an interrupt on the card detect pin or a GPIO that is monitored in the main loop, depending on how your app is coded.
Make a routine that when the card is reinserted AVR-DOS is reinitialized.
Regards,
Mark |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Sun Jun 07, 2020 6:58 pm Post subject: |
|
|
Thank you Mark,
Today it is raining so I work a little bit to this tooo big program !
I did it but some variables are maybe hidden in the AVR-dos lib
My program work fine
At the end of the job, the user remove the card to see what it does withe a Excel file
then if it put it again
When the user push the start-again button I make a goto bebin
the begin label reinitialise everything less the name of user and the number of study the used did
but error sd card !
after I try to save the values in EEprom and do a goto 0
but I still have an error.
That is not a big problem I will write a message to stop machine before removing the card
But I dont like that !
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sun Jun 07, 2020 8:14 pm Post subject: |
|
|
before you remove a card, you need to flush the pending data. then close the files.
the next step is to turn off power to the card. and you might want to put the used SPI pins into high-z state. (or better have some buffer)
when re-inserted you can init the system again.
that is just a communication from the micro to the SD card.
but your problem is most likely not flushing the data. _________________ Mark |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Mon Jun 08, 2020 2:22 am Post subject: |
|
|
Hello JP
Maybe create a button "Press to Remove SD card"
Do the house keeping , flush buffer , close files , turn off power
then put message on screen "Now Safe to Remove SD Card"
Which is what I will have to do as I am going to use a SD card
to hold data.
Regards Paul |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Mon Jun 08, 2020 5:01 pm Post subject: |
|
|
Hi Mark,
You said
Quote: | but your problem is most likely not flushing the data. |
I did flush, I open and close file after use , I go to the root at the end and I add a flush instruction. but error again !
my program do a full re-inint of spi after the line begin
so I think about to disable SPI before re-init
in the help about spiinit
but I'm really don't know how to do to put the bit SPE to "0" that is assembler and i'm afraid about it
If somebody could help ?
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Jun 08, 2020 7:43 pm Post subject: |
|
|
you can do it in basic : spcr.spe=0
this would disable the SPI. just have a look in the datasheet at the SPCR register.
I also looked at the SD card spec.
it seems that you can put the card in idle mode by sending cmd0
in bascom you can do this like this : !call _mmcsd_Sendcmd0
this will put the card in idle mode. so do this when you finish writing and before you eject.
you should perform a simple test :
- write some data
- flush/close
- do not eject card
- re-init and see if it works ok.
do the same with ejecting.
it might not be required to disable the spi pins.
but... it would be good if you can switch the power of the card. maybe that is giving the problems. _________________ Mark |
|
Back to top |
|
|
|