با سلام
دوستان من کد ساده ای رو برای تبدیل floating point به string نوشتم . اما مشکلی که هست اینه که این کد در صورت غیر فعال بودن واحد FPU درست کار میکند. اگر واحد FPU فعال شود ، این کد دیگه درست کار نمیکند. ممنون میشم راهنمایی کنید.
کامپایلر مورد استفاده : KEIL
میکروکنترلر : STM32F407VGT6
[HTML]#include <stm32f4xx.h>
#include "stm32f4xx_conf.h"
#include <stdio.h>
void Delay(__IO uint32_t nCount);
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
char txt2[11];
char txt1[17]="error was ocurred";
uint16_t d=0x0000;
unsigned int size;
float moiseture=1111.655;
int main(void)
{
/* Periph clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/////////
GPIO_PinAFConfig( GPIOA , GPIO_PinSource2 , GPIO_AF_USART2 );
GPIO_PinAFConfig( GPIOA , GPIO_PinSource3 , GPIO_AF_USART2 );
////////
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//////
USART_InitStruct.USART_BaudRate = 9600 ;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None ;
USART_InitStruct.USART_Mode = USART_Mode_Tx |USART_Mode_Rx ;
USART_InitStruct.USART_Parity = USART_Parity_No ;
USART_InitStruct.USART_StopBits = USART_StopBits_1 ;
USART_InitStruct.USART_WordLength = USART_WordLength_8b ;
USART_Init( USART2 , &USART_InitStruct);
//////
USART_Cmd( USART2 , ENABLE );
//////
while (1)
{
size=snprintf( txt2,11, "%4.4f\n", moiseture);
for( d=0;d<size;d++){
USART_SendData( USART2 , txt2[d]);
while (!(USART2->SR & USART_SR_TC));
}
Delay(0x6FFFFF);
}
}
void Delay(__IO uint32_t nCount)
{
while(nCount--)
{
}
}
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
for( d=0;d<17;d++){
USART_SendData( USART2 , txt1[d]);
while (!(USART2->SR & USART_SR_TC));
}
while(1);
}
[/HTML]