Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problems printing to SD card

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

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Fri Mar 23, 2007 8:14 pm    Post subject: Problems printing to SD card Reply with quote

Hi.

Yesterday, I wrote a small program to write some garbage data to an SD card to learn how to do it. And, it worked! I wanted to add a menu to the program, so today, I added a menu loop and suddenly it won't print data to the SD card. Here is the latest code:

Code:

'
' This is MyAVRDOS Second Try.bas
'
$regfile = "M128def.dat"
$crystal = 7372800

$hwstack = 128
$swstack = 128
$framesize = 128

$baud1 = 19200

Config Clock = Soft
Enable Interrupts
Config Date = Dmy , Separator = /
Dim Btemp1 As Byte
Dim Count As Word
Dim A As Word
Dim Choice As Byte

Open "Com1:" As Binary As #1                                ' use #1 for fs_interpreter
Config Serialin = Buffered , Size = 20

Print #1 , "Heeere we go!"
$include "Config_MMC.bas"

' Include AVR-DOS Configuration and library

If Gbdriveerror = 0 Then

$include "Config_AVR-DOS.BAS"

Beginning:

' Clear Screen
Print #1 , Chr(27)

' Display main menu and get choice
Print #1 , "MAIN MENU FOR DATA LOGGER" : Print #1,
Print #1 , "What do you want to do?" : Print #1 , : Print #1,
Print #1 , "1 To read the system time"
Print #1 , "2 To set the system time"
Print #1 , "3 To exit menu and log data" : Print #1,
Input "Enter Choice => " , Choice

Select Case Choice
   Case 1
      Print #1 , Time$
      Input "Hit any key to go back to main menu"
      Goto Beginning
   Case 2
      Goto Settime
   Case 3
      Goto Mainprog
   Case Else
      Print #1 , "Bad Choice.  Try Again. "
      Wait 1
      Goto Beginning
End Select

Mainprog:

Count = 0
A = 0

  Print #1 , "Starting the loop"
   Open "Test.txt" For Append As #10
   Print #1 , "Opened Test.txt"
   Print #10 , "Count" ; "{009}" ; "A"
   Print #1 , "Wrote headings to file"
   For Count = 1 To 100 Step 1
    Print #10 , Count ; "{009}" ; A
    Print #1 , Count ; "{009}" ; A
    A = A + Count
    Waitms 100
   Next Count
   Close #10
   Print #1 , "Loop done!"
End

Settime:

' Clear Screen
Print #1 , Chr(27)
Goto Beginning

Else
   Print #1 , "Error during Drive Init: " ; Gbdriveerror
End If
 


All the Print #1 statements work (i.e. send data to the serial port and read on the terminal emulator) and the menu loop works (i.e. the program branches where I want), but the program hangs up at the Print #10 statements. I added more Print #1 to see where is stops.

One other thing, I see in the manual that using the print statement in AVR-DOS you must use strings. Yesterday, it ran using the numeric values and the data showed up as numbers in the spreadsheet I imported the data into. However, as one of my fix tries, I changed the Print #10 statement as follows:

Code:


    Print #10 , str(Count) ; "{009}" ; str(A )

 


Anybody see a problem??

Thanks and Regards,

Pete

EDIT:

Forgot to mention that converting the variables to strings in the print statement had no effect.
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Tue Mar 27, 2007 6:36 pm    Post subject: Reply with quote

Hi.

Just an update on my problem. Still not able to print to the SD card.

I changed cards (two time, in fact!), ran the BASCOM update wizard (none found), ran a virus scan on my computer (getting despirate!), and the problem remains.

One more clue, if I comment out the PRINT #10 commands, the program works fine. I get no errors and all the "PRINT #1" commands work (i.e. I can see the output on the terminal emulator). However, when I look on the SD card there is no "test.txt" file. I assumed that there would be a file, but of 0 size. I opened the file (using both APPEND and OUTPUT at different times) and the file apparently is not created.

What am I doing wrong??

I'm coming to the conclusion that my BASCOM might be corrupted just like my 1.11.8.3 version was. To remind you, I had a program that Luciano and Ian were able to compile and run, they e-mailled me their compiled version and it ran, but my compiled version did not. My next step is to try my latest fixes on my BASCOM version I have at home.

