Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

AvrDos -> SD newby problem

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

Bascom Member



Joined: 14 Nov 2005
Posts: 5

italy.gif
PostPosted: Tue Nov 15, 2005 12:09 am    Post subject: AvrDos -> SD newby problem Reply with quote

Hi Josef,
I'm trying to use Your AvrDos with M128L and SD card to construct a simple datalogger.

.................... confusion Sad(

How i make for write the text "ABCD" in the file XYZ.TXT in the SD card ?

---------------------------------
Dim Txt As String * 4
Txt = "ABCD"
Open Xyz.txt For Append #1
Print Txt
Close #1
---------------------------------

What other needs ?

Sorry, but more I read the forum and more the confusion increases.

Best Regards
Stefano
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Thu Nov 17, 2005 2:56 pm    Post subject: Reply with quote

Hi Stefano,

First you need to tell BASCOM which mass storage device you want to use.
For MMC or SD you have to include the file Config_MMC.bas
Code:
$Include "Config_MMC.bas"

This file makes 3 Point:

    o Settings for Hardware Pin Wiring
    o Linking the driver library
    o Calls the init-routine for the MMC/SD Card

Check the comments in this file. If you use standard HW-SPI on the Mega128 (SS on PortB.0) you have nothing to change. If you use another Chip-Select you have to change the part in the Section for HW-SPI.
If you want to use other pins than them from the HW-SPI, you have to configure for SOFT-SPI and adapt the settings in the Part Section for Soft-SPI

The result of the Init-Routine is stored in the Byte-Variable gbDriveError
If the Init-Routine is successfully with the MMC/SD card it write a 0 to this variable, all other values indicates an error.
Code:
IF gbDriveError <> 0 then
   print "Card Error " ; gbDriveError
   ' Insert here your Error Handler
END IF


For use of AVR-DOS you have to include Config_AVR-DOS.bas
Code:
$Include "Config_AVR-DOS.bas"

This File DIMs all used variables for AVR-DOS und defines some constants.
Additional you can configure following points in this file:
o Count of file handles
o separate buffer for FAT
o Kind of updating FAT and Directory sector
o surrounding of texts writing to card with quotation-mark
Please check the comments in this file, how to configure it is written there.

Next you have to Init the File system in your application.
Code:
Dim bTemp1 as Byte
bTemp1 = InitFileSystem(1)


This routine reads the file system information (FAT-Type, Size and so on) from the card and initializes the AVR-DOS internal variables.
If this routine is successfully, it return a 0. Please check this result too.
Code:
IF bTemp1 <> 0 then
   print "File System Error " ; bTemp1
   ' Insert here your Error Handler
END IF


Now you can start with your logging part.

Code:
Dim Txt As String * 4
Txt = "ABCD"
Open "Xyz.txt" For Append As #10
Print #10, Txt
Close #10


Don't use numbers for the file-handle, which can conflict with the numbers for OPEN COM. Numbers greater or equal 10 will be a good choice.

Each AVR-DOS function fill the variable gbDOSError with the success-status. If this variable contains a 0, the function was finished successfully, all other values indicates an error. Check this variable gbDOSError at certain points of your program.

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

Bascom Member



Joined: 14 Nov 2005
Posts: 5

italy.gif
PostPosted: Fri Nov 18, 2005 8:20 pm    Post subject: Reply with quote

Hi Josef,
thanks for the clear answer.

I have tried to follow your instructions, but the compiler evidences me an error: 31 Invalid datatype(0)

This evening I will try with more attention.



One question, why in the Config_MMC.bas you config the pinb.0 twice?

--------------------------------------------------------------------------------------
' define Chip-Select Pin
Config Pinb.0 = Output ' define here Pin for CS of MMC/SD Card
--> Mmc_cs Alias Portb.0
Set Mmc_cs

' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
Config Pinb.0 = Output ' define here Pin of SPI SS
--> Spi_ss Alias Portb.0
Set Spi_ss ' Set SPI-SS to Output and High por Proper..
--------------------------------------------------------------------------------------

Best regards
Stefano
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Fri Nov 18, 2005 9:08 pm    Post subject: Reply with quote

Hi,

To your question about PinB.0:

If you use another pin than the SPI-SS to select the MMC/SD Card, you have to make sure, that SPI-SS (PinB.0 on the M128) is configured in OUTPUT direction. If this Pin works as Input-Pin and forced to LOW, than the HW-SPI changes to SLAVE mode (described in the ATMEL Datasheet) and this will disturbe the SPI communication.
That's the reason I inserted a part, that this pin is configured for OUTPUT anyway.

Compiler-Error: Please show your code and the line which the compiler complains.

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

Bascom Member



Joined: 14 Nov 2005
Posts: 5

italy.gif
PostPosted: Fri Nov 18, 2005 10:24 pm    Post subject: Reply with quote

Hi Josef,
here the code.
The compiler indicates the error in correspondence of the command "End"

---------------------------------------------------------------------------------
$crystal = 7372800
$regfile = "m128def.dat"

Config Lcdpin = Pin , E = Portd.1 , Rs = Portd.5 , Db4 = Porte.7 , Db5 = Porte.5 , Db6 = Porte.3 , Db7 = Porte.1
Config Lcd = 20 * 4 'configure lcd screen
Cursor Off Noblink
Cls

Dim Txt As String * 4
Dim Btemp1 As Byte 'Init File System on SD card

$Include "Config_MMC.bas"
If Gbdriveerror <> 0 Then 'The result of the Init-Routine is stored in the Byte-Variable gbDriveError
Print "Card Error " ; Gbdriveerror
End
' Insert here your Error Handler
End If


$Include "Config_AVR-DOS.bas"
Btemp1 = Initfilesystem(1)
If Btemp1 <> 0 Then
Print "File System Error " ; Btemp1
End 'fine programma inutile proseguire
' Insert here your Error Handler
End If

Txt = "ABCD"

Open "Xyz.txt" For Append As #10 ' Numbers greater or equal 10 will be a good choice.
Print #10 , Txt
Close #10

End
--------------------------------------------------------------------------------

Best regards
stefano
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Sat Nov 19, 2005 5:06 pm    Post subject: End... Reply with quote

Stefano

Is it possible to use only one End-statement and have all END's do a jump to the label quit (goto quit)

quit:
end

Could you tell us what the result is?

Bye
Ben Zijlstra
Back to top
View user's profile Visit poster's website
stefano

Bascom Member



Joined: 14 Nov 2005
Posts: 5

italy.gif
PostPosted: Sat Nov 19, 2005 6:19 pm    Post subject: Reply with quote

Hi Josef,
adding the label jump the result not change.
I have tested the program on the M128 and in the SD(1Gb) I have found the file xyz.txt but without data inside.

thanks for the demonstrated patience

stefano
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Sun Nov 20, 2005 11:06 am    Post subject: Reply with quote

Hi Stefano,

At writing data to the card, AVR-DOS uses the date and time values of the clock for the directory information (Update time and create time in the directory)

Please insert the line
Code:
Config Cock = Soft
somewhere at the beginning of the program.
It will insert the six byte variable _sec, _min, _hour, _day, _month, _year which are used from AVR-DOS to write date/time information to the directory entry.
If the compiler miss these variables, it will complain it with your mentioned Error message (unfortunately not very useful).

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

Bascom Member



Joined: 14 Nov 2005
Posts: 5

italy.gif
PostPosted: Sun Nov 20, 2005 2:18 pm    Post subject: Reply with quote

Hi Josef,
with the command "Config clock = Soft" the program don't run,
but manually configure the variable:
Dim _day As Byte
Dim _month As Byte
Dim _year As Byte
Dim _sec As Byte
Dim _hour As Byte
Dim _min As Byte

it's work fine Very Happy Very Happy Very Happy Very Happy

Big thanks
Stefano
Back to top
View user's profile
oe9vfj

Moderator



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

austria.gif
PostPosted: Mon Nov 21, 2005 9:04 am    Post subject: Reply with quote

Hi,

Please use following order for DIM the time/date variables.
Code:
Dim _Sec as Byte, _Min as Byte, _Hour as Byte, _Day as Byte, _Month as Byte, _Year as Byte

Than you can use Date and time function of BASCOM-AVR too in proper 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
kero

Bascom Member



Joined: 06 Mar 2009
Posts: 1

blank.gif
PostPosted: Fri Mar 06, 2009 9:45 am    Post subject: MMC+Atmega32 Reply with quote

hello..

can anyone help me?Ii want to make a data logger with mmc as storage divice. I am using Atmega32 and external DS1302 RTC, i want to log the data of rotary encoder.I want to simplified taken mmc from data logger and reading it on commercial card reader to read the data using Windows operating system. the data is on csv format. I am newbe on programming. I use a basic language and Bascom Avr compiler. can anyone give me the working code? i am confusing reading on this forum.

regard

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