SD Write compile error

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

SD Write compile error

Post by Francis » Fri Jun 22, 2007 3:56 pm

I was trying to compile my code and its come up with an apparent error at the assemble stage.

My bit of test code is:-

Code: Select all

      If ErrFlag = 0 Then                   ' OK to write
          RecordLength = SerialBuffer         
          For I = 2 To RecordLength
             SD.Write(SData(I))           '  << WRITE
          Next
          If AutoFileSave=BTrue Then        ' Has auto save been set?  
            SD.SaveFile()
          EndIf
      EndIf
When I click Compile, I get a red-box at the Assemble window section with "Errors Found" but assemble window comes and goes so quickly I can't tell you what else it says.

Then it highlights (in orange) a line in the SD FIle system file.

Code: Select all

}   
Sub WriteSectorByte(pByte As Byte)
   If File.CurrentSectorPos = $200 Then   ' << ORANGE HIGHLIGHT
      File.CurrentSectorPos = $000
   EndIf
   File.CurrentSectorBuffer(File.CurrentSectorPos) = pByte
   If File.CurrentSectorPos = $1FF Then
      WriteSector(File.CurrentSector)
      Inc(File.CurrentSector)
   EndIf
   Inc(File.CurrentSectorPos)
End Sub
Though the Hint just says that CurrentSectorPos might not have been initialised.

However, if I stick in another byte in my code then all is well.
E.G.

Code: Select all

SD.Write(SData(I),10)  ' Compiles OK with extra byte
Just adding a single byte makes it happy. Can't I write byte-at-a-time?

Note: The variable is just:
Dim SData(140) As Byte

I'd be very grateful if someone would point out where I've gone wrong please.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Jun 22, 2007 4:42 pm

Can you post a 'small as possible' program which will generate the error, which include all variable declarations and device used.

I am unable to create the same error here, but I'm having to make assumptions about some of your declarations, initialisation routines and device used.

Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Post by Francis » Fri Jun 22, 2007 5:57 pm

Thanks for being so quick David.

This, I hope, demonstrates the behaviour.
Un-comment line of choice for testing.

Code: Select all

// device and clock...
Device = 18F2520
Clock =  8

// import SD file system, usart and conversion modules...
#option SD_SPI = MSSP         // use hardware SPI
Include "SDFileSystem.bas"
Include "usart.bas"
Include "Convert.bas"
Include "String.bas"

// variables...
Dim Index As Byte
Dim SData(140) As Byte

Dim  I As Word


// program start...
SetBaudrate(br9600)
USART.Write("Initialising card...", 13, 10)   
If SD.Init(spiOscDiv64) Then

   // write data to SD card...
   USART.Write("Writing data, please wait...", 13, 10)
   If SD.NewFile("test.txt") = errOK Then
      For I = 0 To 100
         'sd.write(sdata(i),10)         ' << THIS WORKS
         'SD.Write(SData(I))             ' << THIS CAUSES ERROR
         'sd.write(Index)              ' << THIS CAUSES ERROR
         SD.Write(Index,Index)        ' << THIS WORKS
      Next
      SD.CloseFile
   EndIf

Else
  USART.Write("Initialising FAILED!", 13, 10)           
EndIf
Its based on one of the Sample programmes and cut about a bit.

The only difference in this quick example is that it orange-highlights the SD.Write(..) line , whereas in my other programme it orange-highlights the line in the SD FileSystem file.

Please note; all the File opening/closing dates/times work fine. And it just seems to go funny when writing a single byte.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Jun 22, 2007 6:11 pm

I cannot reproduce the error here using the above program. All I get is warning messages (orange) about SData and Index may not have been initialised (which is correct, as they have not been initialised). I'm not seeing any error (red) or assembler errors.

I think the best course of action is if you email me your full program (click on the email link below). I will also need you IDE and ICC version numbers, which are shown in HELP...ABOUT.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Fri Jun 22, 2007 7:50 pm

I am also getting an ASM error [116] - Address label duplicated or different in second pass (END_PROC_WRITEBYTE_1). The ASM around the error line has been sent to Dave.

Compiler version is Beta 2.0.0.5, ICC 1.1.5.1

Regards,

Steven

P.S. This is with the SD.Write(SData(I)) used for testing.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Fri Jun 22, 2007 8:08 pm

Test Code for benefit of Dave for duplication:

Code: Select all

{
****************************************************************
*  Name    : UNTITLED.BAS                                      *
*  Author  : [select VIEW...EDITOR OPTIONS]                    *
*  Notice  : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
*          : All Rights Reserved                               *
*  Date    : 22/06/2007                                        *
*  Version : 1.0                                               *
*  Notes   :                                                   *
*          :                                                   *
****************************************************************
}
// device and clock... 
Device = 18F2520 
Clock =  8 

// import SD file system, usart and conversion modules... 
#option SD_SPI = MSSP         // use hardware SPI 
Include "SDFileSystem.bas" 
Include "usart.bas" 
Include "Convert.bas" 
Include "String.bas" 

// variables... 
Dim Index As Byte 
Dim SData(140) As Byte 

Dim  I As Word 


// program start... 
SetBaudrate(br9600) 
USART.Write("Initialising card...", 13, 10)    
If SD.Init(spiOscDiv64) Then 

   // write data to SD card... 
   USART.Write("Writing data, please wait...", 13, 10) 
   If SD.NewFile("test.txt") = errOK Then 
      For I = 0 To 100 
         'sd.write(sdata(i),10)         ' << THIS WORKS 
          SD.Write(SData(I))             ' << THIS CAUSES ERROR 
         'sd.write(Index)              ' << THIS CAUSES ERROR 
         'SD.Write(Index,Index)        ' << THIS WORKS 
      Next 
      SD.CloseFile 
   EndIf 

Else 
  USART.Write("Initialising FAILED!", 13, 10)            
EndIf

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Jun 22, 2007 8:41 pm

I've spoken to Steven (Thanks for the code snippet) and I can now see the error here. Steven has pointed out that if you reverse the includes, from

Code: Select all

include "SDFileSystem.bas"
include "usart.bas"
to

Code: Select all

include "usart.bas"
include "SDFileSystem.bas"
You won't get the ASM error message. This is why I could not reproduce the error earlier. The 'orange' warnings (given the code snippet) are correct.

Clearly there is a problem, which I will work on next week. I'll delay the online update until it is fixed.

Francis
As a temporary workaround, follow Stevens suggestion and try reversing the include order. That is, 'usart.bas' before 'SDFileSystem.bas'. If you still receive errors in your full program and you feel these are not correct, please email me your full program (I will treat in confidence) so I can investigate further.

Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Post by Francis » Fri Jun 22, 2007 10:19 pm

Many thanks to both of you.

Changing the order has sorted it.

I very much appreciate it.

Post Reply