printing a float

Discussion in 'Embedded Systems and Microcontrollers' started by taarabt, Dec 25, 2015.

  1. taarabt

    Thread Starter New Member

    Dec 24, 2015
    6
    0
    I'm trying to print a float however when i try to use printf(%f, x) i get this error when trying to sent it to pic:
    avrdude.exe: 34792 bytes of flash verified

    avrdude.exe: safemode: lfuse reads as 0
    avrdude.exe: safemode: hfuse reads as 0
    avrdude.exe: safemode: efuse reads as 0
    avrdude.exe: safemode: Fuses OK
    avrdude.exe: stk500v2_recv():checksum error
    avrdude.exe: stk500_2_ReceiveMessage(): timeout
    avrdude.exe: stk500_2_ReceiveMessage(): timeout

    if i just print a string like printf("hello") in th exact same line it works with no problems
    avrdude.exe: 30328 bytes of flash verified

    avrdude.exe: safemode: lfuse reads as 0
    avrdude.exe: safemode: hfuse reads as 0
    avrdude.exe: safemode: efuse reads as 0
    avrdude.exe: safemode: Fuses OK

    avrdude.exe done. Thank you.

    any ideas what is going on ?
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
  3. taarabt

    Thread Starter New Member

    Dec 24, 2015
    6
    0
    i'm using pic32mx320F128H and library stdio.h to use printf
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    See my signature line please.

    Why on earth are you using avrdude to try and program a pic?
     
  5. taarabt

    Thread Starter New Member

    Dec 24, 2015
    6
    0
    I'm doing this for a school project, just following what i learned on my classes. It worked until now....
     
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    You learned completely wrong or simply was not paying attention. My guess the later.

    The pic32mx320F128H is a chip made by Microchip.

    AVRDude is an utility to download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers made by Amtel.

    http://www.nongnu.org/avrd
     
  7. taarabt

    Thread Starter New Member

    Dec 24, 2015
    6
    0
    You guessed wrong then. I would message you my Box file if i could, only to prove my point.
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    OK then keep trying to program a Pic with an Amtel application then. See how far it gets you. Nothing I can find anywhere says this can be done.

    And you can attach files in this thread.
     
  9. taarabt

    Thread Starter New Member

    Dec 24, 2015
    6
    0
    I'm programing a chipkit board with MPLAB thats probably why it is possible to use avrdude, sorry, just taking my first steps here.
     
  10. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    I have never heard of using avrdude. There is no reason to use it. MPLab has its own ability to program a pic.

    What compiler are you using? And you still have not posted the line that causes an issue.

    What programmer are you using?
     
  11. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Hi.

    Normally:

    To program an Arduino, use the Arduino IDE
    To program an ATMEL AVR, use ATMEL Studio. I believe the latest version is close to 7. And an AVR MK II.

    To program a PIC, use MPLAB X, and the PCKit3 or likewise programmer. Do not try to make a programmer yourself. Not in a few years.
    You can also use MikroC.

    It would benefit everybody, if you inserted your source code, in code-tags, and told us which IDE you are using.
     
  12. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    You guys should really take a quick look at the Digilent Chipkit products featuring PIC32MX while using an Arduino style bootloader and IDE.
     
    Last edited: Dec 26, 2015
  13. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    I stand corrected.

    Thanks!
     
  14. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    It would have been real nice for the OP to provide us with that little bit of information that it was an Arduino that is acting as a programmer. I don't recall hearing that was possible though I see no reason why it could not be done. Which nerdgutta's statement still rings true in some respect. "Do not try to make a programmer yourself. Not in a few years.". Basically the OP is using a homemade programmer or rather a 3rd party programmer. Really bad idea in my opinion. Way too many weird problems.

    Since the OP provided no information whatsoever to fix the problem. I am going to take a guess that he/she is using C32 to compile the code, based on issues with %f in the sprintf call. C18 does not support the %f format specifier so I would assume c32 does not either. To print a float do something like this:


    float fBatteryVolts = 12.2;

    sprintf(string,(const far rom char*)"Battery %2d.%02dV ",(int)fBatteryVolts ,(int)((fBatteryVolts - (int)fBatteryVolts) *100));
     
    Last edited: Dec 26, 2015
Loading...