串口发送字符串

2019-07-20 22:03发布

求各位大神,有没有串口发送字符串的函数,模板给提供一个,比如发送‘SET_WZERO’,谢谢了,简洁明了的
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
kingnike
2019-07-21 00:44
本帖最后由 kingnike 于 2016-5-24 11:20 编辑

#include <stdio.h>
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(USART1, (u8) ch);

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


  return ch;
}





int main(void)
{
   char buff[20];
   printf("hello world! ");
   sprintf(buff,"%s","stm32 test");
  printf(buff);

}

一周热门 更多>