P224~



UART : CPU에서 나오는 신호레벨(TTL 레벨)

RS-232 : UART칩을 거쳐 나온 신호


#define USART1_BASE    (APB2PERIPH_BASE + 0x3800)    관련 RSMap은 맨 위의 표와 같음

#define USART1            ((USART_TypeDef*)USART1_BASE)



<Source_Code>


#include <stm32f10x.h>


#define GPIO_USART  GPIOA

#define GPIO_USART_Rx_Pin GPIO_Pin_10

#define GPIO_USART_Tx_Pin GPIO_Pin_9


//GPIOA의 10번과 9번 핀을 각각 수.송신부로 사용하고 있다.


void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure; 

  

  GPIO_InitStructure.GPIO_Pin = GPIO_USART_Tx_Pin;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIO_USART,&GPIO_InitStructure);

  

  GPIO_InitStructure.GPIO_Pin = GPIO_USART_Rx_Pin;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIO_USART,&GPIO_InitStructure);

}


void USART1_Init(void)

{

  USART_InitTypeDef USART_InitStructure; 

  

  /*USARTx configured as follow:

  -BaudRate : 115200 baud

  -Word Length = 8bits

  -One Stop Bit

  -No parity

  -Hardware flow control disabled (RTS and CTS signals)

  -Receive and transmit enabled

  */

  

  USART_InitStructure.USART_BaudRate = 115200;

  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;

  

  //Configure the USARTx

  

  USART_Init(USART1, &USART_InitStructure);

  

  //Enable the USART1

  USART1->CR1 |= CR1_UE_Set;

}


void Serial_PutString(uint8_t *s){

  while(*s != '\0'){

    SerialPutChar(*s);

    s++;

  }

}


void RCC_Set(void){

  RCC->APB2ENR |= RCC_APB2Periph_USART1;

}


int main(void)

{

  RCC_Set();


  GPIO_Configuration();

  

  USART1_Init();


  while(1){

 Serial_PutString("\r\nHello World! Hello Cortex-M3!\r\n") ; 

  }

}




'중도연재종료 > CORTEX M3' 카테고리의 다른 글

당분간 정지  (0) 2013.06.14
UART_ Hello_Wolrd 찍기_2  (0) 2013.06.08
GPIO_Init  (0) 2013.05.25
Key가 눌린것 알아채기  (0) 2013.05.24
고급스러운 코딩1.  (0) 2013.05.24
Posted by 십자성군