Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

MBR on a SD Card ?

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

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Fri Mar 03, 2006 1:08 pm    Post subject: MBR on a SD Card ? Reply with quote

Good afternoon,
Does anyone know how to create an MBR on a SD Card ?
(Previous post topic refers)
Currently, AVR-DOS is reporting Error#17/No MBR. I don't know how to create a suitable MBR, if I need to create one... etc...
I'v formatted the SD Card (in this case a mini SanDisk 512MB in a mini-to-std adaptor) on my PC and can read/write (via the PC) from/to it... but AVR-DOS reports 'No MBR'...
Any ideas...
Thanks chaps.

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Fri Mar 03, 2006 4:30 pm    Post subject: Reply with quote

Hi,

If you format a Card on a PC with FAT16 or FAT32, it is suitable for AVR-DOS.
There are two kind of formatting a card.
The one is with a Master-Boot-Record at sector 0. This MBR contains in the partition table the information where to find the first sector (partition boot record - PBR) of the first partition.

The other kind of formatting is with no MBR. Here the first partition starts with the PBR at the first sector (sector 0).

If you init AVR-DOS with InitFileSystem(1), you can handle both ways. First AVR-DOS tries to get information about the first parititon (Sector# of the PBR). When it finds at the place of the partition table no valid information, AVR-DOS tries to handle the Sector 0 like the partition boot sector.

If you use the FS_Interpreter to AVR-DOS, please make a Dump of the sector 0 with SD 0. Please post the output of this dump, so it would be probably possible to say, what is the problem.

_________________
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
Wattsy

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Sat Mar 04, 2006 11:59 am    Post subject: Reply with quote

I'm well out of my depth... thanks for responing to my problem.

I don't even know how to use FS_Interpreter Evil or Very Mad I don't know where to put it, or how to call it/include it.... frustration... grrrr....

OK... calme toi...

I copied the FS_Interpreter.bas file to my code directory.
I then used the $Include "FS_Interpreter.bas" statement after my existing $Include "Config_AVR-DOS.bas" and bytInitFS = InitFileSystem(1) statements... and I get a load of errors. I'm obviously doing it wrong... I don't have a clue...

My code:

===============================================
'-------------------------------------------------------------------------------
' SPI.BAS
' homemade SPI example - attempts to teach SPI basics and then progress onto
' full SD Card file storage and retrieval...
'-------------------------------------------------------------------------------
'System DEFAULT Setup
$RegFile = "m128def.dat"
$Crystal = 9830400
$Framesize = 256
$HWStack = 64
$SWStack = 512

' Bascom Full version 1.11.8.2
' STK300 Dev Board
' ATMega 128L operating at 3.3V
' 9.8304MHz Xtal

Dim ss as Byte , strTxt as String * 40 , bytInitFS as Byte , DataLength As Byte

'500mS Clock Pulse Interrupt
Config Timer1 = Timer , Prescale = 64
Const Timer1Reset = &HB500 'Set to provide a clock pulse @ 500 mS intervals (&HB500@9.830400MHz)
On Timer1 Timer1_Reset

Config Clock = Soft
Time$ = "00:00:00"
Date$ = "01/01/01"
'Dim _Sec as Byte, _Min as Byte, _Hour as Byte, _Day as Byte, _Month as Byte, _Year as Byte ' (for FAT/AVR-DOS file data)

'Hardware UART(0) - PE0/1
$Baud = 19200
Config SerialIn = Buffered , Size = 128
Config Com1 = GPS , Synchrone = 0 , Parity = None , StopBits = 1 , DataBits = 8 , Clockpol = 0

'Hardware UART(1) - PD2/3
$Baud1 = 19200
Config SerialIn1 = Buffered , Size = 128
Config Com2 = ETNetwork , Synchrone = 0 , Parity = None , StopBits = 1 , DataBits = 8 , Clockpol = 0
Open "com2:" For Random As #1

'Show that we're starting
Print #1 , "Start"
Waitms 100

'Hearbeat (Pulsing LED just to let us know something's going on...)
Config PortB.7 = Output
Config PortB.6 = Output
Heartbeat Alias PortB.7
Reset Heartbeat 'Just to let us know we've got this far

