Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Comunication Atmega32 with SD card

Status
Not open for further replies.

bolek

Newbie level 3
Joined
Oct 27, 2010
Messages
3
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,298
Hello.

J have problem with write file *.txt on card sd. I use avr dos. My program write only about 17kB, one cluster and stop run. I don't know why ?
 

Post your code, then only we can find out the problem
 

My code.

Code:
$regfile = "m32def.dat"
$crystal = 8000000
$hwstack = 128
$swstack = 128
$framesize = 128
$baud = 9600
$include "Config_MMC.bas"
$include "Config_AVR-DOS.BAS"


Declare Sub Srednik

Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pinb.2 = Input
Config Pinb.3 = Input
Config Porta.0 = Output
Config Porta.1 = Output
Config Porta.2 = Output
Config 1wire = Portd.7
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5
Config Lcd = 20 * 4
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Disconnect , Prescale = 1
Config Clock = Soft , Gosub = Sectic
Config Date = Dmy , Separator = /


Dim Temp1_lcd As String * 6
Dim Temp2_lcd As String * 6
Dim Tempmin_lcd As String * 6
Dim Tempmax_lcd As String * 6
Dim Tempminsd_lcd As String * 6
Dim Tempmaxsd_lcd As String * 6
Dim Tempamplituda_lcd As String * 6
Dim Srednia_lcd As String * 6
Dim Data_sd As String * 8
Dim Flaga_zapisz As Bit
Dim Flaga_zapisz_sr As Bit
Dim Flaga_menu As Bit
Dim Flaga_1w As Bit
Dim Blad_sd As Bit
Dim Interwal As Byte
Dim Dsid1(8) As Byte
Dim Dsid2(8) As Byte
Dim Czujnik As Byte
Dim Errorcode As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Tempmin As Integer
Dim Tempmax As Integer
Dim Tempminsd As Integer
Dim Tempmaxsd As Integer
Dim Tempamplituda As Integer
Dim Czas As Integer
Dim Srednia As Long
Dim Srednia_p As Long


Deflcdchar 1 , 12 , 18 , 18 , 12 , 32 , 32 , 32 , 32        ' Stopnie
Deflcdchar 2 , 32 , 7 , 15 , 31 , 31 , 31 , 31 , 31
Deflcdchar 3 , 32 , 4 , 4 , 4 , 4 , 21 , 14 , 4             ' replace ? with number (0-7)
Deflcdchar 4 , 4 , 14 , 21 , 4 , 4 , 4 , 4 , 32             ' replace ? with number (0-7)
S1 Alias Pinb.0
S2 Alias Pinb.1
S3 Alias Pinb.2
S4 Alias Pinb.3
Led1 Alias Porta.0
Led2 Alias Porta.1
Led3 Alias Porta.2

Set Porta.0
Set Porta.1
Set Porta.2
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3

Time$ = "06:00:01"
Date$ = "01.01.10"
Flaga_zapisz = 0
Tempmin = 1000
Tempmax = -1000
Interwal = 3

Dsid2(1) = 1wsearchfirst()
Dsid1(1) = 1wsearchnext()
Interwal = 1
Cursor Off
Cls
Enable Interrupts
Wait 4
Pwm1a = 50
Do
If S4 = 0 Then
   Waitms 25
      If S4 = 0 Then
         Flaga_menu = 1
         Cls
            Locate 1 , 8
            Lcd "Czas    "
            Wait 2
            Do
            Locate 3 , 6
            Lcd Time$
            Waitms 500
            If S2 = 0 Then
               Waitms 25
                  If S2 = 0 Then
                     _sec = 0
                     Czas = 0
                     Srednia = 0
                     Incr _min
                     If _min = 60 Then
                        _min = 0
                     End If
                  End If
            End If
            If S3 = 0 Then
               Waitms 25
                  If S3 = 0 Then
                     _sec = 0
                     Czas = 0
                     Srednia = 0
                     Incr _hour
                     If _hour = 24 Then
                        _hour = 0
                     End If
                  End If
            End If
            Loop Until S4 = 0
            Cls
            Locate 1 , 8
            Lcd "DATA    "
            Wait 3
            Do
            Locate 3 , 6
            Lcd Date$
            Waitms 500
            If S3 = 0 Then
               Waitms 25
                  If S3 = 0 Then
                     Incr _day
                     If _day = 31 Then
                        _day = 0
                     End If
                  End If
            End If
            If S2 = 0 Then
               Waitms 25
                  If S2 = 0 Then
                     Incr _month
                     If _month = 12 Then
                        _month = 12
                     End If
                  End If
            End If
            If S1 = 0 Then
               Waitms 25
                  If S1 = 0 Then
                     Incr _year
                     If _year = 20 Then
                        _year = 10
                     End If
                  End If
            End If

            Loop Until S4 = 0
            Cls
            Locate 1 , 6
            Lcd "INTERWAL"
            Wait 2
            Do
            If S3 = 0 Then
               Waitms 25
                  If S3 = 0 Then
                     Incr Interwal
                     If Interwal = 4 Then
                        Interwal = 1
                     End If
                  End If
            End If
            If S2 = 0 Then
               Waitms 25
                  If S2 = 0 Then
                     Decr Interwal
                     If Interwal = 0 Then
                        Interwal = 3
                     End If
                  End If
            End If
            Locate 3 , 1
            Select Case Interwal
               Case 1 : Lcd "1 sekunda    "
               Case 2 : Lcd "1 minuta     "
               Case 3 : Lcd "10 minut     "
            End Select
            Waitms 500
            Loop Until S4 = 0

            Locate 1 , 6
            Lcd "EXIT MENU"
            If Tempmax = 850 Then
               Tempmax = -1000
            End If
            Waitms 600
            Srednia_p = 0
            Srednia = 0
            Czas = 0
            Flaga_menu = 0
            Cls
         End If
   End If
   If Flaga_zapisz = 1 Then
      If Flaga_menu = 0 Then
         Gbdriveerror = Driveinit()
            If Gbdriveerror = 0 Then
               Errorcode = Initfilesystem(1)
               If Errorcode <> 0 Then
                  Blad_sd = 1
                  Else
                  Led2 = 0
                  Waitms 5
                  Led2 = 1
                  Open "temper.txt" For Append As #2
                  Write #2 , Date$ , Time$ , Temp1_lcd , Temp2_lcd
                  Flush #2
                  Close #2
                  Led3 = 0
                  Waitms 5
                  Led3 = 1
                  If Flaga_zapisz_sr = 1 Then
                     Waitms 50
                     Led2 = 0
                     Waitms 5
                     Led2 = 1
                     Open "avg.txt" For Append As #1
                     Write #1 , Data_sd , Tempminsd_lcd , Tempmaxsd_lcd , Tempamplituda_lcd , Srednia_lcd
                     Flush #1
                     Close #1
                     Led3 = 0
                     Waitms 5
                     Led3 = 1
                     Flaga_zapisz_sr = 0
                  End If
                  Flaga_zapisz = 0
                  Select Case Interwal

                  Case 1:
                           Waitms 1
                  Case 2:
                           Wait 2

                  Case 3:
                           Wait 2

                  End Select
               End If
            Else
            Locate 2 , 1
            Lcd "blad"
            End If
      End If
   End If
Loop


Sectic:

         Led1 = 0
         Czujnik = 1wirecount()
         1wreset
         1wwrite &H55
         1wverify Dsid1(1)
         1wwrite &HBE
         Temp1 = 1wread(2)
         1wreset
         1wwrite &H55
         1wverify Dsid2(1)
         1wwrite &HBE
         Temp2 = 1wread(2)
         1wreset
         1wwrite &HCC
         1wwrite &H44
         Temp1 = Temp1 * 10
         Temp1 = Temp1 \ 16
         Temp2 = Temp2 * 10
         Temp2 = Temp2 \ 16
         If Temp1 < Tempmin Then
            Tempmin = Temp1
            Tempminsd = Temp1
         End If
         If Temp1 > Tempmax Then
            Tempmax = Temp1
            Tempmaxsd = Temp1
         End If
         Tempamplituda = Tempmaxsd - Tempminsd
         Temp1_lcd = Str(temp1)
         Temp1_lcd = Format(temp1_lcd , "0.0")
         Temp2_lcd = Str(temp2)
         Temp2_lcd = Format(temp2_lcd , "0.0")
         Tempmin_lcd = Str(tempmin)
         Tempmin_lcd = Format(tempmin_lcd , "0.0")
         Tempmax_lcd = Str(tempmax)
         Tempmax_lcd = Format(tempmax_lcd , "0.0")
         Tempminsd_lcd = Str(tempminsd)
         Tempminsd_lcd = Format(tempminsd_lcd , "0.0")
         Tempmaxsd_lcd = Str(tempmaxsd)
         Tempmaxsd_lcd = Format(tempmaxsd_lcd , "0.0")
         Tempamplituda_lcd = Str(tempamplituda)
         Tempamplituda_lcd = Format(tempamplituda_lcd , "0.0")

         If S1 = 0 Then
            Tempmin = 1000
            Tempmax = -1000
         End If
         Led1 = 1
         Gosub Srednik


         Select Case Interwal

         Case 1:
                  Flaga_zapisz = 1
         Case 2:
                  If _sec = 0 Then
                     Flaga_zapisz = 1
                  End If
         Case 3:
                  If _min = 0 Or _min = 10 Or _min = 20 Or _min = 30 Or _min = 40 Or _min = 50 Then
                     If _sec = 0 Then
                     Flaga_zapisz = 1
                     End If
                  End If
         End Select
         If Flaga_menu = 0 Then
         Locate 1 , 1
         Lcd Time$ ; "   "
         Locate 1 , 12
         Lcd Date$
         Locate 2 , 1
         Lcd "Out:" ; Temp1_lcd ; Chr(1) ; "C " ; "Avg:" ; Srednia_lcd ; Chr(1) ; "C "
         Locate 3 , 1
         Lcd "In :" ; Temp2_lcd ; Chr(1) ; "C  "
         Locate 4 , 1
         Lcd Chr(3) ; ":" ; Tempmin_lcd ; Chr(1) ; "C  "
         Locate 4 , 11
         Lcd Chr(4) ; ":" ; Tempmax_lcd ; Chr(1) ; "C  "
         End If
Return

Srednik:


         If _sec = 0 And _min = 59 And _hour = 23 Then
            Data_sd = Date$
         End If
         If _sec = 0 Then
            Incr Czas
            Srednia_p = Srednia_p + Temp1
            Srednia = Srednia_p / Czas
            Srednia_lcd = Str(srednia)
            Srednia_lcd = Format(srednia_lcd , "0.0")
         End If
         If _sec = 0 And _min = 0 And _hour = 0 Then
            Flaga_zapisz_sr = 1
            Srednia_p = 0
            Srednia = 0
            Czas = 0
            Tempminsd = 1000
            Tempmaxsd = -1000
            Tempamplituda = 0
         End If
Return


---------- Post added at 09:07 ---------- Previous post was at 09:01 ----------

and congig mmc

Code:
 '-------------------------------------------------------------------------------
'                         Config_MMC.BAS
'               Config File for MMC Flash Cards Driver
'        (c) 2003-2005 , MCS Electronics / Vögel Franz Josef
'-------------------------------------------------------------------------------
' Place MMC.LIB version 5.6 in the LIB-Path of BASCOM-AVR installation
'
'Connection as following
'MMC    M128/M103           M32
'1      MMC_CS PORTB.0      MMC_CS PORTB.4
'2      MOSI PORTB.2        MOSI PORTB.5
'3      GND                 GND
'4      +3.3V               +3.3V
'5      CLOCK PORTB.1       CLOCK PORTB.7
'6      GND                 GND
'7      MISO, PORTB.3       MISO, PORTB.6

' 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 here you SPI-Mode
' using HW-SPI:     cMMC_Soft = 0
' not using HW_SPI: cMMC_Soft = 1

Const Cmmc_soft = 0

#if Cmmc_soft = 0

' --------- Start of Section for HW-SPI ----------------------------------------


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

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

   ' 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 default = commented changed by author
   Spiinit                                                  ' Init SPI

' --------- End of Section for HW-SPI ------------------------------------------

#else                                                       ' Config here SPI pins, if not using HW SPI

' --------- Start of Section for Soft-SPI --------------------------------------

   ' Chip Select Pin  => Pin 1 of MMC/SD
   Config Pinb.4 = Output
   Mmc_cs Alias Portb.4
   Set Mmc_cs

   ' MOSI - Pin DI => Pin 2 of MMC/SD
   Config Pinb.5 = Output
   Set Pinb.5
   Mmc_portmosi Alias Portb
   Bmmc_mosi Alias 2

   ' MISO - Pin  D0 => Pin 7 of MMC/SD
   Config Pinb.6 = Input
   Mmc_portmiso Alias Pinb
   Bmmc_miso Alias 3

   ' SCK - Pin CLK  => Pin 1 of MMC/SD
   Config Pinb.1 = Output
   Set Pinb.7
   Mmc_portsck Alias Portb
   Bmmc_sck Alias 1

' --------- End of Section for Soft-SPI ----------------------------------------

#endif

' ========== End of user definable range =======================================


' Error
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
$lib "MMC.LIB"                                              ' link driver library
$external _mmc
Gbdriveerror = Driveinit()                                  ' Init MMC/SD Card
 
Yes Tahmid you have right it's BASCOM AVR
 

can somebody help me writing a .txt file in sd card with avr.???:sad:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top