Thanks for your time. Any suggestions would be appreciated.

Regards,

Pete
Back to top
View user's profile
oe9vfj

Moderator



Joined: 17 Jun 2004
Posts: 269
Location: Austria, Hard

austria.gif
PostPosted: Wed Mar 28, 2007 8:48 am    Post subject: Reply with quote

Every AVR-DOS command fills the variable gbDOSError with the information about the success-information.
0 is successful.
> 0 is an error.

Check after each command beginning with the InitFileSystem this variable.
I suppose, that there is a problem with the card. Can you work with this card on a PC. Probably try to reformat them.

_________________
regards Josef

DOS - File System for BASCOM-AVR on http://members.aon.at/voegel
Back to top
View user's profile Visit poster's website
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Wed Mar 28, 2007 7:08 pm    Post subject: Reply with quote

Josef,

Thank you for your reply.

As you suggested, I checked the value of gbDOSError after every line of the program. In all cases, the value is 0 except I cannot check the value after my 'PRINT #10' commands. The program halts at that line. So, I remarked those print statements out and all the gbDOSErrors are 0 including when I open and close test.txt.

And, yes, the SD cards work on my PC. I can write and read files to and from them using Windows Explorer.

One other thing I did not consider is that my test PCB might have been damaged somehow. My program worked last week, and suddenly stopped working. I should have thought of the board being bad. It will take me some time to get a replacement. I'll let you know any results.

Thank you again and Regards,

Pete
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Wed May 09, 2007 7:13 pm    Post subject: Reply with quote

Josef,

I am returning to this problem because I finally got my new boards!

I have the same problem with the new boards, so it is an error on my part.

To further investigate, I modified your Test_DOS_Drive.bas from the samples directory changing the $CRYSTAL and the $BAUD lines. I commented out line #17 ($Include "Config_HardDisk_M128.bas") because I am using a 256 MB SD card. Here's the code:

Code:

$regfile = "M128def.dat"
$crystal = 7372800

' Adjust HW Stack, Soft-Stack and Frame size to 128 minimum each!!!

$hwstack = 128
$swstack = 128
$framesize = 128

$baud = 19200
Open "Com1:" As Binary As #1                                ' use #1 for fs_interpreter
Config Clock = Soft
Enable Interrupts
Config Date = Mdy , Separator = .
Dim Btemp1 As Byte

Print #1 , "Wait for Drive"

' Include here you driver for Compactflash/HardDisk or other
$include "Config_CompactFlash_M128.bas"                     ' Does drive init too
'$Include "Config_HardDisk_M128.bas"

If Gbdriveerror = 0 Then

  ' Include AVR-DOS Configuration and library
$include "Config_AVR-DOS.BAS"

  Print #1 , "Init File System ... ";
  Btemp1 = Initfilesystem(1)                                ' Partition 1
                                          ' use 0 for drive without Master boot record
  If Btemp1 <> 0 Then
     Print #1 , "Error: " ; Btemp1 ; " at Init file system"
  Else
     Print #1 , " OK"
     Print #1 , "Filesystem: " ; Gbfilesystem
     Print #1 , "FAT Start Sector: " ; Glfatfirstsector
     Print #1 , "Root Start Sector: " ; Glrootfirstsector
     Print #1 , "Data First Sector: " ; Gldatafirstsector
     Print #1 , "Max. Cluster Nummber: " ; Glmaxclusternumber
     Print #1 , "Sectors per Cluster: " ; Gbsectorspercluster
     Print #1 , "Root Entries: " ; Gwrootentries
     Print #1 , "Sectors per FAT: " ; Glsectorsperfat
     Print #1 , "Number of FATs: " ; Gbnumberoffats
  End If
Else
   Print #1 , "Error during Drive Init: " ; Gbdriveerror
End If


' If you want to test with File-System Interpreter uncomment next line
'$include "FS_Interpreter.bas"
 


I got an error 206 in line 115 Library file not found (this is the CF_HD.lbx called out in Config_CompactFlash_M128.bas). I found the file on your web site and created the lbx file.

