Forum Discussion
Altera_Forum
Honored Contributor
15 years agoWritting floating point numbers using IOWR IORD
Hi, I'm trying to read a custom register which has a 32 bit floating point value, from the NIOS in the c-code using the Macro IORD(base,offset). If I assign this to a variable defined as flo...
Altera_Forum
Honored Contributor
15 years agoIn my opinion the compiler sees the IORD result as an integer, and will cast it to a float value. I think the only way you could get around this is by using pointers and changing the pointer type. Something like (not tested):
float x,v;
*((unsigned int*)&x)= IORD(IOREG_BASE,0); // Reading from the register1 defined in H/W
v= x+2;
IOWR(IOREG_BASE,1,*((unsigned int*)&v)); // Writing to register2 defined in H/W I don't know if there is a more elegant way to do it...