Hi, ATOI on HCS08 not working for me, help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hi, ATOI on HCS08 not working for me, help

Jump to solution
1,140 Views
gusnavarro
Contributor II

Hi, im new here, and Im doing a proyect which happens that i need to change a string to integer.

On C eclipse works fine however on Freescale doesnt do anything.

 

Pleace help

 

I create a new proyect apart just to see ATOI working properly. I was able to see that the variable "number" changes from 4 to cero, as if nothing got atoi and if I uncoment the atof line i geet the error Symbol strtod ... is undefined.

 

Please advice (version of  my codewarrior is V6.3 build 9279

This is the code:

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

char y[] @0x0068 ="12";

char f[] @0x0070 ="143.343";

 

int number @0x0060 =4;

double flot;

 

void main(void) {

  

  EnableInterrupts; /* enable interrupts */

  /* include your code here */      

  for(;;) {

    __RESET_WATCHDOG(); /* feeds the dog */

      number=atoi((const char*)y);   /// also like this doesnt work : number=atoi(y);

  

     //flot = atof((const char*)f);

 

  } /* loop forever */

  /* please make sure that you never leave main */

}

Labels (1)
1 Solution
872 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Gus,

You can use function atoi() directly in your application.

See attached example project for reference.


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

10 Replies
873 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Gus,

You can use function atoi() directly in your application.

See attached example project for reference.


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

872 Views
gusnavarro
Contributor II

I have another doubt.

Your code works fine under MC9S08DZ60, but on the proyect im working on which happens to be 08QG8 doesnt work there

why is that ?


Greetings

0 Kudos
872 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi

1. QG8 default project allocates 0x40 bytes RAM to stack. while atoi and atof is very memory consuming. so you need increase the stack size.

2. use atof, you need use floating support.

see attached demo code and screenshot.


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

872 Views
gusnavarro
Contributor II

Thanks a lot Zhang!

I owe you a beer ! :smileyhappy:

0 Kudos
872 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

You are welcome !  :-)


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

872 Views
gusnavarro
Contributor II

Hi Jennie!
I have a new quetion for you :smileygrin:

0 Kudos
872 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Gus,

please create a new thread for the new questions. I will check. thanks!


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

872 Views
gusnavarro
Contributor II

Thanks a lot Jennie :smileyhappy:

0 Kudos
872 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome! :-)


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
872 Views
gusnavarro
Contributor II

Thank you Zhang! now it works fine atoi ! thx a lot

By the way  , do you happen to know why im getting strtod in file main.c.o is undefined ? in case i want to use atof ?

0 Kudos