View previous topic :: View next topic |
Author |
Message |
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Mon Aug 12, 2019 8:41 pm Post subject: SD card hardware SPI problems |
|
|
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 |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Aug 13, 2019 4:02 pm Post subject: |
|
|
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 _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Tue Aug 13, 2019 8:49 pm Post subject: |
|
|
Thank you. I'll give it a try. |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Tue Aug 13, 2019 11:08 pm Post subject: |
|
|
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 |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Aug 14, 2019 7:21 am Post subject: |
|
|
Why dont you use newest 2082?
Like picture shows, your code compiles fine, without errors.
Mabe your Bascom have some problem with license
|
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Wed Aug 14, 2019 4:40 pm Post subject: |
|
|
same result on 2082, two different computers.
frustrating!!!! |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Aug 14, 2019 6:14 pm Post subject: |
|
|
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
_________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Aug 14, 2019 6:35 pm Post subject: |
|
|
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 |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Wed Aug 14, 2019 9:11 pm Post subject: |
|
|
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 |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Wed Aug 14, 2019 9:25 pm Post subject: |
|
|
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 |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Wed Aug 14, 2019 9:28 pm Post subject: |
|
|
Wow!!! I never would have found that!
Thanks!! |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Wed Aug 14, 2019 9:42 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Aug 14, 2019 9:51 pm Post subject: |
|
|
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 |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Wed Aug 14, 2019 10:20 pm Post subject: |
|
|
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 |
|
|
|