Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

remove a sd card with the power on

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS
View previous topic :: View next topic  
Author Message
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Jun 05, 2020 6:12 pm    Post subject: remove a sd card with the power on Reply with quote

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
Wink
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 311
Location: Delano, MN

usa.gif
PostPosted: Sun Jun 07, 2020 2:32 pm    Post subject: Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sun Jun 07, 2020 6:58 pm    Post subject: Reply with quote

Thank you Mark,

Today it is raining so I work a little bit to this tooo big program ! Twisted Evil

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 !
Crying or Very sad
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sun Jun 07, 2020 8:14 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Jun 08, 2020 2:22 am    Post subject: Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Mon Jun 08, 2020 5:01 pm    Post subject: Reply with quote

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 Embarassed
If somebody could help ?
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Jun 08, 2020 7:43 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum