Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:29 07 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Reading SD card.

     Page 1 of 3    
Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 01:33pm 20 Aug 2016
Copy link to clipboard 
Print this post

Hi All,

Want to start playing about with writing some data to the card.

Here's the difficult part:-

I'm playing around with an E64 on a breadboard birds nest at the moment,
So removing & replacing the card is a total PITA.

Am I right to assume I can just leave the card in & copy the file off to have a look with MMedit?

Haven't looked at how yet. Simple to do?

Thanks.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 02:23pm 20 Aug 2016
Copy link to clipboard 
Print this post

Short answer - No.

Long answer:
The maximite XMODEM command allowed copying to and from the SDcard.
The micromite only allows copying to the program memory. The option to do file copying is in the todo list but not yet.
If it happens, the File Manager in MMEdit would make life easy.

If you are only interested in text based files, you can easily incorporate the reading/writing into your own programs.

Alternatively, you could write a Basic XMODEM program to handle the stored files.
This is something I have considered but I am getting too far behind with other programming to make the offer.

Jim

VK7JH
MMedit
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 02:23pm 20 Aug 2016
Copy link to clipboard 
Print this post

What am I missing here?

I can download my code; done that many times before.

But how to I copy my text file off the card?

Thanks

Phil.



 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 02:57pm 20 Aug 2016
Copy link to clipboard 
Print this post

Thanks Jim,

Not sure if I missed something else, but while the card was in the E64 the touch did not respond.

Code still ran & it wrote data to the file, (Just formatted as CSV).

Card back out & touch came to life again. (Just had to comment out the File I/O Code).

Phil.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 03:42pm 20 Aug 2016
Copy link to clipboard 
Print this post

Not sure what's happening here.

If I break to a prompt, touch is still responding as expected without the code running, get the clicks as expected.

But if I send

Open "TestLog.txt" for APPEND as #2,

Touch immediately stops.

Reset is the only way to get it back.

So it's not the card being present, it's opening the card that is stopping touch.

All I really added was;-

[Code] Sub Logdata

OPEN "TestLog.txt" FOR Append AS #2
Print #2, Time$;",";TmpAmb;",";TmpPan;",";TmpCur;",";TmpInp;",";TmpOut;",";TmpDif;",";SlrVlt
Close #2

End Sub
[/code]

Called it on startup & then again every 5 minutes....

Cheers

Phil.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 03:51pm 20 Aug 2016
Copy link to clipboard 
Print this post

YES - the touch WILL stop responding WHILE the SD card is being accessed. This is because the SD card and touch controller are BOTH on the same SPI bus, and only ONE device can be using the bus at any one time. If the MM selects the SD card via it's CS line(done for you by MMBASIC), then the SD card has the bus, and anything else on the same bus can't have the bus, till the SD card CS line goes high again.

C'est La Vie........

Normally not a problem, as you are usually doing one or the other, but NOT both at the same time, if you see what I am getting at. In YOUR case, you might be trying to do something like that, in which case, it will fail, cos of the nature of how the SPI bus and CS lines work.

EDIT: Thinking about this some more, the touch does have an IRQ line, so perhaps I am wrong on this one, and it SHOULD work, as MMBASIC should get the IRQ pulse from the touch controller when it wants the bus. Weather the SD card handler will allow that interrupt request though, is another story. Once the file is open, all current SD card I/O might have to finish before it will release the SPI bus. I don't have the source code for MMBASIC, so can't comment on that, but matherp or Geoff may well chime in at this point.....Edited by Grogster 2016-08-22
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 04:10pm 20 Aug 2016
Copy link to clipboard 
Print this post

Thanks Grog,

Thers a bit of a confict in the manual I think.

Page 16:-

[Quote]64-Pin Example
For the Explore 64 board (64-pin Micromite Plus) the following allocations are recommended:
...Pin 12 for the SSD1966 LED_A control
...Pin 51 for the touch Chip Select
...Pin 33 for the touch IRQ input
...Pin 50 for the touch click output (see the next chapter)
...Pin 52 is the SD card Chip Select
The corresponding configuration commands are:
OPTION LCDPANEL SSD1963_5, LANDSCAPE, 12
OPTION TOUCH 51, 33, 50
OPTION SDCARD 52
These match the pin allocations on the TFT Backpack+ PCB board offered by CircuitGizmos.[/quote]


Bottom of Page 19...

