打印

难道f2 f4的串口1 不能用?

[复制链接]
1886|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
网络转接|  楼主 | 2012-1-16 17:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题
沙发
rdghx| | 2012-1-16 22:40 | 只看该作者
可以用啊,用的挺好的

使用特权

评论回复
板凳
网络转接|  楼主 | 2012-1-17 10:26 | 只看该作者
能不能分享一下啊

使用特权

评论回复
地板
网络转接|  楼主 | 2012-1-17 10:30 | 只看该作者
SystemInit();

   RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
     GPIO_Configuration();
  /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - 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;

  USART_Init(USART1, &USART_InitStructure);
  USART_Cmd(USART1, ENABLE);

  Uart_PutString(TxBuffer,50);
  /* Output a message on Hyperterminal using printf function */
  printf("\n\r      S-107 USART  Study    \n\r");
  printf("\n\r      www.stmsky.com/bbs    \n\r");
  printf("\n\r           stm家园    \n\r");
  printf("\n\r      www.stmsky.com/bbs    \n\r");
  printf("\n\r  http://shop60442272.taobao.com    \n\r");



  while (1)
  {
  }
}
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);

  /* Connect PXx to USARTx_Rx*/
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
  /* Configure USARTx_Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure USARTx_Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

}
/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */

u8 Uart_PutChar(u8 ch)
{
   
        USART_SendData(USART1, (u8) ch);
        while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
    {}
        return ch;

}
void Uart_PutString(u8 buf[],u16 len)
{
    u16 i;
    for( i=0;i<len;i++)
    {
        Uart_PutChar(*buf++);
        }

}
PUTCHAR_PROTOTYPE
{
  
    USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  {}
  /* Loop until the end of transmission */

  return ch;
}

使用特权

评论回复
5
香水城| | 2012-1-17 11:02 | 只看该作者
是不是电路上有什么问题呀?

使用特权

评论回复
6
网络转接|  楼主 | 2012-1-17 11:36 | 只看该作者
这个有待 验证 在家没烙铁 不过我isp可以连 应该没问题

使用特权

评论回复
7
baidudz| | 2012-1-17 18:53 | 只看该作者
可以用

使用特权

评论回复
8
秋天落叶| | 2012-1-17 19:01 | 只看该作者
楼主检查一下电路

使用特权

评论回复
9
火箭球迷| | 2012-1-17 19:50 | 只看该作者
我用过,挺好用的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:stm家园 http://corxstm32.taobao.com/ 专业 诚信  stm家园

19

主题

503

帖子

6

粉丝