cancel
Showing results for 
Search instead for 
Did you mean: 

Transmitting with USART my code

jgalea
Associate II
Posted on February 11, 2009 at 12:59

Transmitting with USART my code

1 REPLY 1
jgalea
Associate II
Posted on May 17, 2011 at 13:02

Hello, Thanks to brunoalltest, Im transmitting with USART. Im putting the code as promised.

void USART_Set_up(void)

{

USART_InitTypeDef USART_InitStructure; //declaration of structure

// USART_ClockInitTypeDef USART_ClockInitStructure;

USART_DeInit(USART1); //places USART1 to default reset value

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_Tx;

USART_Init(USART1, &USART_InitStructure);

/* Enable the USARTx */

USART_Cmd(USART1, ENABLE);

}

/* USART1 Rx */

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* USART1 Tx */

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_Init(GPIOA, &GPIO_InitStructure);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1 |

RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |

RCC_APB2Periph_GPIOC | RCC_APB2Periph_USART1, ENABLE);

/* Send one HalfWord on USART1 */

USART_SendData(USART1, 115); //38 decimal