cancel
Showing results for 
Search instead for 
Did you mean: 

SOLVED : USART_SendData

julien
Associate II
Posted on April 17, 2008 at 11:24

SOLVED : USART_SendData

9 REPLIES 9
julien
Associate II
Posted on May 17, 2011 at 12:30

Hello,

I'm using USART_SendData function, and i'm surprised that when i transmit the value ''224''(decimal) i receive ''248''.

USART_SendData(USART1, 224);

or if I transmit ''65'' I receive ''224''..

my configuration :

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_InitStructure.USART_Clock = USART_Clock_Disable;

USART_InitStructure.USART_CPOL = USART_CPOL_Low;

USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;

USART_InitStructure.USART_LastBit = USART_LastBit_Disable;

/* Configure the USART1 */

USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);

I don't understand ..

thanks

[ This message was edited by: julien.massot on 15-04-2008 15:43 ]

[ This message was edited by: julien.massot on 17-04-2008 14:54 ]

16-32micros
Associate III
Posted on May 17, 2011 at 12:30

What is your host UART or other part configuration ?

julien
Associate II
Posted on May 17, 2011 at 12:30

My host Uart is the USART1, I'm using the firmware library um0427

GPIO :

/* Configure USART1 Tx as alternate function push-pull */

GPIO_InitStructureU.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructureU.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructureU.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructureU);

/* Configure USART1 Rx (PD.10) as input floating */

GPIO_InitStructureU.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructureU.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructureU);

On my PC i launch a sniffer who reads the decimal value

16-32micros
Associate III
Posted on May 17, 2011 at 12:30

Bonjour Julien,

I mean what is the full configuration of the PC sniffer ?

baudrate, partity, etc.. thank you.

Cheers,

STOne-32.

julien
Associate II
Posted on May 17, 2011 at 12:30

Com6

baud 9600

Data 8

Parity none

Stop 1

However

this function works properly, and return the good value

do

{

if((USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)&&(RxCounter < RxBufferSize))

{

RxBuffer[RxCounter] = USART_ReceiveData(USART1);

USART_SendData(USART1, RxBuffer[RxCounter++]);

}

}while(RxCounter != RxBufferSize);

strange..

lanchon
Associate III
Posted on May 17, 2011 at 12:30

hi,

I don't know the USART peripheral, but couldn't help but notice that

224 = 0xE0 = 11100000

248 = 0xF8 = 11111000

it smells like maybe there's a significant difference (40%) in baud rate between transmitter and receiver. check your clock frequency. I assume you're using a crystal, the firmware lib expects the frequency of the external crystal in a #define directive. the default is 8MHz.

julien
Associate II
Posted on May 17, 2011 at 12:30

Thanks,

I'm using an external crystal at 12Mhz, PLL factor is configure at 6 :

RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_6);

So i'm running at 72 Mhz..

I'm searching with gdb..

16-32micros
Associate III
Posted on May 17, 2011 at 12:30

Hi Julien,

lanchon suggestion is right and you should modifiy in the file called

''stm32f10x_conf.h''

Just before the Assert macro

/* In the following line adjust the value of External High Speed oscillator (HSE)

used in your application */

#define HSE_Value ((u32)8000000) /* Value of the External oscillator in Hz*/

By #define HSE_Value ((u32)12000000) /* Value of the External oscillator in Hz*/

Hope this is more clear now. Cheers,

STOne-32.

julien
Associate II
Posted on May 17, 2011 at 12:30

Thank you STOne and good suggestion Lanchon..

Now my Usart works properly...