void OPC_N2_data_read()
{
unsigned int32 iobyte[3][4] = {0x00, };
int32 PM_int[3] = {0x00, };
float PM[3] = {0x00, };
int8 i,j,k;
int8 mask = 0x80;
const int16 mask1 = 0x0001;
const int16 mask0 = 0x0000;
int8 trash_byte = 0x32;
output_bit(ss,1);
output_bit(PM_CLOCK_pin,0);
delay_us (1);
output_bit(ss,0);
delay_us (2);
for( i = 0 ; i < 3 ; i ++ )
{
for ( j = 0 ; j < 4 ; j ++ )
{
for (k = 0 ; k < 8 ; k ++ )
{
output_bit(PM_CLOCK_pin,1);
iobyte[i][j] = iobyte[i][j] << 1;
if ( input ( PM_MISO_pin))
{
iobyte[i][j] |= mask1;
}
else
{
iobyte[i][j] |= mask0;
}
if ((trash_byte & mask) >0)
{
output_high(PM_MOSI_pin);
}
else
{
output_bit(PM_MOSI_pin,0);
}
delay_us(1);
output_bit(PM_CLOCK_pin,0);
delay_us(5);
mask = mask >>1;
}
}
}
delay_us(3);
output_high(ss);
for(i = 0; i<3; i++)
{
PM_int[i] = ((iobyte[i][0]<<24)|(iobyte[i][1]<<16)|(iobyte[i][2]<<8)|(iobyte[i][3]));
PM[i] = *(float*)&PM_int;
}
printf ("%x%x%x%x\r\n",iobyte[0][0],iobyte[0][1],iobyte[0][2],iobyte[0][3]);
printf ("%x%x%x%x\r\n",iobyte[1][0],iobyte[1][1],iobyte[1][2],iobyte[1][3]);
printf ("%x%x%x%x\r\n",iobyte[2][0],iobyte[2][1],iobyte[2][2],iobyte[2][3]);
printf ("%lx,%lx,%lx\r\n", PM_int[0],PM_int[1],PM_int[2]);
printf ("%3.5f,%3.5f,%3.5f\r\n", PM[0],PM[1],PM[2]);
}
I receive data from a 4-byte array. This data is a float value. I check through the computer, I see the following.
e911bd41 d867e641 8084e941 e911bd41,d867e641,8084e941 0.00000,0.00000,0.00000
Making the four data into one INT value works fine. PM_int[0]
,PM_int[1]
,PM_int[2]
However, if you try to convert this to a float value, only 0.00000
is displayed.
I do not know where the problem is.