Sunday, April 22, 2012

ARM STM32 Study Note_4/USART

USART

1. Clock enable
 STM32F107VC has 5 USART, only USART1 use the clock enable signal from reg APB2ENR bit 14, the other four will get the clock enable signal from APB1ENR


 2. USART1 reset
  write 1 to bit 14 of APB2RSTR
3. BAUD-RATE
  Reg USART_BRR

 4. other registers
    data register(only lower 8 bit used): USART_DR
    status register:USART_SR

   control register:USART_CR1
  5. 串口1与USB的ID和VBUS信号富用,使用时需要改变跳线位置
     -使用串口2
    
  6.USART related structures

7. GetFlagStatus function
 while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)



8. Understanding STM_EVAL_COMInit(COM1, &USART_InitStructure);
   -defined at stm3210c_eval.c
   {
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable GPIO clock */
  RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
  /* COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
  and EVAL_COM1_TX_GPIO_CLK is defined in stm3210c_eval.h as #define EVAL_COM1_TX_GPIO_CLK    RCC_APB2Periph_GPIOD */

  if (COM == COM1)
  {
    /* Enable the USART2 Pins Software Remapping */
    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
    RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
  }
  else
  {
    /* Enable the USART1 Pins */
    RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
  }

  /* Configure USART Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);

  /* Configure USART Rx as input floating */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
  GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);

  /* USART configuration */
  USART_Init(COM_USART[COM], USART_InitStruct);
   
  /* Enable USART */
  USART_Cmd(COM_USART[COM], ENABLE);
}





================================================================

No comments:

Post a Comment