2008-03-11 11:03 PM
Basic conversion function
2011-05-17 03:26 AM
Hello,
I am actually trying to develop a communication between hyperterminal and STM3210 eval board. I would like to transmit real/string/integer by an easy way. Is there some functions to make this conversions (integer/real >> string)? Is there a better way to handle this (something like printf) ? Here is my sending routine :Code:
/******************************************************************************* <BR>* Function Name : USART_send <BR>* Description : Send a frame through USART <BR>* Input : const char *s <BR>* Output : None <BR>* Return : None <BR>*******************************************************************************/ <BR>void USART_send(const char *s) <BR>{ <BR> while (*s) <BR> { <BR> USART_SendData(USART2,*s++); <BR> while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); <BR> } <BR>}
[ This message was edited by: joneuhaus on 12-03-2008 10:13 ]2011-05-17 03:26 AM
I have found a way to do the trick : I use sprintf.
In the following example, I run an ADC conversion and send the return value through USART. int main(void) { #ifdef DEBUG debug(); #endif unsigned int value=0; volatile char *b; /* Configure the system clocks */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* Inputs Configuration */ GPIO_Configuration(); /* USART Configuration */ USART_Configuration(); /* ADC Configuration */ ADC_Configuration(); while (1) { /* Test if PB.09 level is low (Key push-button on Eval Board pressed) */ if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == 0x00) { /* Key is pressed */ /* Introduction message */ USART_send(''\r\nHey, you push me!!!\r\n''); /* Start ADC conversion */ ADC_SoftwareStartConvCmd(ADC1,ENABLE); /* Wait End of conversion */ while (!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)); /* Retrieve ADC value */ value=ADC_GetConversionValue(ADC1); /* Convert the ADC value into string */ sprintf(&b,''valeur = %d'',value); // convert integer >> String for display /* Send the previous string through USART */ USART_send(&b); } } [ This message was edited by: joneuhaus on 12-03-2008 11:34 ] [ This message was edited by: joneuhaus on 12-03-2008 11:36 ]