'Push to End/Exit switch
Config PortD.0 = Input

Enable Timer1
Enable Interrupts

'Connection as following
'MMC M128/M103
'1 MMC_CS PORTB.0
'2 MOSI PORTB.2
'3 GND
'4 +3.3V
'5 CLOCK PORTB.1
'6 GND
'7 MISO, PORTB.3

' you can vary MMC_CS on HW-SPI and all pins on SOFT-SPI, check settings
' ========== Start of user definable range =====================================

' you can use HW-SPI of the AVR (recommended) or a driver build in Soft-SPI, if
' the HW-SPI of the AVR is occupied by an other SPI-Device with different settings

' Declare the SPI-Mode
' using HW-SPI: cMMC_Soft = 0
' not using HW_SPI: cMMC_Soft = 1

'Set-up SPI Use (0=Hardware pins (M128 B0,1,2,3)
Const cMMC_Soft = 0

'Set-up the CS Pins (SD Card / RTC)
Config PinB.4 = Output
Mmc_cs Alias PortB.4
Set Mmc_cs

Config PinB.5 = Output
RTC_cs Alias PortB.5
Reset RTC_cs

'Set-up the Card Inserted & available Pin
'We're currently using PortB.6 as a tell-tale LED so Rem out the next two lines
'Once the code is O.K., the tell-tale LED will go and these lines will be de-rem'ed
'Config PortB.6 = Input
'MMC_Avail Alias PortB.6

'Set-up the SS Pin (SPI as Master )
Config PortB.0 = Output
Spi_ss Alias PortB.0
Set Spi_ss

'HW-SPI is configured to highest Speed
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
'Spsr = 1 ' Double speed on ATMega128
SPIInit ' Init SPI

Const Cperrdrivereset = 225 ' Error response Byte at Reset command
Const Cperrdriveinit = 226 ' Error response Byte at Init Command
Const Cperrdrivereadcommand = 227 ' Error response Byte at Read Command
Const Cperrdrivewritecommand = 228 ' Error response Byte at Write Command
Const Cperrdrivereadresponse = 229 ' No Data response Byte from MMC at Read
Const Cperrdrivewriteresponse = 230 ' No Data response Byte from MMC at Write
Const Cperrdrive = 231
Const Cperrdrivenotsupported = 232 ' return code for DriveGetIdentity, not supported yet

Waitms 1 ' Wait some time before initialising MMC/SD
Dim gbDriveError As Byte ' General Driver Error register
Dim Gbdriveerrorreg As Byte ' Driver load Error-Register of HD in case of error
Dim Gbdrivestatusreg As Byte ' Driver load Status-Register of HD on case of error
Dim Gbdrivedebug As Byte
Dim ErrText As String * 40
Dim bitSPIError As Bit
Dim bitFileError As Bit

$Lib "MMC.LIB" ' link driver library
$External _mmc
gbDriveError = Driveinit() ' Init MMC/SD Card

If gbDriveError <> 0 then

Select Case gbDriveError
Case 225
ErrText = "Drive Reset Error"

Case 226 ' Error response Byte at Init Command
ErrText = "Drive Init Error"

Case 227 ' Error response Byte at Read Command
ErrText = "Drive Read Command Error"

Case 228 ' Error response Byte at Write Command
ErrText = "Drive Write Command Error"

Case 229 ' No Data response Byte from MMC at Read
ErrText = "Drive Read Response Error"

Case 230 ' No Data response Byte from MMC at Write
ErrText = "Drive Write Response Error"

Case 231
ErrText = "Drive Error"

Case 232 ' return code for DriveGetIdentity, not supported yet
ErrText = "Drive Not Supported Error"

Case Else
ErrText = "Unknown Error"

End Select
Print #1 , "Card Error " ; gbDriveError ; " = " ; ErrText
Waitms 100

Set bitSPIError

Else
Print #1 , "Card Initialised OK " ; gbDriveError
Waitms 100
Reset bitSPIError

