STM32F051C8芯片的USART奇怪的问题

[复制链接]
4854|27
 楼主| zxm19820916 发表于 2013-3-11 12:28 | 显示全部楼层 |阅读模式
使用这款芯片开发一款产品(有USART1和USART2)。一个USART口作为串口打印,另外一个作为Modbus通信口。
问题:使用1作为Modbus口,2作为串口。
USART1配置中有
USART_ITConfig(USART1, USART_IT_TC, ENABLE);
或者
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
都导致USART2打印不出测试字符串。

仿真发现,u32  isr = USART1->ISR;  isr = 0x000000C0。即TXE和TC位均为1.(为什么?)
所以一直在中断函数(发送)中出不来。
而2个USART调换下功能,不会有这个问题,请多多指教。

 楼主| zxm19820916 发表于 2013-3-11 12:39 | 显示全部楼层
不知道为什么,发送中断使能应该在哪个地方使用?
IJK 发表于 2013-3-11 13:29 | 显示全部楼层
TXE和TC位均为1,属于正常现象
 楼主| zxm19820916 发表于 2013-3-11 14:24 | 显示全部楼层
TC中断使能在配置USART时DISABLE,在要发送数据的地方再ENABLE,另外一个uart可以打印出测试字符串了。
 楼主| zxm19820916 发表于 2013-3-11 18:11 | 显示全部楼层
但是,PC端使用Modbus Poll做主站,通过485连接此模块。一直连接不上。进入不了接收中断,不知道什么原因?
UART的配置和NVIC都配置了,接收中断也使能了。
罗菜鸟 发表于 2013-3-12 09:30 | 显示全部楼层
4楼正解,TXE和TC标志是常为1的,往里面压入一个字节后才能清零。
 楼主| zxm19820916 发表于 2013-3-12 09:53 | 显示全部楼层
罗菜鸟 发表于 2013-3-12 09:30
4楼正解,TXE和TC标志是常为1的,往里面压入一个字节后才能清零。

我在5楼的问题你能指教一下吗?
Modbus Poll可以发送出数据,但模块进入不了接收中断,不知道为啥?
罗菜鸟 发表于 2013-3-12 10:05 | 显示全部楼层
zxm19820916 发表于 2013-3-12 09:53
我在5楼的问题你能指教一下吗?
Modbus Poll可以发送出数据,但模块进入不了接收中断,不知道为啥? ...

你的配置如何?
 楼主| zxm19820916 发表于 2013-3-12 10:16 | 显示全部楼层
罗菜鸟 发表于 2013-3-12 10:05
你的配置如何?

