Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SD card hardware SPI problems

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

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Mon Aug 12, 2019 8:41 pm    Post subject: SD card hardware SPI problems Reply with quote

Several years ago I used the AVR-DOS SD card routines for implementing SD card data logging in an instrument using hardware SPI (ATMega2560). Worked great, still works.
However, I can no longer get the old code to work (now using BASCOM 2.0.8.0). Software SPI works, but not hardware SPI.

Here is excerpt from original code (Config_MMCSD_HC.BAS) that worked:

Code:

Const Cmmc_soft = 0

#if Cmmc_soft = 0

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

   ' 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 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 = 0
'   Spsr = 1                                     ' Double speed on ATMega128
   Spiinit


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

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



If I compile this, I get an error in the Config SPI=Hard... line.
After removing "Master=Yes", I can compile it without error, however, the program freezes at the SD initialization and never continues.

Any help is appreciated !!!

[/u]
Back to top
View user's profile AIM Address
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1197
Location: France

france.gif
PostPosted: Tue Aug 13, 2019 4:02 pm    Post subject: Reply with quote

hi
I have a lot of pb with AVRDOS but now I use my own (from the original) config prog I give you it in file addess I hope it will help you
JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
jeremywilson

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Tue Aug 13, 2019 8:49 pm    Post subject: Reply with quote

Thank you. I'll give it a try.
Back to top
View user's profile AIM Address
jeremywilson

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Tue Aug 13, 2019 11:08 pm    Post subject: Reply with quote

JP:
I have the same problem with your code. Compiler returns "Invalid Parameter" on the Config SPI... line.
Removing "Master=YES" eliminates the error, but program freezes at SD initialization.
Back to top
View user's profile AIM Address
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Wed Aug 14, 2019 7:21 am    Post subject: Reply with quote

Why dont you use newest 2082?
Like picture shows, your code compiles fine, without errors.
Mabe your Bascom have some problem with license Very Happy
Back to top
View user's profile Visit poster's website
jeremywilson

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Wed Aug 14, 2019 4:40 pm    Post subject: Reply with quote

same result on 2082, two different computers.

frustrating!!!!
Back to top
View user's profile AIM Address
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1197
Location: France

france.gif
PostPosted: Wed Aug 14, 2019 6:14 pm    Post subject: Reply with quote

tomorrow i will send you a short program working now it is 19h00 pm i'm tired
but before try to use the help prog
jp
Rolling Eyes

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6197
Location: Holland

blank.gif
PostPosted: Wed Aug 14, 2019 6:35 pm    Post subject: Reply with quote

we can all send working code but the TS should post his code that does not work. Not just some fragment that means nothing without context. But the smallest part that does not work.
_________________
Mark
Back to top
View user's profile Visit poster's website
jeremywilson

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Wed Aug 14, 2019 9:11 pm    Post subject: Reply with quote

Files attached.

"S1012-100P2 A1300 PI3.BAS" is the main program


when I compile, I get:

Error : 127 Line : 51 Invalid parameter [1] , in File : M1046-101 MMCSD_HC.BAS

with this line highlighted:

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 0
Back to top
View user's profile AIM Address
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1571
Location: Basel, Switzerland

switzerland.gif
PostPosted: Wed Aug 14, 2019 9:25 pm    Post subject: Reply with quote

Hi,

Looking in you code your defining a constant "YES" and YES is also used in the CONFIG SPI command.

Deleting the Definition from "M1010-101 Constants.bas" the code compiles.

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
jeremywilson

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Wed Aug 14, 2019 9:28 pm    Post subject: Reply with quote

Wow!!! I never would have found that!

Thanks!!
Back to top
View user's profile AIM Address
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1571
Location: Basel, Switzerland

switzerland.gif
PostPosted: Wed Aug 14, 2019 9:42 pm    Post subject: Reply with quote

Hi,

Glad to be of Service.

I've seen afew other things in you Software that I'm not sure if they'll work the way you think, I'll look at the code again when I've had a sleep.

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6197
Location: Holland

blank.gif
PostPosted: Wed Aug 14, 2019 9:51 pm    Post subject: Reply with quote

I removed the attachment because i am not sure you want to share it with the whole world. When not ok, just post it again.

Great find of Ian indeed !

There are some issues with your code.
One of them : Sensor_ua_raw = Sensor_volts / Gain(gain1_idx , Gain2_idx) 'sensor current
this will not work since gain is not an array. I will check that since in this case you should get an error. The IDE indicates as an error, but the compiler should give one too.

there are others but you do not call that code so no problem yet.

_________________
Mark
Back to top
View user's profile Visit poster's website
jeremywilson

Bascom Member



Joined: 11 Jul 2011
Posts: 79
Location: United States

usa.gif
PostPosted: Wed Aug 14, 2019 10:20 pm    Post subject: Reply with quote

Thanks for the attachment removal.

The software is a work-in-progress based on my existing analyzer software that has a single gain amp, where Gain(gain_idx) is an array of gains. In this new analyzer, there are two digitally-controlled amps, so I just stuck that Gain2_idx in there to remind me to take it into account when I get there. But you're correct - Gain(gain1_idx,gain2_idx) looks like a function call or 2-dimensional array ! Will change soon.
Currently working on the touchscreen interface, so the software is just sending temperature, pressure, time & date to the display. Alarm relays, analog outputs, SD card, Modbus, valve and pump drivers are all functional.
Back to top
View user's profile AIM Address
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