cancel
Showing results for 
Search instead for 
Did you mean: 

Basic conversion function

joneuhaus
Associate II
Posted on March 12, 2008 at 07:03

Basic conversion function

2 REPLIES 2
joneuhaus
Associate II
Posted on May 17, 2011 at 12:26

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 ]

joneuhaus
Associate II
Posted on May 17, 2011 at 12:26

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 ]