USART1作为Modbus通信口。时钟开启了,中断向量表加入了,USART1初始化配置了,使能了接收中断,使能了USART1。公司的电脑,上传不了代码。
罗菜鸟 发表于 2013-3-12 10:18 | 显示全部楼层
复制粘贴
罗菜鸟 发表于 2013-3-12 10:19 | 显示全部楼层
罗菜鸟 发表于 2013-3-12 10:18
复制粘贴
  1. /******************** (C) COPYRIGHT 2008 litt ********************
  2. * File Name          : usart.c
  3. * Author             : luo yi ming
  4. * Version            : V1.0.0
  5. * Date               : 2012年12月28日
  6. * Description        : This file provides a set of functions needed to manage the
  7. *                      communication between usart peripheral and RS485/HW/PLC.
  8. ********************************************************************************/

  9. /* Includes ------------------------------------------------------------------*/
  10. #include "includes.h"
  11. #include "usart.h"

  12. /* Private typedef -----------------------------------------------------------*/
  13. struct UartFifo{
  14.         //rx 12byte
  15.         u8*   rxBuf;             //4
  16.         vu16  rxSize;            //2
  17.         vu16  rxPush;   //2
  18.         vu16  rxPop;    //2
  19.         u16   rxCnt;    //2
  20.         //tx 12byte
  21.         u8*   txBuf;             //4
  22.         vu16  txSize;            //2
  23.         vu16  txPush;   //2
  24.         vu16  txPop;    //2
  25.         u16   txCnt;    //2
  26.         //Isr 4byte
  27.         void (*isr)(uint8_t,enum UartIsrMod);
  28. };//28


  29. struct UartCfg{
  30.         struct UartFifo  fifo;
  31.   USART_TypeDef*   uart;
  32.   DMA_Channel_TypeDef*     rxdma;
  33.   DMA_Channel_TypeDef*     txdma;
  34. };

  35. /*struct UartReg{
  36.          USART_TypeDef*   uart;
  37.         DMA_Channel_TypeDef*     rxdma;
  38.         DMA_Channel_TypeDef*     txdma;
  39. };*/

  40. /* Private define ------------------------------------------------------------*/




  41. #define  UART1_DMA_RX  DMA1_Channel5
  42. #define  UART1_DMA_TX  DMA1_Channel4

  43. #define  UART2_DMA_RX  DMA1_Channel6
  44. #define  UART2_DMA_TX  DMA1_Channel7

  45. #define  UART3_DMA_RX  DMA1_Channel3
  46. #define  UART3_DMA_TX  DMA1_Channel2



  47. #define  UART_REG_1 {USART1,UART1_DMA_RX,UART1_DMA_TX}
  48. #define  UART_REG_2 {USART2,UART2_DMA_RX,UART2_DMA_TX}
  49. #define  UART_REG_3 {USART3,UART3_DMA_RX,UART3_DMA_TX}
  50. #define  UART_REG_4 {UART4,NULL,NULL}
  51. #define  UART_REG_5 {UART5,NULL,NULL}

  52. /* Private macro -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/

  54. struct UartCfg UartCfgTab[UART_PORT_MAX];
  55. //const struct UartReg UartRegTab[UART_PORT_MAX] = {UART_REG_1,UART_REG_2,UART_REG_3,UART_REG_4,UART_REG_5};



  56. /*
  57.     UART running by interrupt model
  58. */

  59. /*************************************************************************************************
  60. * Name       : UartIntIsr
  61. * Describe   : 串口中断服务程序
  62. * Input      : pfifo,uart
  63. * Output     : 无
  64. * Create by  : 罗一鸣 2012-12-03
  65. * Moid   by  :
  66. *************************************************************************************************/
  67. static __inline void UartIntIsr(uint8_t port,struct UartFifo *pfifo,USART_TypeDef *uart)
  68. {
  69.         uint32_t ie;
  70.         uint8_t c;
  71.         ie = __get_PRIMASK();
  72.         __set_PRIMASK(1);
  73.         if((uart->CR1 & 0x0020) && (uart->SR & 0x0020))
  74.         {
  75.                 c = uart->DR;
  76.                 if(pfifo->rxCnt < pfifo->rxSize)
  77.                 {
  78.                         pfifo->rxBuf[pfifo->rxPush] = c;
  79.                         pfifo->rxPush += 1;
  80.                         pfifo->rxPush %= pfifo->rxSize;
  81.                         pfifo->rxCnt += 1;
  82.                         if(pfifo->rxCnt == (pfifo->rxSize - SERIAL_RXFULL_LINE))
  83.                         {
  84.                                 if(NULL != pfifo->isr)
  85.                                 {
  86.                                         pfifo->isr(port,RxFull);
  87.                                 }
  88.                         }
  89.                 }
  90.         }
  91.         //IDLE IRQ
  92.         if((uart->CR1 & 0x0010)&&(uart->SR & 0x0010))
  93.         {
  94.                 c = uart->DR;
  95.                 if(pfifo->rxCnt < (pfifo->rxSize - SERIAL_RXFULL_LINE))
  96.                 {
  97.                         if(NULL != pfifo->isr)
  98.                         {
  99.                                 pfifo->isr(port,RxTimeout);
  100.                         }
  101.                 }
  102.         }
  103.         //TXE IRQ
  104.         if((uart->SR & 0x0080) && (uart->CR1 & 0x0080))
  105.         {
  106.                 uart->CR1 &= (uint16_t)~0x0080; //off TX
  107.                 if(pfifo->txCnt)
  108.                 {
  109.                         c = pfifo->txBuf[pfifo->txPop];
  110.                         uart->DR = c;
  111.                         uart->CR1 |= (uint16_t)0x0080;
  112.                         pfifo->txPop += 1;
  113.                         pfifo->txPop %= pfifo->txSize;
  114.                         pfifo->txCnt -= 1;
  115.                         if(pfifo->txCnt == 0)
  116.                         {
  117.                                 if(NULL != pfifo->isr)
  118.                                 {
  119.                                         pfifo->isr(port,TxEmpty);
  120.                                 }
  121.                         }
  122.                 }
  123.         }
  124.         __set_PRIMASK(ie);
  125. }


  126. /*************************************************************************************************
  127. * Name       : UartRead
  128. * Describe   : 串口读取函数
  129. * Input      :
  130. * Output     :
  131. * Create by  :
  132. * Moid   by  :
  133. *************************************************************************************************/
  134. static uint16_t UartReadInt(struct UartFifo *pfifo,USART_TypeDef *uart,uint8_t *data,uint16_t len)
  135. {
  136.         uint16_t n;
  137.         if(len == 0)
  138.         {
  139.                 return 0;
  140.         }
  141.         else if(len > pfifo->rxSize)
  142.         {
  143.                 len = pfifo->rxSize;
  144.         }
  145.        
  146.         for(n=0;n<len;n++)
  147.         {
  148.                 USART_ITConfig(uart,USART_IT_RXNE ,DISABLE);
  149.                 if(pfifo->rxCnt > 0)
  150.                 {
  151.                         *data++ = pfifo->rxBuf[pfifo->rxPop];
  152.                         pfifo->rxPop += 1;
  153.                         pfifo->rxPop %= pfifo->rxSize;
  154.                         pfifo->rxCnt--;
  155.                         USART_ITConfig(uart,USART_IT_RXNE ,ENABLE);
  156.                 }
  157.                 else
  158.                 {
  159.                         USART_ITConfig(uart,USART_IT_RXNE ,ENABLE);
  160.                         break;
  161.                 }
  162.         }
  163.        
  164.         return n;
  165. }


  166. /*************************************************************************************************
  167. * Name       : UartWrite
  168. * Describe   : 串口发送函数
  169. * Input      :
  170. * Output     :
  171. * Create by  :
  172. * Moid   by  :
  173. *************************************************************************************************/
  174. static uint16_t UartWriteInt(struct UartFifo *pfifo,USART_TypeDef *uart,uint8_t *data,uint16_t len)
  175. {
  176.         uint16_t n;
  177.         if(len == 0)
  178.         {
  179.                 return 0;
  180.         }
  181.         else if(len > pfifo->txSize)
  182.         {
  183.                 len = pfifo->txSize;
  184.         }
  185.         USART_ITConfig(uart,USART_IT_TXE ,DISABLE);
  186.         for(n=0;n<len;n++)
  187.         {
  188.                 if(pfifo->txCnt < pfifo->txSize)
  189.                 {
  190.                         pfifo->txBuf[pfifo->txPush] = *data++;
  191.                         pfifo->txPush += 1;
  192.                         pfifo->txPush %= pfifo->txSize;
  193.                         pfifo->txCnt++;
  194.                 }
  195.                 else
  196.                 {
  197.                         break;
  198.                 }
  199.         }
  200.         USART_ITConfig(uart,USART_IT_TXE ,ENABLE);
  201.         return n;
  202. }

  203. /*************************************************************************************************
  204. * Name       : USART_ISR
  205. * Describe   : 串口中断服务
  206. * Input      :
  207. * Output     :
  208. * Create by  :
  209. * Moid   by  :
  210. *************************************************************************************************/
  211. void USART_ISR(uint8_t port)
  212. {
  213.         UartIntIsr(port,&UartCfgTab[port].fifo,UartCfgTab[port].uart);
  214. }


  215. /*

  216. */
  217. __inline void UartDmaIsr(uint8_t port,struct UartFifo *pfifo,USART_TypeDef *uart)
  218. {
  219.        
  220.        
  221. }




  222. /*
  223.                 UART API
  224. */




  225. /*************************************************************************************************
  226. * Name       : SerialPortConfig
  227. * Describe   :  
  228. * Input      :  
  229. * Output     :  
  230. * Create by  : 罗一鸣    Date: 2012-12-03
  231. * Moid   by  :
  232. *************************************************************************************************/
  233. void UartNvicSet(uint8_t port,uint8_t preprio,uint8_t subprio)
  234. {
  235.         NVIC_InitTypeDef NVIC_InitStructure;
  236.         GPIO_InitTypeDef GPIO_InitStructure;
  237.         if(UART_PORT_1 == port)
  238.         {               
  239.                 // config USART1 clock
  240.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
  241.                 // Configure USART1 Tx (PA.09) as alternate function push-pull
  242.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  243.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  244.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  245.                 GPIO_Init(GPIOA, &GPIO_InitStructure);
  246.                 // Configure USART1 Rx (PA.10) as input floating
  247.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  248.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  249.                 GPIO_Init(GPIOA, &GPIO_InitStructure);
  250.                 // Set Interrupt Priority
  251.     NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  252.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preprio;
  253.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = subprio;
  254.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  255.                 //CLI();
  256.                 NVIC_Init(&NVIC_InitStructure);
  257.                 //SEI();
  258.         }
  259.         else if(UART_PORT_2 == port)
  260.         {
  261.                 // config USART2 clock
  262.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  263.                 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  264.                 // Configure USART2 Tx (PA.02) as alternate function push-pull
  265.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  266.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  267.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  268.                 GPIO_Init(GPIOA, &GPIO_InitStructure);
  269.                 // Configure USART2 Rx (PA.03) as input floating
  270.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  271.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  272.                 GPIO_Init(GPIOA, &GPIO_InitStructure);
  273.                 // Set Interrupt Priority
  274.     NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  275.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preprio;
  276.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = subprio;
  277.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  278.                 //CLI();
  279.                 NVIC_Init(&NVIC_InitStructure);
  280.                 //SEI();
  281.         }
  282.         else if(UART_PORT_3 == port)
  283.         {
  284.                 // config USART3 clock
  285.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  286.                 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  287.                 // Configure USART2 Tx (PB.10) as alternate function push-pull
  288.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  289.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  290.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  291.                 GPIO_Init(GPIOB, &GPIO_InitStructure);
  292.                 // Configure USART2 Rx (PB.11) as input floating
  293.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  294.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  295.                 GPIO_Init(GPIOB, &GPIO_InitStructure);
  296.                 // Set Interrupt Priority
  297.     NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  298.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preprio;
  299.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = subprio;
  300.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  301.                 //CLI();
  302.                 NVIC_Init(&NVIC_InitStructure);
  303.                 //SEI();
  304.         }
  305. }




  306. /*************************************************************************************************
  307. * Name       : UartConfig
  308. * Describe   :  
  309. * Input      :  
  310. * Output     :  
  311. * Create by  : 罗一鸣    Date: 2012-12-03
  312. * Moid   by  :
  313. *************************************************************************************************/
  314. void UartConfig(uint8_t port,uint8_t *buf,uint16_t size,void (*isr)(uint8_t,enum UartIsrMod),FunctionalState dma)
  315. {
  316.         switch(port)
  317.         {
  318.                 case UART_PORT_1: UartCfgTab[port].uart = USART1;UartCfgTab[port].rxdma = UART1_DMA_RX;UartCfgTab[port].txdma = UART1_DMA_TX;break;
  319.                 case UART_PORT_2: UartCfgTab[port].uart = USART2;UartCfgTab[port].rxdma = UART2_DMA_RX;UartCfgTab[port].txdma = UART2_DMA_TX;break;
  320.                 case UART_PORT_3: UartCfgTab[port].uart = USART3;UartCfgTab[port].rxdma = UART3_DMA_RX;UartCfgTab[port].txdma = UART3_DMA_TX;break;
  321.                 case UART_PORT_4: UartCfgTab[port].uart = UART4;break;
  322.                 case UART_PORT_5: UartCfgTab[port].uart = UART5;break;
  323.                 default : return;
  324.         }
  325.         UartCfgTab[port].fifo.rxBuf = buf;
  326.         UartCfgTab[port].fifo.txBuf = buf+size/2;
  327.         UartCfgTab[port].fifo.rxSize = UartCfgTab[port].fifo.txSize = size/2;
  328.         UartCfgTab[port].fifo.rxPush = UartCfgTab[port].fifo.rxPop = UartCfgTab[port].fifo.rxCnt = 0;
  329.         UartCfgTab[port].fifo.txPush = UartCfgTab[port].fifo.txPop = UartCfgTab[port].fifo.txCnt = 0;
  330.         UartCfgTab[port].fifo.isr = isr;       
  331.         if(DISABLE == dma)
  332.         {
  333.                 UartCfgTab[port].rxdma = NULL;
  334.                 UartCfgTab[port].txdma = NULL;
  335.                 USART_ITConfig(UartCfgTab[port].uart,USART_IT_TXE ,DISABLE);
  336.                 USART_ITConfig(UartCfgTab[port].uart,USART_IT_RXNE,ENABLE);
  337.                 USART_ITConfig(UartCfgTab[port].uart,USART_IT_IDLE,ENABLE);
  338.                 USART_Cmd(UartCfgTab[port].uart, ENABLE);
  339.         }
  340.         else
  341.         {
  342.                 USART_ITConfig(UartCfgTab[port].uart,USART_IT_IDLE,ENABLE);
  343.                 USART_Cmd(UartCfgTab[port].uart, ENABLE);
  344.         }
  345. }

  346. /*************************************************************************************************
  347. * Name       : UartOpen
  348. * Describe   :  
  349. * Input      :  
  350. * Output     :  
  351. * Create by  : 罗一鸣    Date: 2013-02-27
  352. * Moid   by  :
  353. *************************************************************************************************/
  354. void UartOpen(uint8_t port,uint32_t baud,uint8_t mod)
  355. {
  356.         USART_InitTypeDef init;
  357.         init.USART_BaudRate = baud;
  358.         init.USART_WordLength = USART_WordLength_8b;
  359.         init.USART_StopBits = USART_StopBits_1;
  360.         init.USART_Parity = USART_Parity_No ;
  361.         if(mod & UART_FLOW_EN)
  362.         {
  363.                 init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  364.         }
  365.         init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  366.         USART_Init(UartCfgTab[port].uart, &init);
  367. }

  368. /*************************************************************************************************
  369. * Name       : UartRead
  370. * Describe   :  
  371. * Input      :  
  372. * Output     :  
  373. * Create by  : 罗一鸣    Date: 2012-12-03
  374. * Moid   by  :
  375. *************************************************************************************************/
  376. uint16_t UartRead(uint8_t port,uint8_t *data,uint16_t len)
  377. {
  378.         if(UART_PORT_MAX <= port)
  379.         {
  380.                 return 0;
  381.         }
  382.         if((NULL != UartCfgTab[port].rxdma))
  383.         {
  384.                 return 0;
  385.         }
  386.         else
  387.         {
  388.                 return UartReadInt(&UartCfgTab[port].fifo,UartCfgTab[port].uart,data,len);
  389.         }
  390. }

  391. /*************************************************************************************************
  392. * Name       : UartWrite
  393. * Describe   :  
  394. * Input      :  
  395. * Output     :  
  396. * Create by  : 罗一鸣    Date: 2012-12-03
  397. * Moid   by  :
  398. *************************************************************************************************/
  399. uint16_t UartWrite(uint8_t port,uint8_t *data,uint16_t len)
  400. {
  401.         if(UART_PORT_MAX <= port)
  402.         {
  403.                 return 0;
  404.         }
  405.         if((NULL != UartCfgTab[port].txdma))
  406.         {
  407.                 return 0;
  408.         }
  409.         else
  410.         {
  411.                 return UartWriteInt(&UartCfgTab[port].fifo,UartCfgTab[port].uart,data,len);
  412.         }
  413. }


  414. /*************************************************************************************************
  415. * Name       : UartRxCnt
  416. * Describe   :
  417. * Input      :
  418. * Output     :
  419. * Create by  :
  420. * Moid   by  :
  421. *************************************************************************************************/
  422. uint16_t UartRxCnt(uint8_t port)
  423. {
  424.         return UartCfgTab[port].fifo.rxCnt;
  425. }

  426. /*************************************************************************************************
  427. * Name       : UartTxCnt
  428. * Describe   :
  429. * Input      :
  430. * Output     :
  431. * Create by  :
  432. * Moid   by  :
  433. *************************************************************************************************/
  434. uint16_t UartTxCnt(uint8_t port)
  435. {
  436.         return UartCfgTab[port].fifo.txCnt;
  437. }

  438. /****************************************************************************
  439. *************************** End of File *************************************
  440. ****************************************************************************/





















 楼主| zxm19820916 发表于 2013-3-12 10:32 | 显示全部楼层