[Quote]Specific Examples
On the Explore 64 module (http://www.rictech.nz/pages/5/Products) the SD Card Chip Select (CS) signal is on
pin 12 and the Card Detect (CD) signal is on pin 14. So, to enable the SD Card on this module the command is:
OPTION SDCARD 12, 14[/quote]

I've got:-

[Code]> option list
OPTION AUTORUN ON
OPTION LCDPANEL SSD1963_5, LANDSCAPE
OPTION TOUCH 51, 33, 50
OPTION SDCARD 12, 14
[/code]

Phil.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 04:25pm 20 Aug 2016
Copy link to clipboard 
Print this post

  Grogster said  Thinking about this some more, the touch does have an IRQ line, so perhaps I am wrong on this one, and it SHOULD work, as MMBASIC should get the IRQ pulse from the touch controller when it wants the bus....

I don't have the source code for MMBASIC, so can't comment on that, but matherp or Geoff may well chime in at this point.....


Re confirmed it a few times,

All I need to do is OPEN "File" as.... to lose the touch.

Closing it won't give it back as far as I can see.

 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 05:08pm 20 Aug 2016
Copy link to clipboard 
Print this post

Hi Phil.

The touch should only EVER not respond DURING I/O operations - transferring data to or from the card. If the file handle is open, but you are not actually transferring any data to or from any file AT THE POINT YOU ARE USING THE TOUCH, then that should work fine. Only while the SD card is actually clocking data in or out, should the touch NOT want to work, cos the SD card is using the bus.

At the point that the data to or from the SD card is finished, the SD card CS line should go high again, and anything else on the bus should be able to use it.

Put an LED + 1k resistor on the SD CS line(pin-12 of the E64 module) and 3v3 for a test:

3v3--->1k resistor--->LED ANNODE--->LED CATHODE--->PIN-12.

The LED should light when the SD card is selected by MMBASIC, but should remain OFF most of the time. If it stays ON all the time, then the CS line is being held low all the time, which will prevent anything but the SD card from talking on the bus.

You might have found a bug perhaps.......

If I get any time tonight, I will run some tests, but I would have expected this to have been reported as a problem before now if it really was, as lots of people use the LCD, TOUCH and SD together.

....with no disrespect to your issue, naturally......
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 05:50pm 20 Aug 2016
Copy link to clipboard 
Print this post

Connected the LED, activity is not overly bright, mid intensity.


Program running & Touch active.

^C
>

Touch objects still responding, switches dim etc, buzzer still clicking.

>Open "Test.txt" for Append as #2

Approx 500-700mS of LED activity.

Touch no longer responding.

>Close #2

Very brief LED activity.
Touch still not responding.

>Run

Code executing again but no touch.

^C
>Cpu Restart

Running again & touch active.

Phil.






 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 05:58pm 20 Aug 2016
Copy link to clipboard 
Print this post

Very interesting. That should NOT be happening.

LED activity sounds right. SD CS line does not appear to be being held permanently low, so we can rule that out. Very quick flash on the LED when you close the file handle sounds right. With the LED off at this point, the touch should respond.

I don't suppose you have another LCD you could try?

I am just wondering if you have a fluffy touch controller on that LCD you are using.

I will try to hook up an E64 and touch screen tonight and run these tests to see if I can replicate your issue.

EDIT: You can also move the LED+1k resistor you used on the SD CS line, to both the touch CS line, then the touch IRQ line and run the same tests. What you are looking for, is if the touch CS line and touch IRQ lines light the LED as the SD CS did, when you touch the screen. In both the touch CS and IRQ lines cases, BOTH should light the LED when you touch the screen. The IRQ line should light the LED whenever you touch the screen at all(this signals to the MM+ that the touch controller wants attention), and pretty much the same time, the touch CS line should also go low while you are touching the screen. It should not matter where you touch the screen, as these are just handshaking lines not data lines.Edited by Grogster 2016-08-22
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 06:29pm 20 Aug 2016
Copy link to clipboard 
Print this post

Just retested this with Geoff's "Pump Control" demo on Page 36.

Same scenario.

Break to prompt & Touch still responds.

OPEN "Test.Txt" for APPEND as #1 & the touch stops responding.

Just wanted to eliminate my own code that mixes the graphics.


Cheers

Phil.

Edit:-

Led connected to Touch CS, Pin 51,

Goes low, blinks, with every touch.

As soon as I open the file I get no activity on Touch CS

Closing #1; still the same.

Led connected to Touch IRQ, Pin 33,

Led on while ever touch is down.

One I give it Open file command I get no activity out of Touch IRQ.

Tried the other 5" screen I have here & the same.

Testing it on the Pump Control code....

2016-08-21_045313_Pump_Control_Demo_-_Original.zip

Only thing I've changed in it is added a couple of print lines to send the switch output to the console.


Version is 5.02.

Only other thing I can relate to it is, originally I configured the Panel with:-

[Code]OPTION LCDPANEL SSD1963_5, LANDSCAPE, 12[/code]

But have since changed it once I moved the jumper on the board from LED_A to 1963_PWM.

It now just set as:-

[Code]OPTION AUTORUN ON
OPTION LCDPANEL SSD1963_5, LANDSCAPE
OPTION TOUCH 51, 33, 50
OPTION SDCARD 12, 14
[/code]

Phil.





Edited by Phil23 2016-08-22
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 06:34pm 20 Aug 2016
Copy link to clipboard 
Print this post

Sounds like you might have found an obscure bug - I will email Geoff and ask him to check this thread if he has time. He is still on holiday though.

This is interesting to me, so I will see if I can hook up something here to test.

Out of interest, what version of MMBASIC are you using?

5.2?
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 07:14pm 20 Aug 2016
Copy link to clipboard 
Print this post

Can't exactly remember when I reconfigured the display, to changed it to PWM.

Think from memory I needed to do:-

[Code]OPTION LCDPANEL DISABLE
then after a reset,
OPTION LCDPANEL SSD1963_5[/code]
Has me thinking the something may have been left behind if it's not a known issue.


Phil.Edited by Phil23 2016-08-22
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 07:22pm 20 Aug 2016
Copy link to clipboard 
Print this post

This sounds like an obscure problem that I have had with the SD card code. Accessing some SD cards will cause the touch controller on the LCD panel to become unresponsive. The only solution is to reset the power on the LCD panel and therefore reset the touch controller.

I have lost many hours (days?) trying to track down this issue and I cannot tell if it is the fault of the SD card, the design of the LCD panel, the touch controller or the firmware. The only permanent fix is to test a number of different SD card to find one which works correctly.

I plan to switch to a different FAT driver in a future version and my hope is that will fix the issue. But, given my track record on this issue I am not sure.

Geoff (currently in Silicon Valley south of San Francisco).
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 07:26pm 20 Aug 2016
Copy link to clipboard 
Print this post

Wow, that is really odd.

Can't say I have seen it myself. I would LOVE for anyone else who has seen the same problem that Phil is seeing, to post on this thread, just for the purpose of collecting information.

How strange..........
Smoke makes things work. When the smoke gets out, it stops!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:42am 21 Aug 2016
Copy link to clipboard 
Print this post

Just tried to replicate this on the E100, but it works fine,

8 Gig cards in both cases, Full sized SD on the 100;
8 Gig Class 4 Sandisk MicroSD on the E64.


Phil.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:45am 21 Aug 2016
Copy link to clipboard 
Print this post

  Phil23 said   Just tried to replicate this on the E100, but it works fine,

8 Gig cards in both cases, Full sized SD on the 100;
8 Gig Class 4 Sandisk MicroSD on the E64.

Edit:- Will try the same MicroSD I used in the E64 in the E100 To-morrow.


Phil.
 
Nathan
Regular Member

Joined: 10/01/2016
Location: Germany
Posts: 49
Posted: 06:57am 21 Aug 2016
Copy link to clipboard 
Print this post

Hi,

also it is a little bit off topic.

Some of the SD cards requires an Pull up resistor
at the SPI IN (MISO) pin of the CPU. After the SD-Card
entered the SPI mode it is not required anymore.
The value should be between 10k and 100k.

I personally use a 10k resistor on miso and mosi and all
chip select lines by default.

Some of the LCD shields with the sd-card slot have a serial resistor,
in some sd lines. Mostly with a stamp of 102, which means 1KOhm.
I replace them with 100Ohm resistors (101). In case they are not replaced
it is better to use 50k resistors for pull up on that line.

Have fun

Nathan
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 11:19am 21 Aug 2016
Copy link to clipboard 
Print this post

Hi all,

In an attempt to test different cards as per @GeoffG 's comment I added a line to the Pump Control code:-

[Code]Case sw_pmp ' the pump on/off switch
Print CtrlVal(sw_pmp) 'Added to indicate Switch activity
CtrlVal(led_run) = CtrlVal(sw_pmp)
CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 20.1)
CtrlVal(r_norm) = 1
Case pb_test ' the alarm test button
CtrlVal(led_alarm) = 1
GUI beep 250
Open "Test.txt" For Append As #1 'Added to Test SD cards & touch issue
Case r_econ ' the economy radio button
[/code]

Strange thing is when I run the code it crashes when attempting to open the file.

[Code] 0
1
[96] Open "Test.txt" For Append As #1
Error: Cannot access the SD card
>[/code]

Strangely though, if I attempt to open the file at the prompt,
all the following commands are processed correctly, & the file on the card is created.

[Code]>
>
> Open "Test.txt" for Append As #1
> print #1, "Hello World"
> close #1
>[/code]

Slip the card in the PC:-

[Code]I:\>type test.txt
Hello World

I:\>[/code]

Phil.

No luck with any of 6 SD cards I've tried so far.
Sizes ranging from 512k up to 8 Gig.

All can be written to from the command prompt though.

But I can't even open them from within the Pump Control test code.

The only one success I've had is the one attempt on the Explore 100.

Really has me wondering if it's something hanging over from when I configured it for LED_A on pin 12.

Is there a way to reset MM.Basic at the prompt?, as I don't have a USB to TTL connected yet; still just the E64's interface, which I can't connect to until after it boots.

Cheers

Phil


Edited by Phil23 2016-08-22
 
     Page 1 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025