hey people,
Im really close to achieving my objective but I seem to get a type conversion error/problem.
I'm basically sampling from an temperature sensor in an ADC on a 8051 MCU and every second firing a timer to take a sample and send out on UART (RS-232) in which i have connected a serial cable to my PC with hyperterminal running. I have the ADC result saved as a float, but the UART has a 1 byte tx/rx buffer so tried using sprintf:
Hyperterminal shows:
Tâ"þTâ"þTâ"þTâ"þ // repetitively on and on....
The above doesn't get me anything
However if i just do like :
Hyperterminal:
TÁTÁTÁTÁTÁTðTðTðTðTðTðTðTðTðTƒTðTðTÁTÁ /* Ignore the 'T's i add them in as i need to send out a byte first. A changing output when i touch the MCU, built in temp-sensor*/
So i know ADC readings are occuring by the output(random character/symbols) changing when i warm up the MCU (touch it with my finger! - v. technical!) and they change back when i let go.
So my question is how can i get the ADCresult float value into a char array(string) to output onto hyperterminal as the char array equivalent of the fADCresult float vals ?????? I know i'm close!
Im really close to achieving my objective but I seem to get a type conversion error/problem.
I'm basically sampling from an temperature sensor in an ADC on a 8051 MCU and every second firing a timer to take a sample and send out on UART (RS-232) in which i have connected a serial cable to my PC with hyperterminal running. I have the ADC result saved as a float, but the UART has a 1 byte tx/rx buffer so tried using sprintf:
Rich (BB code):
char cArray[4];
fADCresult = getADCresult();
sprintf(cArray, "%3f", fADCresult);
for (i=0 ; i<sizeof(cArray); i++)
{
UART0_WAIT_AND_SEND( cArray );
}
// in header file:
#define UART0_WAIT_AND_SEND(x) \
do \
{ while (!UTX0IF); \
UTX0IF=0; \
U0DBUF=(x); \
} while (0)
Hyperterminal shows:
Tâ"þTâ"þTâ"þTâ"þ // repetitively on and on....
The above doesn't get me anything
However if i just do like :
Rich (BB code):
/*sprintf(cArray, "%3f", fADCresult); // Get rid of this sprintf*/
UART0_WAIT_AND_SEND((unsigned char)fADCresult);
TÁTÁTÁTÁTÁTðTðTðTðTðTðTðTðTðTƒTðTðTÁTÁ /* Ignore the 'T's i add them in as i need to send out a byte first. A changing output when i touch the MCU, built in temp-sensor*/
So i know ADC readings are occuring by the output(random character/symbols) changing when i warm up the MCU (touch it with my finger! - v. technical!) and they change back when i let go.
So my question is how can i get the ADCresult float value into a char array(string) to output onto hyperterminal as the char array equivalent of the fADCresult float vals ?????? I know i'm close!