The program then compiled with no errors. However, when I ran it on my board, here is the output:

Quote:

Wait for Drive
Error during Drive Init: 225
225Wait for Drive
Error during Drive Init: 225
225Wait for Drive
Error during Drive Init: 225
225Wait for Drive


The output simply runs non-stop.

I looked at the manuals but I could not find out what it means when Gbdriveerror has a value of 225.

As always, thank you for your time.

Regards,

Pete

EDIT:

I should mention that I am running BASCOM 1.11.8.7 registered version.
Back to top
View user's profile
oe9vfj

Moderator



Joined: 17 Jun 2004
Posts: 269
Location: Austria, Hard

austria.gif
PostPosted: Fri May 11, 2007 9:39 am    Post subject: Reply with quote

Hi,

If you want to write on a SD Card, you have to use the driver for SD/MMC Card.

use

Code:
$Include "Config_MMC.bas"

instead $include "Config_CompactFlash_M128.bas"

check also hardware-setting in the file Config_MMC.bas according to your wiring.

_________________
regards Josef

DOS - File System for BASCOM-AVR on http://members.aon.at/voegel
Back to top
View user's profile Visit poster's website
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Fri May 11, 2007 8:00 pm    Post subject: Reply with quote

Joseph,

Thank you. That change you suggested worked.

However, I still can't write or print to the SD card. Here's my code:

Code:

$regfile = "M128def.dat"
$crystal = 7372800

$hwstack = 128
$swstack = 128
$framesize = 128

$baud1 = 19200

Config Clock = Soft
Enable Interrupts
Config Date = Dmy , Separator = /
Dim Btemp1 As Byte
Dim Count As Word
Dim A As Word
Dim Choice As Byte

Open "Com1:" As Binary As #1                                ' use #1 for fs_interpreter
Config Serialin = Buffered , Size = 20

Print #1 , "Heeere we go!"
$include "Config_MMC.bas"

' Include AVR-DOS Configuration and library

If Gbdriveerror = 0 Then

$include "Config_AVR-DOS.BAS"

Beginning:

' Clear Screen
Print #1 , Chr(27)

' Display main menu and get choice
Print #1 , "MAIN MENU FOR DATA LOGGER" : Print #1,
Print #1 , "What do you want to do?" : Print #1 , : Print #1,
Print #1 , "1 To read the system time"
Print #1 , "2 To set the system time"
Print #1 , "3 To exit menu and log data" : Print #1,
Input "Enter Choice => " , Choice

Select Case Choice
   Case 1
      Print #1 , Time$
      Input "Hit any key to go back to main menu"
      Goto Beginning
   Case 2
      Goto Settime
   Case 3
      Goto Mainprog
   Case Else
      Print #1 , "Bad Choice.  Try Again. "
      Wait 1
      Goto Beginning
End Select

Mainprog:

Count = 0
A = 0

  Print #1 , "Starting the loop"
   Open "Test.txt" For Append As #10
   Print #1 , "Opened Test.txt"
   Print #10 , "Count" ; "{009}" ; "A"
   Print #1 , "Wrote headings to file"
   For Count = 1 To 100 Step 1
    Print #10 , Count ; "{009}" ; A
    Print #1 , Count ; "{009}" ; A
    A = A + Count
    Waitms 100
   Next Count
   Close #10
   Print #1 , "Loop done!"
End

Settime:

' Clear Screen
Print #1 , Chr(27)
Goto Beginning

Else
   Print #1 , "Error during Drive Init: " ; Gbdriveerror
End If
 


The program simply stops at line #69 which reads

Code:


Print #10 , "Count" ; "{009}" ; "A"
 


If I comment out all the Print #10 statements, the program runs to the end.

Also, I checked the connections on my board with those used in Config_MMC.bas and they match (i.e. port b.0 is the chip select, port b.2 is the MOSI, etc.)

I'm pretty sure that the SD card is good because I can use it with my PC and I can run your Test_DOS_Drive.bas program using the cards.

Any other ideas or tests I can run??

As always, thank you for your time and patients!

Pete
Back to top
View user's profile
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