我用的STM32M051C8芯片,你这个好复杂啊。我只要USART1的中断函数,中断里面处理接收中断还是发送中断,处理发送和接收(数组)。
香水城 发表于 2013-3-12 10:54 | 显示全部楼层
“Modbus Poll可以发送出数据,但模块进入不了接收中断”

请调试:如何得知主机发出数据了?在USART1的Rx引脚挂示波器看到数据了么?然后再看看USART1的中断和状态寄存器ISR如何。
 楼主| zxm19820916 发表于 2013-3-12 11:22 | 显示全部楼层
用示波器看到主机发出了数据。
最新发现:串口1和2的RTS脚无论拉高还是拉低,都输出高,而输出高即为发送模式。目前看来是这个原因导致进入不了接收中断。
 楼主| zxm19820916 发表于 2013-3-12 11:40 | 显示全部楼层
M0芯片的GPIO管脚配置和以前的差别比较大啊。
香水城 发表于 2013-3-12 12:26 | 显示全部楼层
F0的GPIO和F2保持一致的,只是比F1的GPIO多了每个引脚(pin)上的多路选择复用开关。

但是F0的USART比以往的F1、F2多了RS485的方向信号硬件控制。LZ可以参看USART->CR3中DEP和DEM位。以往的MCU的方向控制是由任意某个GPIO来由用户控制的。
 楼主| zxm19820916 发表于 2013-3-12 14:31 | 显示全部楼层
