Page 1 of 2

Read/write sd card

Posted: Mon Nov 29, 2021 8:05 pm
by WingNut
Hi. I've been battling with a sd card read write for a while now. The flowcode below has stripped out of a bigger project to try and figure out why it doesnt work in hardware but simulates. Its messy but thats because ive been stripping things out adding things etc. Can you give me apointer? The circuit also uses an RTC which is working and I have spent quite a while figuring out which PIC to use, settling onPIC16F1887 for its ram size and features. Any help pointers greatly appreciated. Flowcode has greatly improved development speed up to now but I need your help now

Re: Read/write sd card

Posted: Mon Nov 29, 2021 8:17 pm
by WingNut
I should have added that I was using an sd card module with a 3.3 v regulator but changed to a micro sd module with regulator and level adjuster on board

Re: Read/write sd card

Posted: Tue Nov 30, 2021 8:38 am
by stefan.erni
Hi WingNut


Only SDHC or (microSDHC) card will work
32Giga is the largest that still works.

Set the Speed Prescaler to 64
divider_2021-11-30_8-36-50.png
divider_2021-11-30_8-36-50.png (46.03 KiB) Viewed 3736 times

Try to make a loop like this (name is fileSD ):
loop_2021-11-30_9-18-21.png
loop_2021-11-30_9-18-21.png (28.76 KiB) Viewed 3736 times
regards


Stefan

Re: Read/write sd card

Posted: Tue Nov 30, 2021 8:51 am
by WingNut
Stefan, thanks for your suggestion I'll give it a go when i get home tonight. I did think it might have been a clocking seed issue but had no idea where to start

Re: Read/write sd card

Posted: Tue Nov 30, 2021 9:11 pm
by WingNut
I tried as you suggested. Changed high speed prescaler value to 64 and made some changes to see what was being returned. So from the flowcode it displays 255 continuously as i wanted to give it as much time to initialise but to no avail

I'm using a 2GB micro sd card but i swapped for a 32GB sdhc card and same result. Checked all connections too

Re: Read/write sd card

Posted: Wed Dec 01, 2021 7:11 am
by stefan.erni
Hi WingNut

Can you try to switch the SPI Mode to software mode?
regards
Stefan

Re: Read/write sd card

Posted: Wed Dec 01, 2021 10:22 am
by WingNut
Same result Stefan

Re: Read/write sd card

Posted: Wed Dec 01, 2021 10:40 am
by stefan.erni
ok. What hardware do you have?

Here is my hardware as a sample how to connect a micro sd card to a PIC and set the port in FC.
Pin_SD_2021-12-01_11-30-46.png
Pin_SD_2021-12-01_11-30-46.png (206.98 KiB) Viewed 3671 times
pin_FC_2021-12-01_11-35-00.png
pin_FC_2021-12-01_11-35-00.png (42.44 KiB) Viewed 3671 times

Re: Read/write sd card

Posted: Wed Dec 01, 2021 10:50 am
by WingNut
This one connected as per the pinout on the device view
I have no pull up resistors or voltage dividers as the device has a regulator and level shifter

https://www.amazon.co.uk/gp/product/B07 ... UTF8&psc=1

Re: Read/write sd card

Posted: Wed Dec 01, 2021 11:03 am
by stefan.erni
So your PIC and your SD-card are both on 3.3v or 5.0 Volt?

The wiring is here

https://mschoeffler.com/2017/02/22/how- ... duino-uno/

Can you check if your SD card is FAT32 format (Windos click on drive and choose propertis)
Fat-2021-12-01_11-51-12.png
Fat-2021-12-01_11-51-12.png (22.12 KiB) Viewed 3668 times