NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Support Forum » A little help with printf_P(PSTR
July 15, 2011 by Ralphxyz |
I am trying to print some debug info about my "for" statements to my PC.
This is what I get from the printf:
ptr is a pointer to elements of an previously established/populated array. I would like to see the string contained in ptr. The for statements need some work but they do sorta work which is why I need to see what is being passed as _array[i] . Ralph |
---|---|
July 15, 2011 by Ralphxyz |
Here is a simpler example:
I guess the question is how does one print out an array's elements? I get this:
Thanks, Ralph |
July 15, 2011 by Ralphxyz |
Here is wayward's great explanation of initializing string arrays. Essentially one needs to add .data to avr-objcopy in the Makefile.
So now I get this:
I sure would be lost without the forum archive. Ralph |
July 15, 2011 by Noter |
Hey Ralph, The .data section is RAM so your strings are in RAM. The array of pointers named menu is in ROM but not the character strings. If you really intend to have the strings in ROM then an extra step is required to define them in ROM before populating the array. Then you must also use %S in your printf_P format instead of %s. You can remove the .data from your makefile and the following will still work because everything is in ROM.
|
July 16, 2011 by Noter |
Using a structure may be more to your liking because the extra step of setting the strings into ROM before populating the array is not necessary. Less typing on the upside but the drawback is the max length of the strings has to be specified and storage is reserved for that amount so it will not be as efficient in memory utilization. But since they are in ROM there is probably plenty of space.
|
July 16, 2011 by Ralphxyz |
Thanks Paul, I was hoping you would jump in (and all of the rest of you I depend on so much). I was/am just so pleased that it finally worked. I had/have a whole lot of questions about "Memory" but figured I had best re-read the links that wayward gave in his thread. Then I might be able to ask a intelligent question. I like the struct, I am starting to understand them. I was going to ask you about putting the definitions of the slant objects into EEPROM but was going to try once I at least got something working using device memory. So look for my question in your I2C EEPROM thread. Of course I am having problems restoring the I2C code I had working once so it might take me a bit before I am ready to ask about using EEPROM. Right now I am just trying to get something working so that I can test my water curtain . I think now I can revise my code from the top of this thread and be able to generate patterns then I can confirm that my water curtain will actually work. Once I can determine that I can actually see a pattern in the water then I'll be better off to see what is next. Plus I can look at expanding to 32 solenoids instead of 8. Not only do I need to work out mcu memory but I also have to figure out lighting which I had not had high on my list but now see that it is going to be essential probable critical. I really want to get my strobe light working but at least I have manual control over that so I do not yet have to work out the programming. Thanks again for all of your help, we are gonna make it yet. Ralph |
July 16, 2011 by Ralphxyz |
Hey Paul your struct code doesn't quite work :-(
I am working on it. Ralph |
July 16, 2011 by Ralphxyz |
Well this "fixes it", the problem I reported above with Paul's struct code, which I really like. It probable is not the best solution or method but hey it works!
Ralph |
July 16, 2011 by Noter |
That's strange, I tested it before posting and it works fine. Something different is going on with your setup. Probably in your terminal emulator or whatever you are using to display the data from the serial line on your PC. Where do you suppose that "ba" comes from at the begining of your output? |
July 16, 2011 by Ralphxyz |
Darn I've seen references to that ba but can not remember the context or how to remove it. I do not know but it might be something to do with OS X Terminal. Now if I hit the reset button I randomly get garbage on the first line:
I'll fire up my windows pc and see what I get in PUTTY. Ralph |
July 16, 2011 by Ralphxyz |
I am getting the same garbage on line one on my Windows 7 x64 computer. This is just a minor step in the process so I do not think there is a big problem with the random garbage. It would be nice to know why and what the fix is but I have to move on. If it inhibits my testing then I'll have to worry about it. Ralph |
July 16, 2011 by Noter |
Did you try HyperTerminal on the windows box? |
July 16, 2011 by Ralphxyz |
I used PUTTY, Hyper-Terminal is not connecting for me. Ralph |
July 17, 2011 by Rick_S |
Doesn't the bootloader send a ba at startup? If not, chalk it up to it being early and I'm just thinking out loud Rick |
July 17, 2011 by Noter |
I just checked and yes it does. The ba comes from the bootloader before it jumps to the application. Good memory there Rick! Even this early! |
July 17, 2011 by Ralphxyz |
I knew I had seen that ba somewhere, thanks Rick. Now here is a interesting twist:
I tried adding a while(1) loop thinking I would just repeat the serial output. Instead all I get is the � and it freezes until I do a reset. What am I missing now?
Ralph |
July 17, 2011 by Ralphxyz |
Why can't I do this?
Ralph |
July 17, 2011 by Noter |
That should work ... guess you need to figure out and correct your serial communications problem. I doubt it's the chip so that only leaves the usb conversion cable, although you surely would have trouble downloading if that was the problem, and the PC port config or software. I use hyperTerminal and config for 15200, N, 8, 1, and no flow control. Then I start the session before I powerup or reset my nerdkit. These days I'm using a real serial port (COM1) since my usb cable died last week and it works just as good as the usb cable did. |
July 17, 2011 by Ralphxyz |
Is [quote] That should work [/quote] referencing the while(1) statement? It doesn't work. What serial communications problem? Using my code above with the .data in the Makefile it all works as expected with no occasional garbage. Plus I can pass menu[i] to a variable and the while(1) works. Ralph |
July 17, 2011 by Noter |
On second look you need to remove the ";" at the end of the while statement line, then it will work. I thought you were still having serial problem but if not that's good. |
July 17, 2011 by Noter |
I thought you had data display problems without the extra cr/lf print statement? Maybe that's the serial issue I was thinking about. Then the reset thing is strange too. I don't see any of that with exactly the same code. |
Please log in to post a reply.
Did you know that you can input numbers in binary via a DIP switch, and output them to the LCD? Learn more...
|