STM32 - Cast from icucnt_t to float

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
DeSantis
Posts: 3
Joined: Wed Jul 16, 2014 1:12 pm

STM32 - Cast from icucnt_t to float

Post by DeSantis »

Hi,
i'm using ICUDriver on STM32f4 but i have a problem when i try to read the return value from "icuGetWidth(icup)" function.
In particular, i can't cast this value to int or float.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 - Cast from icucnt_t to float

Post by Giovanni »

It is already an unsigned integer.

Giovanni
DeSantis
Posts: 3
Joined: Wed Jul 16, 2014 1:12 pm

Re: STM32 - Cast from icucnt_t to float

Post by DeSantis »

Hi Giovanni,

Code: Select all

static void icuwidthcb(ICUDriver *icup) {

  palSetPad(GPIOD, GPIOD_LED4);
  last_width =icuGetWidth(icup);
}

icucnt_t last_width;

static void SRF05init(){

  uint16_t distance = 0;

  distance= last_width/58;
}


Distance is always 0 and say me the warning "optimized out".

Thank's for the reply
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 - Cast from icucnt_t to float

Post by Giovanni »

Is the callback actually called? try putting a breakpoint there.

Giovanni
DeSantis
Posts: 3
Joined: Wed Jul 16, 2014 1:12 pm

Re: STM32 - Cast from icucnt_t to float

Post by DeSantis »

Yes it is, infact if i put the mouse on "last_width" in debug mode, i can see the right value

thank you
fred
Posts: 20
Joined: Wed Feb 27, 2013 4:32 pm

Re: STM32 - Cast from icucnt_t to float

Post by fred »

Stupid question, but is the value of last_width you're seeing larger than 57? If it's not then integer divide is just going to return 0;

Secondly, declare the variable with volatile if you don't want the optimizer to touch it:

Code: Select all

volatile icucnt_t last_width;
Post Reply