View previous topic :: View next topic |
Author |
Message |
user234
Joined: 25 May 2005 Posts: 5
|
Posted: Wed May 25, 2005 2:19 pm Post subject: MMC wiring - AVR DOS |
|
|
Hello,
I want to use a MMC card on a M128 for data logging. Two questions:
1. I have understood that 5V->3,3V voltage conversion problem and have designed it with voltage dividing resistors. But which pins do I use on the M128 side? The hardware MISO/MOSI/CLK-Pins, which are the same where I have my ISP adapter connected to? Or can I use some different pins?
2. I have Bascom 11.7.7. running which comes with some libraries "AVR-DOS / MMC-flashcard.bas, mmc.lbx, mmc.lib ... etc". How do I combine all these to a simple application like OPEN"TEXTFILE.CSV" ... ?
Thanks in advance for answering.
Greets, Hannes |
|
Back to top |
|
|
philm
Joined: 14 Jul 2004 Posts: 138 Location: Australia
|
Posted: Thu May 26, 2005 12:38 am Post subject: |
|
|
Yes and no is the answer.
Quote: | But which pins do I use on the M128 side? The hardware MISO/MOSI/CLK-Pins | Yes
Quote: | which are the same where I have my ISP adapter connected to? | They are not the same pins on a M128. They are on other chips, but not the M128.
This was taled about in this thread http://mcselec.com/forum/viewtopic.php?t=653
Phil |
|
Back to top |
|
|
user234
Joined: 25 May 2005 Posts: 5
|
Posted: Fri May 27, 2005 7:36 am Post subject: |
|
|
Hi Phil,
Thanks for your answer. I am working with a Crisp-module with the programming adapter fine. Now I understand that this adapter does not work with the MOSI/MISO pins and I have to use the MOSI/MISO on the outer side of the module (directly connected to pins on the chip)
Now what about the software-implementation? I don't really understand how to combine the different AVR-DOS-parts LIB / LBX / BAS. Can anyone help me in this matter?
Greets
HNS |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Fri May 27, 2005 11:38 am Post subject: |
|
|
Hi,
here is a short example of reading a file from a MMC-Card and send it to RS232.
First you have to $Include the File "Config_MMC.BAS".
In this file you have your hardware-setting for the card.
This file also call the Init-Routine of the Card and write the result into the byte-variable gbDriveError. Check this variable for a successfully initialising of the Card (0 is no error, values > 0 is error).
Next you have to $Include "Config_AVR-DOS.BAS". This file DIMs all variables and define all constants for AVR-DOS. In the Head-part of the file you can make some configurations like count of file-handles, handling of FAT and directory-buffers and kind of FAT/Directory sectors writing.
With the statement InitFileSytstem() you have to read in the file-system from the card, so AVR-DOS knows the parameters of the partition like location and size of the partition and so on.
Here and after all AVR-DOS commands you have to check the variable gbDOSError of success of the function (0 is no error, > 0 is error, see error-code table in Help-File).
The syntax of the AVR-DOS commands is compatible to QB/BASIC/VB.
Code: |
$regfile = "M128def.dat"
$crystal = 16000000
' Adjust HW Stack, Soft-Stack and Frame size to 128 minimum each!!!
$Baud = 9600
Open "Com1:" As Binary As #1
Config Clock = Soft
Enable Interrupts
Config Date = Mdy , Separator = /
Dim bTemp1 As Byte
Print #1 , "Init MMC/SD Drive"
$Include "Config_MMC.bas" ' Does drive init too
If gbDriveError = 0 Then ' gbDriveError is Dim in Config_MMC.bas
$Include "Config_AVR-DOS.BAS"
Print #1 , "Init File System ... ";
bTemp1 = Initfilesystem(1) ' Partition 1
If bTemp1 <> 0 Then
Print #1 , "Error: " ; bTemp1 ; " at Init file system"
Else
Dim str1 as String * 20
Open "File.txt" for Input as #10
If gbDOSError = 0 then
While eof(10) = 0
Line Input #10, str1
Print #1, str1
Wend
Close #10
else
Print #1, "Can not open File; Error: " ; gbDOSError ' gbDOSError is Dim in Config_AVR-DOS.bas
End if
Close #10
End If
Else
Print #1 , "Error during Drive Init: " ; Gbdriveerror
End If
end
|
You can read and write ASCII and Binary Files with all types of variables implemented in BASCOM-AVR.
The description of all statements is in the BASCOM-AVR-Help.
Check also in Help: ASM-Libraries/AVR-DOS _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
user234
Joined: 25 May 2005 Posts: 5
|
Posted: Fri May 27, 2005 2:51 pm Post subject: |
|
|
Hi Josef,
thanks a lot for this short and comprehensive answer. |
|
Back to top |
|
|
user234
Joined: 25 May 2005 Posts: 5
|
Posted: Sat Jun 04, 2005 7:20 pm Post subject: |
|
|
I get the Drive Error 225 "Error Drive Reset"
Where shall I start to search for errors in my hardware layout?
Thanks + Greetings
HNS |
|
Back to top |
|
|
user234
Joined: 25 May 2005 Posts: 5
|
Posted: Sat Jun 04, 2005 8:25 pm Post subject: |
|
|
Now it works, after I changed the brand of MMC card to a noname SD-card.
So the hardware layout wasn't too bad at all.
Now my problem is, that the EOF seems to be reached to early. I cant receive the last few chars from a file. I am using the above printed example for file open + serial out (i changed it to LCD out, because I do not have serial output)
Whats the deal with the EOF. How does that LINE INPUT command work, how can I read single bytes out of files. I tried setting the sting length of STR1 to 1 but then I get only the first char out of the file. |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Sun Jun 05, 2005 8:18 am Post subject: |
|
|
Hi,
Line Input reads from the file as long as the line is or the string is dimmed.
If the line is 10 bytes long and the string is 20, then 10 bytes are read.
If the line is 30 bytes long and the string is 20, then 20 bytes are read.
If the String is shorter then the line, the string is filled with its length and the file pointer skips to the end of the line, so your next line input command start from the next line.
This behaviour is compatible to QB/VB.
If you want to read in the whole line, you have to DIM your string to the length of the longest line.
If you want to read in the file byte by byte, you have to open the File in BINARY mode and use the statement GET. In this mode you get every byte as is from the file even the Line terminator (Carriage Return &H0D and Line Feed &H0A), so you have to check for end of the line by your self. _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
|