香主的意思是使用F0的USART的收、发方向控制是由USART自己控制的?
要怎么配置呢?
如果硬件上使用了RTS,是否可以用户软件拉高或拉低来控制收发?
罗菜鸟 发表于 2013-3-12 14:32 | 显示全部楼层
zxm19820916 发表于 2013-3-12 10:32
我用的STM32M051C8芯片,你这个好复杂啊。我只要USART1的中断函数,中断里面处理接收中断还是发送中断,处 ...
  1. /******************** (C) COPYRIGHT 2008 boost ********************
  2. * File Name          : usart.h
  3. * Author             : sms
  4. * Version            : V1.0.0
  5. * Date               : 2010年1月21日
  6. * Description        : Header for usart.c module
  7. ********************************************************************************/

  8. /* Define to prevent recursive inclusion ------------------------------------ */
  9. #ifndef __USART_H
  10. #define __USART_H

  11. #define  SERIAL_RXFULL_LINE  16
  12. #define  SERIAL_MIN_FIFO     32
  13. #define  SERIAL_MAX_FIFO     1024

  14. #define  UART_PORT_MAX            5

  15. #define  UART_PORT_1              0
  16. #define  UART_PORT_2              1
  17. #define  UART_PORT_3              2
  18. #define  UART_PORT_4              3
  19. #define  UART_PORT_5              4

  20. #define  UART_FLOW_EN             0x80
  21. #define  UART_2STOP_EN            0x40
  22. #define  UART_EVEN_EN             0x20
  23. #define  UART_ODD_EN              0x10


  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f10x.h"

  26. enum UartIsrMod{
  27.         TxEmpty,
  28.         RxFull,
  29.         RxTimeout,
  30.         };

  31. //typedef uint8_t UartBuf_t[28];




  32. extern void UartNvicSet(uint8_t port,uint8_t preprio,uint8_t subprio);
  33. extern void USART_ISR(uint8_t port);
  34. extern void UartConfig(uint8_t port,uint8_t *buf,uint16_t size,void (*isr)(uint8_t,enum UartIsrMod),FunctionalState dma);
  35. extern void UartOpen(uint8_t port,uint32_t baud,uint8_t mod);
  36. extern uint16_t UartRead(uint8_t port,uint8_t *data,uint16_t len);
  37. extern uint16_t UartWrite(uint8_t port,uint8_t *data,uint16_t len);
  38. /*
  39. extern void UartIsr(struct UartPort port);
  40. extern uint16_t UartRead(struct UartPort port,uint8_t *data,uint16_t len);
  41. extern uint16_t UartWrite(struct UartPort port,uint8_t *data,uint16_t len);
  42. extern uint16_t UartRxCnt(struct UartPort port);
  43. extern uint16_t UartTxCnt(struct UartPort port);
  44. extern void UartInit(struct UartPort port,uint16_t size,uint8_t *buf,void(*isr)(enum UartIsrMod));
  45. extern void UartPortConfig(struct UartPort port,uint8_t preprio,uint8_t subprio);
  46. */

  47. #endif /* __USART_H */

  48. /******************* (C) COPYRIGHT 2008 boost *****END OF FILE****/
我这个就是这样用的,中断程序处理收发中断,我忘了发头文件了
罗菜鸟 发表于 2013-3-12 14:34 | 显示全部楼层
zxm19820916 发表于 2013-3-12 14:31
香主的意思是使用F0的USART的收、发方向控制是由USART自己控制的?
要怎么配置呢?
如果硬件上使用了RTS, ...

你还不明白,你的程序卡死在发送里,ST系列的TXE和TC的用法与LPC这些不一样。
 楼主| zxm19820916 发表于 2013-3-12 14:43 | 显示全部楼层
不好意思,有点头晕了。不知道F0这芯片的USART该怎样配置中断收发了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

22

主题

299

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部