Is there an annular queue serial transmission data that is needed yet

 

 

 

1. A question, the following program has no BUG

 

 

 

 

 2. circular queue solves the beginning interrupt transmission data coverage issue, but it has introduced a new problem

 

3. Then look interrupt transmission

 

 

 

4. think thought to understand what is the problem

 

 

 The transmission data 1 and 2 transmit data without delay between ......

Do the procedure when we often encounter various places serial data needs to be sent, but if a send function to send two finish, then immediately sent another .......

This time there is a problem, send a device, it could have been the correct data, but because such a whole, the data became wrong.

 

Well now to solve this problem

The main purpose is to transmit the data also need to manage it, so that there is the time interval between data transmission

Well, plus a circular queue

The circular queue it, recording the number of data to be transmitted

 

Now there are two circular queue,

Circular queue storing a number of data, we started using is

Another circular queue is to store the number of data to be transmitted

 

So each time you send data becomes

 

 

 

Then interrupt transmission inside

Usart1ManageSendDatLen the number of data records is transmitted

Send when Usart1ManageSendDatLen -, becomes 0, it means that the data sent over now

The number of data transmission is acquired timer inside

 

 

 

    if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
  {        
    if(Usart1ManageSendDatLen>0 && rbCanRead(&Uart1rb)>0)//发送的数据个数大于0 ,环形队列可以读出来数据
    {
      rbRead(&Uart1rb, &Usart1SendDat, 1);//读取一个数据
      USART_SendData(USART1, Usart1SendDat);//发送
            Usart1ManageSendDatLen -- ;//发送的数据个数减一
    }
    else
    {
      //发送字节结束
      USART_ClearITPendingBit(USART1,USART_IT_TXE);
      USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
      USART_ITConfig(USART1, USART_IT_TC, ENABLE);
            Usart1ManageSendDatLen = 0;//发送完成,清零
    }
  }
  //发送完成
  if (USART_GetITStatus(USART1, USART_IT_TC) != RESET)
  {
    USART_ClearITPendingBit(USART1,USART_IT_TC);
    USART_ITConfig(USART1, USART_IT_TC, DISABLE);
  }

 

 

 

 

 

 

 

定时器里面

 

Usart1ManageSendDatLen = 0;说明发送完数据了

然后 利用变量累加进行延时

延时10Ms(自行调节,该变量控制两条数据发送的时间间隔)

读取下保存每次发送多少数据的那个环形队列

取出来这次要发送的数据个数然后赋值给 Usart1ManageSendDatLen 

然后打开发送中断

发送中断发送完数据又会出现 Usart1ManageSendDatLen = 0;

然后一直这样工作

这样的话,多条同时填充的数据,发送每一条数据的时间间隔是10Ms

不会再出现整个发出去的情况了!

 

 

 

 

 

    if(Usart1ManageSendDatLen == 0)//没有在发送数据
    {
        Usart1ManageSendDelayCnt++;
        if(Usart1ManageSendDelayCnt>=10)//延迟10Ms
        {
            Usart1ManageSendDelayCnt = 0;
            if(rbCanRead(&Uart1rbManage)>0)//是不是有需要发送的数据
            {
                //取出这次要发送的数据个数
                rbRead(&Uart1rbManage, &Usart1ManageSendDatLen, 1);
                USART_ITConfig(USART1, USART_IT_TXE, ENABLE);//打开发送中断
            }
            else
            {
                //没有数据发送的时候1Ms判断一次,延迟1Ms
              Usart1ManageSendDelayCnt=10;
            }
        }
    }

 

 

测试

如果想测试的明显

 

 

 

 

 

 

 

现在说下现在这个程序带来的新问题

1.发送数据最低延迟 1Ms

  其实这个延迟再加点变量就可以解决,但是呢,我怕加多了,大家理解起来困难....

  所以先这样吧,有兴趣自己去修改

 

 

 

 

 

 

2.无疑又增加了内存开销

 

 

 

 

 

 

 

 

3.这是是我最不愿意的事情

  影响了printf一开始使用的中断发送

  因为一开始是不停的插入一个数据,然后中断发出去

  现在不可以这样了,还需要想办法呀

  需要一次性得到printf发送的内容,然后填充到环形队列里面.............

  真不好搞的话,还是用 sprintf 把,把数据序列化到一个数组里面,然后

  发送的数据个数 = sprintf(数组,XXXXXXX)

  PutData(&Uart1rb,NULL,数组,发送的数据个数);//数据写入环形队列
  SendCount[0] = 发送的数据个数;//这次发送的数据个数
  PutData(&Uart1rbManage,NULL,SendCount,1);//数据写入环形队列,记录这次要发送的数据个数

 

 

 

Guess you like

Origin www.cnblogs.com/yangfengwu/p/11769059.html