Cypress技术论坛
直播中

刘溪

8年用户 192经验值
私信 关注
[问答]

如何在UART的ISR中禁用中断

嗨,大家好,
我正在使用一些ISR的UART UART SCB模式VER 3.2并使用下面的代码
UIT8标志=0;
CysISR(UART中断)
{
UIT32源=0;
旗=1;
UARTHUUARTPUSTSHIPE(“nFLAG=1  rn”);
源= uARTHEGETRXBASTUSTORKEASKASKED();
UARTHI CURLRX中断源(源);
UARTHUUARTPTCCHAR(UARTHI UARTEGETCHARE());
/*’结尾’*
}
int()
{
utiN 32 CH;
UARTHART START();
UARTHI SCBIIQL SARTEX(UART中断);
//uARTHARRXIISRSARTEXTEX(UART中断);
*通过UART**发送字符串
CyGloalActuabess;/*取消注释此行以启用全局中断。*/
UTARTUAUTARTPT字符串(“R**************************************************************************************************************************************************************************************************************************************************************************************************************************************************
UARTHUUARTPUSTSHIPE(“UART IMAILISIDER RN”);
(;)
{
CH=UARTHI UARTGETHARCH();
If(FLAG=1)
{
旗=0;
CH=UARTHI UARTGETHARCH();
UARTHI UARTARPTCHA(CH);
UARTHUUARTPUSTSHIPE(“nFLAG=0  rn”);
}
}
}
观察:
1。控制不是来自ISR“CysISR(UART中断)”
2。无法清除中断
请帮助

以上来自于百度翻译


     以下为原文
  Hi all,
I am using some ISR for UART UART SCB Mode ver 3.2 and using the following code

uint8 flag = 0;


CY_ISR(uartInterrupt)
{
    uint32 source = 0;
     flag = 1;
   
    UART_UartPutString("nFlag = 1rn");
    source = UART_GetRxInterruptSourceMasked();
    UART_ClearRxInterruptSource(source);
   
    UART_UartPutChar(UART_UartGetChar());
    /* `#END` */
}

int main()
{
   
     uint32 ch;
    UART_Start();
    UART_SCB_IRQ_StartEx(uartInterrupt);
    //UART_RX_ISR_StartEx(uartInterrupt);
   
    /* Transmit string through UART */
    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
  
    UART_UartPutString ("rn***********************************************************************************rn");
    UART_UartPutString ("UART Initialisedrrn");

    for (;;)
    {
        ch = UART_UartGetChar();

         if(flag == 1)
        {
          flag = 0;
          ch = UART_UartGetChar();
          UART_UartPutChar(ch);
          UART_UartPutString("nFlag = 0rn");
        }      


    }
}

Observation :

1. Control is not coming out from ISR "CY_ISR(uartInterrupt)"
2. Could not able to clear interrupt

Please help

回帖(3)

王琳

2018-12-21 15:39:15
一般情况下:
不要在中断处理程序中使用冗长代码。与普通CPU速度相比,在UART上发送数据非常慢。
不要在中断处理程序中重复。如果你做了类似的事情,由于缺少一些信息,这并不十分清楚。
在中断处理程序中更改的每个全局变量都应该声明为“易失性”。所以你需要
挥发性UIT8标记=0;
这将阻止编译器优化对变量标志的冗余访问。请看这里。
能否请您发布您的完整项目,以便我们都可以看看您的所有设置。为此,使用
创建者-gt;文件& gt;创建工作区束(最小)
并附加生成的文件。
鲍勃

以上来自于百度翻译


     以下为原文
  Generally:
Do not use lengthy code in an interrupt handler. Sending data over the UART is very slow compared to normal CPU speed.
 
Do not recurse in an interrupt handler. It is not quite clear due to some missing information if you do something like that.
 
Every global variable that is changed in an interrupt handler should be declared as "volatile". so you need
volatile uint8 flag = 0;
This will prevent you from compiler optimizing-out redundant accesses to the variable flag. See here.
 
Can you please post your complete project so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
 
Bob
举报

刘溪

2018-12-21 15:46:16
引用: ncmza 发表于 2018-12-21 18:52
一般情况下:
不要在中断处理程序中使用冗长代码。与普通CPU速度相比,在UART上发送数据非常慢。
不要在中断处理程序中重复。如果你做了类似的事情,由于缺少一些信息,这并不十分清楚。

感谢答复和建议,我将改变代码作为易失性UIT8标志=0;
SCBUUARCOMDE01.CYDSn.ZIP
2兆字节

以上来自于百度翻译


     以下为原文
  Thanks for reply and suggestion i will change in code as volatile uint8 flag = 0;


举报

刘溪

2018-12-21 15:57:33
引用: huzp 发表于 2018-12-21 18:59
感谢答复和建议,我将改变代码作为易失性UIT8标志=0;
SCBUUARCOMDE01.CYDSn.ZIP
2兆字节

嗨,鲍伯
你能用附件来解决这个问题吗?
伪装

以上来自于百度翻译


     以下为原文
  Hi Bob
 
Can you address the issue with ref to attached code?
 
Sham
举报

更多回帖

发帖
×
20
完善资料,
赚取积分