I want to receive a float on Atmega32 from matlab. I display the output on an lcd, but i receive 0.000, can any one help me? Please ...
matlab code
s=serial('COM1','BaudRate',9600);
fopen(s)
fwrite(s,170,'uint8');//header frame
fwrite(s,1.2,'float');//the data to be sent
ATmega32 code
union {
signed long l;
float f;
} data;
int main(void)
{
DDRA=0xff;//for LCD
DDRB=0xff;//for LCD
data.l;
char value[8];
usart_init();
Lcd8_Init();
while(1)
{
if(uart_receive()==0xAA)
{
//header,0xAA=170
Lcd8_Set_Cursor(0,0);
Lcd8_Write_String("Float");
_delay_ms(100);
data.l=(long)uart_receive();
data.l=(long)(data.l||(uart_receive()<<8));
data.l=(long)(data.l||(uart_receive()<<16));
data.l=(long)(data.l||(uart_receive()<<24));
dtostrf(data.f,8,3,value);//convert float to string
Lcd8_Clear();
Lcd8_Set_Cursor(0,0);
for(int i=0;i<8;i++) Lcd8_Write_Char(value[i]);
}
}}
data.l, but you tried to convert the float member of datadata.fto a string.data.fis still 0.0