ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
chipfryer27
Valued Contributor
Posts: 1149
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by chipfryer27 »

Hi

Quite by chance I've been playing with the SD card component and have issues. My chart simulated fine but when I tried in hardware my issues began. I cut everything back to just creating the file with no joy.

For me, I needed to insert a delay after initialising for it to then do anything, and cards make a difference. I have plenty 32Gb and above cards kicking around but few under, and the 2GB one I did have seemed to work (Sandisk).

However that was short lived. On hardware, although FC responds with the correct return indicating things have went well, in reality they haven't and again I couldn't even create a file. Not only that but an existing directory disappeared too. Card is now corrupted and unreadable. Good job it was from my girlfriend's camera and not my SD card..........

Logic analyser on SPI did show some funny stuff but as it's really cold now that can wait for another day.

Regards

mnfisher
Valued Contributor
Posts: 957
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 509 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by mnfisher »

Thanks Iain,

That's interesting - maybe I'm not dreaming it... I tried several approaches (including the examples from espressif) - none of which worked. I'll try again using the sdmode component.
Smaller 'FAT' SD cards are definitely an endangered species. I managed to find a 2GB card - but seemed corrupted beyond repair :-(

Martin

chipfryer27
Valued Contributor
Posts: 1149
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by chipfryer27 »

Hi

This link proved informative for me, as I knew little about the cards other than they connected using SPI

http://www.rjhcoding.com/avrc-sd-interface-1.php

In my chart I included a sanity check of my clock which pulsed a pin for 250mS four times. This was straight after setting my clock and before any initialisation of anything took place. My analyser showed a correct uC clock but also activity on SPI pins at the same time. The CLK pin was pulsing at just under 2MHz even though my clock is set at 8MHz with the SPI prescalers both set at /64. I thought that may be to do with the card reader responding to a reset uC and with the CLK pin disconnected from the chip, the pulse was still present so definitely generated by the reader.

I then modified my chart which would display "returns" when the chart initialises the SD component, opens folder and creates my file (failing at creation) to halt before initialisation of the component. A button press would then allow it to continue.

Way-hay, we have a winner.... This allowed the creation of a test file, verified by looking on the card on my laptop. I deleted the file and repeated. Each time I successfully created my file.

Now time to get rid of the button and replace it with a short delay and this is where things again started to go bad, tailing off towards the middle and best not to mention the end.

I was getting a bit cocky. I successfully replaced the button with a one second delay, but instead of then just figuring out my minimum delay, I then included an attempt to write some stuff to the file. Now the card that belonged in my girlfriend's camera is corrupted and can't be read (or formatted). All info contained is no more so you can guess how it ended. My defence of "if you are dumb enough to leave your camera in an Evil Lab then don't be surprised if not nice things happen" only seemed to inflame the situation but I've no idea why.......... Despite my central heating on full the house was still frosty.

My thoughts at present are that my writing of data caused my issue as prior to that, all was going well. I first used append byte to file which did populate the file but I then used write byte to buffer / write file to sector which appeared to screw things up. Maybe in hindsight I shouldn't have used defaults? Also, in the still cold light of day, I'm not sure when I replaced the 32Gbcard with the 2Gb. I might have been using a corrupted card up until I tried with the button, so the delay may not have been necessary, however I still think writing was the issue.

Regards

mnfisher
Valued Contributor
Posts: 957
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 509 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by mnfisher »

Uh oh - I see a rabbit hole....

See also https://electronics.stackexchange.com/q ... ion-in-spi

Try the 'I was just testing this shiny new ... I thought you'd like' Might work if it was recently backed up?

Martin

chipfryer27
Valued Contributor
Posts: 1149
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by chipfryer27 »

Hi

Trip to the jewellery shop seems the only remedial option still open to increase perceived temperature from freezing to a bit warmer. HoweverI have established a new temperature scale for such occasions. Much like Centigrade it too uses the symbol C but I'll use a small c for carats...... Funny how sparkly and shiny things instantly divert attention....

I'm back now to having working cards. What's that you say? Cards as in plural....?

Using Partion Master by Ease US (free edition) I reformatted both the 2Gb and 32Gb card and these both worked in the reader. I stress I've only created a file called "test.txt" on the card. Nothing else.

My chart powers / resets and first has my sanity check then delays for a second before initialising SD card component. It then opens folder and creates file returning the correct responses.

Regards

chipfryer27
Valued Contributor
Posts: 1149
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by chipfryer27 »

Hi

With both my 2Gb and 32Gb cards installed I can create a file then use AppendByteToFile and AppendStringToFile successfully. I then used WriteByteToBuffer and WriteFileSector to again successfully write to the disk. I also wrote, checked on a PC then appended further with no issue.

Might be the way Windows formats cards as yesterday I couldn't get the 32Gb to do anything and afterwards was unreadable, with the 2Gb becoming unusable with Windows unable to bring them to life. Ease US could access.

Formatted with Ease US I've had no issue so far.

Regards

stefan.erni
Valued Contributor
Posts: 758
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by stefan.erni »

Hi Lain, Hi Martin

I just use the windows for formating the sd cards.
One problem I remember when I had the SD card on the same SPI bus as a display,
I had to adjust all the clocks to the card init clock. That was the only way the card worked

Format with windows...
Snag_7a8b37.png
Snag_7a8b37.png (103.84 KiB) Viewed 1167 times

chipfryer27
Valued Contributor
Posts: 1149
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by chipfryer27 »

Hi Stefan

All my issues seem to have disappeared now that I formatted using 3rd-party tools. I can't explain why but although formatted with W10 before insertion they either could not read/write at all or quickly became unreadable and unformatable using W10. This would suggest some form of corruption took place.

Maybe using command line I could have resolved, but Ease US was just a couple of clicks <s>

Regards

mnfisher
Valued Contributor
Posts: 957
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 509 times

Re: ESP32 with 4bit sd-card sparkfun iot 9Dof and ISM330 DHCX

Post by mnfisher »

Still no joy - just playing with one of Ben's esp32-s3 wroom/ili9488 boards (very nice :-) ) - Attempting to compile with the SDMode component I get CONFIG_EXAMPLE_PIN_D0/D1/D2/D3/CLK/CMD undefined (in 4 bit mode - less in one bit)

A bit of a fiddle - but I tried defining the pins in CAL_FILE.c using the 'fixed' sdmode pins. Still kicking out the same error sadly.

Martin

Post Reply