code strangely looping around and around

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guy,
I have attached a complete program. It should connect to an sd card, and read an unsigned 8-bit mono.wav file from it then play it out of OCR0A. It used to do just that. I cant for the life of me work out whats going on, but firstly when I connect to the serial port that it should be printf-ing out of, it just repeats the first line it is supposed to print for ever, without moving on:

Quote:

printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]
printing floats: 14.22, 3[00]

not even finishing printing the line, and never tries to connect to the sd card, and play the track.
Has anyone experienced anything like this before?

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

printf clobbering the stack perhaps ?

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm interesting. I obviosuly need to use progmem and will slim down my printf useage - probably wont use it at all.
Is there any way to move things to the heap? Like in C++ there is the "new" keyword?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is there any way to move things to the heap?
How would that help? It would use the same amount of SRAM.
Quote:
there is the "new" keyword?
C uses malloc().

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you enable watchdog? It appears your program is looping on a reset of some kind, so monitoring MCUSR might tell you whats reseting the micro, if it's a reset.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I find the code usually does whatever I've been dumb enough to tell it to do.

If you're using the watchdog, turn it off. It just confuses things.

Get rid of the printf's and use something simpler to track you app's progress.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I assume you are using the gnu c compiler. 99% of the avr c programmers in the world do. Is there a way of specifying the stack size in that compiler? In the Excellent Imagecraft compiler, there is a dialog box in the IDE to do this without a degree in Computer Science. Rant Off.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anyone got some code I can "borrow" to replace printf but still be able to send floats to the serial?
I dont think Im using the watchdog... I never turned it on...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See the function dtostrf() in .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Is there a way of specifying the stack size in that compiler?

Why would you want to do that ? Is there a benefit to using anything less than all available memory ?

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChaunceyGardiner wrote:
Why would you want to do that ?
I would think because Imagecraft uses two stacks and the users have to guess how much they want for each of the stacks.