Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为ATMEGA128 uc实现接收中断超时_C_Embedded - Fatal编程技术网

为ATMEGA128 uc实现接收中断超时

为ATMEGA128 uc实现接收中断超时,c,embedded,C,Embedded,我正在使用ATMEGA128微控制器和AVR工作室为我的项目。我使用一个接收中断ISR_USART0来接收8字节的数据作为一个数据包,这个中断在它接收完数据后被调用。数据用于刺激一些执行器。这是中断程序。 现在,我想在这个例程中添加一个10毫秒的超时,这样一旦收到第一个字节,它就开始计算超时,这持续10毫秒,然后软件跳过等待字节的过程,返回到主循环。 作为一名新手,我发现在中断例程中实现这样一个超时时,有关中断的数据非常少……有人能建议最好的实现方法吗 ISR(USART0_RX_vect) {

我正在使用ATMEGA128微控制器和AVR工作室为我的项目。我使用一个接收中断ISR_USART0来接收8字节的数据作为一个数据包,这个中断在它接收完数据后被调用。数据用于刺激一些执行器。这是中断程序。 现在,我想在这个例程中添加一个10毫秒的超时,这样一旦收到第一个字节,它就开始计算超时,这持续10毫秒,然后软件跳过等待字节的过程,返回到主循环。 作为一名新手,我发现在中断例程中实现这样一个超时时,有关中断的数据非常少……有人能建议最好的实现方法吗

ISR(USART0_RX_vect)
{   
    uint8_t u8temp;
    u8temp=UDR0;
    data_count++;    
    //UDR0=u8temp;
    //check if period char or end of buffer
    if    (BufferWrite(&buf, u8temp)==1){
           Buffer_OverFlow_ERROR=1; TRANSMISSION_ERROR [6]=Buffer_OverFlow_ERROR;
           MT_ERROR_FLAGS_INIT();BufferInit(&buf);data_count=0;REC_ERROR_FLAG=0;}  

    if (u8temp==0x58){
         BufferSort(&buf);BufferInit(&buf);
         REC_ERROR_FLAG=0;data_count=0;//PORTA|=(1<<PORTA3);
        }

        /*else if{
        REC_ERROR_FLAG=0;BufferInit(&buf);*/


}
ISR(USART0\u RX\u vect)
{   
uint8_u8温度;
u8temp=UDR0;
数据计数++;
//UDR0=u8temp;
//检查周期是否为字符或缓冲区结束
if(BufferWrite(&buf,u8temp)==1){
缓冲区溢出错误=1;传输错误[6]=缓冲区溢出错误;
MT_ERROR_FLAGS_INIT();BufferInit(&buf);data_count=0;REC_ERROR_FLAG=0;}
如果(u8temp==0x58){
BufferSort(&buf);BufferInit(&buf);

REC_ERROR_FLAG=0;data_count=0;//PORTA |=(1我将使用这样一个函数来实现从UART接收8个字节,超时为n毫秒

charbuf[8],c=0;
无符号整数t=65535,th=65535;
做{

如果(UCSRA&(1),除非USART提供硬件超时,否则您需要额外的计时器(软件或硬件)。但是,这对于堆栈溢出来说太宽了。请自行进行一些研究。
char buf[8], c = 0;
unsigned int t = 65535, th = 65535;

do {
    if (UCSRA & (1 << RXC))
        buf[c++] = UDR;
    if (!th--) t--;
} while ((c < 8) && t);