End If

$Include "Config_AVR-DOS.bas"

bytInitFS = InitFileSystem(1)
If bytInitFS <> 0 Then

Select Case bytInitFS

'Group 0 (0-15): 0=No Error / 1-15=File End Information
Case 1
ErrText = "EndOfFile reached"

'Group 1 (17-31): File System Init
Case 17
ErrText = "No MBR detected"

Case 18
ErrText = "No PBR detected"

Case 19
ErrText = "File System Not Supported"

Case 20
ErrText = "Sector Size Not Supported"

Case 21
ErrText = "Sectors Per Cluster Not Supported"

Case 22
ErrText = "Count Of Clusters Not Supported"

'Group 2 (32-47): FAT - Error
Case 33
ErrText = "Next Cluster Not Found"

Case 34
ErrText = "No Free Cluster Found"

Case 35
ErrText = "Cluster Error"

'Group 3 (49-63): Directory Error
Case 49
ErrText = "No Free Dir Entry"

Case 50
ErrText = "File Exists"

Case 51
ErrText = "File Delete Not Allowed"

Case 52
ErrText = "Sub Directory Not Empty"

Case 53
ErrText = "Sub Directory Error"

Case 54
ErrText = "Not A Sub Directory"

' Group 4 (65-79): File Handle
Case 65
ErrText = "No Free File Number"

Case 66
ErrText = "File Not Found"

Case 67
ErrText = "File Number Not Found"

Case 68
ErrText = "File Open No Handle"

Case 69
ErrText = "File Open Handle In Use"

Case 70
ErrText = "File Open Share Conflict"

Case 71
ErrText = "File In Use"

Case 72
ErrText = "File Read Only"

Case 73
ErrText = "File No WildCardAllowed"

Case 74
ErrText = "File Number In Valid"

' Group 7 (97-127): other errors
Case 97
ErrText = "File Position Error"

Case 98
ErrText = "File Access Error"

Case 99
ErrText = "Invalid File Position"

Case 100
ErrText = "File Size To Great"

Case &HC0
ErrText = "Driver Error Start"

Case Else
ErrText = "Unknown Error"

End Select

Print #1 , "File System Error " ; bytInitFS ; " = " ; ErrText
Waitms 100
bitFileError = 1
Else
Print #1 , "File System Initialised OK " ; bytInitFS
Waitms 100
bitFileError = 0
End If

$Include "FS_Interpreter.bas"

Open "Test.txt" For Append As #10 'Filenums >=10 are best

Do

'Do this code / write to the 'Test" file once per second
If ss <> _Sec Then
ss = _Sec
strTxt = Date$ + " " + Time$
DataLength = Len(strTxt)

'O / p data to the Test file...
Print #10 , strTxt

'... and now to a HyperTerminal (or similar) screen...
'SpiOut strTxt , DataLength
Print #1 , strTxt
Toggle PortB.6
End If

'Check to see if we want to exit now...
If _hour = 1 and _min = 59 Then Goto EndProg
If PinD.0 = 0 Then Goto EndProg

Loop


'Heartbeat LED
Timer1_Reset:
Timer1 = Timer1Reset
Toggle Heartbeat

Return

'End our little Test Prog here
EndProg:
Print #1 , "End of Prog..."
Print #10 , "End of Prog..."
Flush #10
Close #1
Close #10 'Unnecessary I think but tidy...
Waitms 1000

End
===============================================

Sorry to be so thick...

Suggestions please ?

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
Wattsy

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Sat Mar 04, 2006 11:55 pm    Post subject: Reply with quote

Good evening Josef,
Thanks for your help, I hope you have time to read and respond to this...

I am REALLY struggling here. I have spent a week or more on this one thing (SD <--> ATM128L) and still I feel I'm getting nowhere fast... Sad

I suppose I should first make sure I need to go down the route I am going down, AVR-DOS etc...

I'm trying to datalog Temperature to a SD Card at a specific interval. I have all but the data logging working...
My requirement is to log the following data fields ;
Date dd/mm/yy
Time hh/mm/ss
Temp ddd.d
<CR>
<LF>
in a definite, comma-delimited, sentence structure :
dd/mm/yy , hh:mm:ss , ddd.d <CR><LF>
dd/mm/yy , hh:mm:ss , ddd.d <CR><LF>
dd/mm/yy , hh:mm:ss , ddd.d <CR><LF>
dd/mm/yy , hh:mm:ss , ddd.d <CR><LF>
.
.
.

This will be the only file/data stored on the SD card.

[Q1] Do I really need AVR-DOS ? Or can I just write/read to/from the card ? (Please bear in mind (as if it wasn't already apparent) I'm a complete newbie to this - we already do this on a PC (easy) but the AVR is new...). The reason for asking is that the AVR-DOS code appears to require a fair chunk of SRAM that I could use (512bytes I believe ?)

[Q2] When the card fails to initialise (for whatever reason) it takes 34 or 35 seconds to make up its mind. What's happening during this time ?

[Q3] If a card reports 0 after initialisation (Initialised OK) can I assume that a 'comms. link' has been successfully established between the AVR and the SD card? ie: my hardware connections are OK ? Or Not ? I'm still trying to ascertain that the 'problem' lies within my software NOT my hardware (possibly both but...)

[Q4] If I do need AVR_DOS (and I can see benefits of using it) then what the $#-# am I doing wrong ?

For indication I set up a 500mS timer (Timer1) to flash an LED on PortB.7 for the duration of the code (to detect hangs etc.)
I was getting Error#17 after correct card initialisation , now I'm (pretty much always) getting a Error#229 (No data Response at Read)
If I eject the card and re-insert it some part of the code recognises this and reports the card as being initialised and the '0000>' prompt is re-displayed on my terminal...
If I type SD 0 at the '0000>' promt either nothing happens OR the ISP indicates a reset occuring on my SDK/M128L and Timer1 stops/tell-tale LED stops flashing... Once this happens removing and re-inserting the SD Card makes no difference - the system appears to have hung...

Anyway, hyperterminal extract printout follows :

Test_Dos_Drive compiled at 03-04-2006 15:09:58
Waiting for SD drive...
Card Initialised OK: 0
Init File System ... Error: 229 at Init file system
AVR-DOS: Ready for commands

0000>Test_Dos_Drive compiled at 03-04-2006 15:09:58
Waiting for SD drive...
Test_Dos_Drive compiled at 03-04-2006 15:09:58
Waiting for SD drive...
Card Error 225 = Drive Reset Error
AVR-DOS: Ready for commands

At the 0000> I typed SD 0
If I restart from my ISP the above occurs all over again...
If I remove power from my IDE and re-apply the above occurs all over again...

I am completely lost... If I swap MOSI/MISO or remove SCLK I get an Error #255 (Drive Reset Error) on power up (after 34/35 secs) which, to me 'proves'(?) my hardware is OK (dubious proof but about as far as I can go, I think). Swapping the card for a DaneElec 256 doesn't help (but then I think DaneElec's aren't liked by this set-up - whereas SanDisks are at least recognised - I've tried three 512 versions...)

Appologies for these long posts but... I really AM in NEED of some help - I'm more than willing to pay you (or anyone) for a speedy answer... this is driving me insane...

Finally, what does BTW mean (I know, I'm thick...) when used on the forum ? example : BTW just use....

Thanks in hope...

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Sun Mar 05, 2006 9:01 pm    Post subject: Reply with quote

Hi Wattsy,

[Q1] AVR-DOS is the easiest way (if the communication with the card is OK) to log data, that must be read by a PC.
If you have only one file to write, there is an alternative way:
Store a huge empty file on a empty (fresh formatted) card. For example, you can save only spaces to that file. The file size should be greater than data size to save by the AVR. Detect the first sector of the file on the card (with a Hex-Editor, which can read single sectors of the card). If you start your dummy file with a significant text, you should have no problem to find that sector.
If you know that sector# you can write your data in a buffer of 512 bytes in the SRAM and write this buffer to the card with DriveWriteSector starting at the first sector# of that file. Check the help file for the command DriveWriteSector.
Later you can read this data on the PC opening the first creating file.

[Q2]I will check the code, what happened during this time. On a HardDisk the specification say, that the Harddisk can use up to 31 seconds to spin up. Due to the fact, that CF-Cards and HardDisks uses the same drive, CF-Card can use also this time, if the is something wrong. But on CF-Cards this should not occur. I will check it.

[Q3]
If the Card Initialization report 0, that card connection should be OK.

[Q4]
Difficult to say what is wrong, can you post your program current in use and your schematic. Please note, taht not all cards works proper with that driver. I made best experiences with SANDISK cards. Other users told problems with some other manufactores too, but I couldn't verify the problem till now.

I think the only point at the moment to bring some light to your problem is to check your code and your schematic. May be I can try your code on my board.

In the minimal configuration you need appr. 1200 Bytes for AVR-DOS (1 File handle)


BTW: is the abbreviaton of "By The Way".

_________________
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
Wattsy

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Mon Mar 06, 2006 10:30 am    Post subject: Reply with quote

Good morning Josef,

Many, many thanks for your response (and many apologies for bothering you with this... all other posts indicate no problems and fantastic work... I'm sorry to be a pain in the backside...) Ok, all that said...

Taking your answers in order (to keep things simple) :

[1] I only want to read/write via the ATM128L - not via a PC. However, I'd still prefer to use your AVR-DOS - The reason for asking was my trying to keep file handler RAM usage to a minimum - so thanks again for clearing up this question...

[2] I understand. 34/35 secs is the norm for me, if, say, I do not insert a SD Card and run the code then 34/35 secs AFTER starting I get a Card Initialisation Error#225. Insert the card and re-start the code and I get File Initialisation Error#17 or Error#229 EVERY TIME - and that's it.

[3] O.K. The card should be OK following an Error#0 report on card initialisation. During this card initialisation does data pass FROM the AVR TO the card and FROM the card TO the AVR ? If so then I guess the hardware connections are OK. However... what d'you think ? I'm asking this for immediate reasons and because I'd like to know for the future.
I've used the schematic @ http://members.aon.at/voegel/Downloads/Driver/MMC/Mmc_gif_1.gif as my basis for the connection :
Exact data for me :
Mini SanDisk 512MB card in a SanDisk mini-std adaptor
Pin1 (SS) -> PortB.4 (Normally, we'd also use an RTC (DS1306) on PortB.5 - PortB.4 is permanently high in this little test code : my code refers)
Pin2 (MOSI) -> PortB.2
Pin3 (VSS) -> GND (+ link to Pin6)
Pin4 (VDD) -> VCC (3.3V generated by AVR STK300 IDE - checked correct)
Pin5 (SCLK) -> PortB.1
Pin6 (VSS) -> GND (+ link to Pin3)
Pin7 (MISO) -> PortB.3
No pull ups etc are used as all power is at 3.3V. Wired connections are via std single core linking cable (approx, 12.5cm long. 6 wires in total)
Like I say; Card Inserted & Power Up = Card Initialisation OK (Error#0) / Card Removed & Power Up = Card Initialisation FAIL (Error#225)

Upon power up (SD Card inserted), the standard response is as follows (all within 1sec or so...)
Test_Dos_Drive compiled at 03-06-2006 10:05:20
Waiting for SD drive...
Card Initialised OK 0
Init File System ... Error: 17 at Init file system
AVR-DOS: Ready for commands

0000>

Upon power up (SD Card removed), the standard response is as follows (after <<<<34/35>>>> sec delay...)
Test_Dos_Drive compiled at 03-06-2006 10:05:20
Waiting for SD drive...
<<<< 34/35 sec delay>>>>
Card Error 225 = Drive Reset Error
AVR-DOS: Ready for commands

0000>

[4] OK, no probs. Schematic as in [3] above. Code follows. I have extracted the Config_Mmc code and placed it within the body of my code just for clarity. I have not touched AVR-DOS code...
==================C O D E B E G I N S=================
$regfile = "M128def.dat"
$crystal = 9830400

$HWStack = 128
$SWStack = 128
$FrameSize = 128

'500mS Clock Pulse Interrupt
Config Timer1 = Timer , Prescale = 64
Const Timer1Reset = &HB500 'Set to provide a clock pulse @ 500 mS intervals (&HB500@9.830400MHz)
On Timer1 Timer1_Reset
Config PortB.7 = Output
Heartbeat Alias PortB.7

'Hardware UART(0) - PE0/1
$Baud = 19200
Config SerialIn = Buffered , Size = 128
Config Com1 = GPS , Synchrone = 0 , Parity = None , StopBits = 1 , DataBits = 8 , Clockpol = 0

'Hardware UART(1) - PD2/3 - USE #1 FOR FS_INTERPRETER
$Baud1 = 19200
Config SerialIn1 = Buffered , Size = 128
Config Com2 = ETNetwork , Synchrone = 0 , Parity = None , StopBits = 1 , DataBits = 8 , Clockpol = 0
Open "com2:" For Random As #1

Config Clock = Soft
Enable Timer1
Enable Interrupts
Config Date = dmy , Separator = .
Print #1 , "Test_Dos_Drive compiled at " ; version()
Dim bTemp1 As Byte

''Include here you driver for Compactflash/HardDisk or other
''$Include "Config_XRAMDrive0.bas"
''$include "Config_CompactFlash_ElektorIF_M128.bas"
''$Include "Config_CompactFlash_M128.bas"
''$Include "Config_HardDisk.bas"
'$Include "Config_MMC(ERDALL).bas"

'Connection as following
'MMC M128/M103
'1 MMC_CS PORTB.0
'2 MOSI PORTB.2
'3 GND
'4 +3.3V
'5 CLOCK PORTB.1
'6 GND
'7 MISO, PORTB.3

' you can vary MMC_CS on HW-SPI and all pins on SOFT-SPI, check settings
' ========== Start of user definable range =====================================

' you can use HW-SPI of the AVR (recommended) or a driver build in Soft-SPI, if
' the HW-SPI of the AVR is occupied by an other SPI-Device with different settings

' Declare the SPI-Mode
' using HW-SPI: cMMC_Soft = 0
' not using HW_SPI: cMMC_Soft = 1

'Set-up SPI Use (0=Hardware pins (M128 B0,1,2,3)
Const cMMC_Soft = 0

'Set-up the CS Pins (SD Card / RTC)
Config PinB.4 = Output
Mmc_cs Alias PortB.4
Set Mmc_cs

Config PinB.5 = Output
RTC_cs Alias PortB.5
Reset RTC_cs

'Set-up the Card Inserted & available Pin
'We're currently using PortB.6 as a tell-tale LED so Rem out the next two lines
'Once the code is O.K., the tell-tale LED will go and these lines will be de-rem'ed
'Config PortB.6 = Input
'MMC_Avail Alias PortB.6

'Set-up the SS Pin (SPI as Master )
Config PortB.0 = Output
Spi_ss Alias PortB.0
Set Spi_ss

'HW-SPI is configured to highest Speed
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
'Spsr = 1 ' Double speed on ATMega128
SPIInit ' Init SPI

Const Cperrdrivereset = 225 ' Error response Byte at Reset command
Const Cperrdriveinit = 226 ' Error response Byte at Init Command
Const Cperrdrivereadcommand = 227 ' Error response Byte at Read Command
Const Cperrdrivewritecommand = 228 ' Error response Byte at Write Command
Const Cperrdrivereadresponse = 229 ' No Data response Byte from MMC at Read
Const Cperrdrivewriteresponse = 230 ' No Data response Byte from MMC at Write
Const Cperrdrive = 231
Const Cperrdrivenotsupported = 232 ' return code for DriveGetIdentity, not supported yet

Waitms 1 ' Wait some time before initialising MMC/SD
Dim gbDriveError As Byte ' General Driver Error register
Dim Gbdriveerrorreg As Byte ' Driver load Error-Register of HD in case of error
Dim Gbdrivestatusreg As Byte ' Driver load Status-Register of HD on case of error
Dim Gbdrivedebug As Byte
Dim ErrText As String * 40
Dim bitSPIError As Bit
Dim bitFileError As Bit

Print #1 , "Waiting for SD drive..." : Waitms 100

$Lib "MMC.LIB" 'link driver library
$External _mmc
gbDriveError = DriveInit() 'Init MMC/SD Card

If gbDriveError <> 0 then
Select Case gbDriveError
Case 225
ErrText = "Drive Reset Error"

Case 226 'Error response Byte at Init Command
ErrText = "Drive Init Error"

Case 227 'Error response Byte at Read Command
ErrText = "Drive Read Command Error"

Case 228 'Error response Byte at Write Command
ErrText = "Drive Write Command Error"

Case 229 'No Data response Byte from MMC at Read
ErrText = "Drive Read Response Error"

Case 230 'No Data response Byte from MMC at Write
ErrText = "Drive Write Response Error"

Case 231
ErrText = "Drive Error"

Case 232 'return code for DriveGetIdentity, not supported yet
ErrText = "Drive Not Supported Error"

Case Else
ErrText = "Unknown Error"

End Select
Print #1 , "Card Error " ; gbDriveError ; " = " ; ErrText
Waitms 100
Set bitSPIError

Else
Print #1 , "Card Initialised OK " ; gbDriveError
Waitms 100
Reset bitSPIError

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

Print #1 , "Init File System ... ";
Btemp1 = Initfilesystem(0) ' 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
Print #1 , ""
Print #1 , "AVR-DOS_Config Settings"
Print #1 , cFileHandles ; " File-Handles (cFileHandles = " ; cFileHandles ; ")"
Print #1 , "Directory and Fat handled in " ;
#IF cSepFATHandle = 1
Print #1 , " different buffers";
#ELSE
Print #1 , "same buffer";
#ENDIF
Print #1 , "(cSepFATHandle = " ; cSepFATHandle ; ")"
Print #1 , "Directory and Fat Information of a File saved " ;
#IF cFATDirSaveAtEnd = 1
Print #1 , "only at Flush and Close" ;
#ELSE
Print #1 , "at every Data Sector" ;
#ENDIF
Print #1 , "(cFATDirSaveAtEnd = " ; cFATDirSaveAtEnd ; ")"
End If
End If


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


End

'Heartbeat LED
Timer1_Reset:
Timer1 = Timer1Reset
Toggle Heartbeat
Return
==================C O D E E N D S=================

Thanks for BTW (I'm a fool )

Looking forwrd to hearing from you...[url][/url]

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
Wattsy

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Tue Mar 07, 2006 11:12 pm    Post subject: Reply with quote

Good evening Josef,
I forgot to mention that ejecting and re-inserting the SD Card hot (with the code running) appears to re-initialise the MMC/AVR-DOS code. My code continues to run (does NOT reboot/restart) BUT your MMC / AVR-DOS deffinitely 'sees' the card as having been (re-)inserted and and re-prints the error code...

Just a BTW... but it might help (at least, to me, it 'proves (?)' the hardware / cabling... ) ... I think... Confused

Thanks.

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
Wattsy

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Sun Mar 12, 2006 12:06 am    Post subject: Reply with quote

Good evening Josef,
I tried to respond to your off-site e-mail but it was returned - 'over quota' specified as reason... anyway, I've included the latest below... I really hope this helps a bit... and... thanks (again)...

O.K. (usual apologies for bothering you with this)...

[1] Disconnecting the SD Card and connecting a DS1306 RTC (SPI mode) produces perfect results for the RTC (I have both Read and write capability now with this RTC using the SPI interface).

[2] Removing the RTC and re-connecting the SD Card :
In the past I used a DaneElec 128Mb card - it didn't work at all (previous forum posts refer)
I then used the SanDisk mini SD 512Mb (with SanDisk mini-std adaptor) - with the results as documented this past week.
Today (just now) i went and bought a standard size SanDisk 512Mb card and plugged it in with the results to various commands (via FS_Interpreter) detailed below...
Just for info : I am now running with your new (e-mailed) FS_Interpreter file ( I extracted your Zip file and placed the new FS_Interpreter in the same folder as my test prog (e-mailed to you earlier this week via the forum), re-compiled the code and uploaded back onto the AVR 128L.
I believe that the results PROVE the hardware (cabling, power supply etc are O.K. but... I'd take your advice as to anything else you may suggest...)
My schematic/hardware/set-up :

An AVR128L on a Kanda STK300 IDE. This board sits adjacent to a large RS breadboard development area (A4 size) complete with inbuilt power supplies etc... The SD Card socket (std size) is soldered to a piece of Vero board and connected as follows :

Looking at the SD card with connection side facing you (uppermost) :

----------------------------------------------------
| 8 n/c |
| 7 MISO ---> PB.3 |
| 6 VSS2 (Gnd) |
| 5 SCLK ---> PB.1 |
| 4 VCC (3.23V from IDE PCB) |
| 3 VSS (Gnd) |
| 2 MOSI ---> PB.2 |
| 1 CS ---> PB.4 |
\ 9 n/c |
\----------------------------------------------------

... and connected to the Vero board(via 75mm flying leads - standard single core Vero cable) and from there to the AVR via a 250mm IDE style ribbon cable and the STK300 PCB

The new card does have some changed o/p (not yest formatted in a PC/straight out of the box)...

0000>sd 0
Dump Sectors from 0 to 0
Read Sector: 0 ... Error 227 at sector# 0
Drive Error: 227
Drive Status:11111111
Drive Debug: 0

0000>MBR
Read Master Boot Record ... done
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

Partition-Table


0000>CFI
Read Card Info
Drive Error: 232
Drive Status:00000000
Drive Debug: 0

0000>CFINIT
OK

0000>CFCHECK
OK

0000>CFRESET
OK

0000>DISKSIZE

No answer was received here but the code did not 'hang'...

Formatting and re-inserting the new card :

0000>sd 0
Dump Sectors from 0 to 0
Read Sector: 0 ... Error 229 at sector# 0
Drive Error: 229
Drive Status:00000000
Drive Debug: 0

0000>

I look forward to hearing your thoughts / anything else I can try...
I'm begining to feel that this is something REALLY simple that my newbie-ness is just not thinking of...

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Thu Mar 16, 2006 4:23 pm    Post subject: Reply with quote

Hello Ian,

I am just on a business journey, so can only make a short answer.

SD 0 and MBR is doing at the first step the same. They dump the sector 0.
In a second step MBR reads the partition table and shows the installed partitions.
If SD 0 brings an card-error, MBR should do the same.

I have no experience with long (more than 15cm) SPI lines.
You write in your mail, that your SPI line is overall appr. 35 cm.

In past I had some problem with a CF-Card with a 40cm line between AVR and card. Of course CF-Card do not communicate with SPI. But it seemed, that the CF-Card is detecting on the RD line more pulses, than the AVR is sending. I assume, there was some kind of oszillating.
May be you have a similar problem. If possible, try to keep the SPI-lines shorter.

_________________
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
Wattsy

Bascom Member



Joined: 21 Nov 2005
Posts: 102
Location: Finistere (on the beach)

france.gif
PostPosted: Tue Mar 21, 2006 9:21 am    Post subject: Reply with quote

Many thanks Josef,
I am EXTREMELY grateful for any and all help and appreciate your time is precious. I have shortenned the SPI lines to a few cm now and will get back to you in due course - a couple of days. Trust your business trip goes well. Again MANY thanks.

_________________
and there it was... gone !

Bascom Full Version 2.0.8.1
STK300 IDE
Back to top
View user's profile
nicolasronan

Bascom Member



Joined: 10 May 2007
Posts: 2

france.gif
PostPosted: Thu May 10, 2007 8:35 pm    Post subject: Reply with quote

bonjour wattsy

je viens de découvrir tes messages,
je suis aussi dans le finistère, et je souhaiterai te demander des conseils sur ton expérience avec les SD Card.

merci
nicolasronan@free.fr
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