读书 串口事件疑问-Arduino中文社区 - Powered by Discuz! Archiver

sjiliang 发表于 2016-3-17 08:04

读书 串口事件疑问

读中发觉arduino可以使用伪事件serial.Event()解决串口数据传输及时响应。
不解内容有二:
一。书中P114程序中没有启动中断语句(类似。。attachinterrupt()的添加中断),后面如何响应终端呢。
二。P113页,“对于MEGA控制器还可以使用以下形式。 void serialEvent1(){}void serialEvent2(){}void serialEvent3(){}"
      如何针对切入具体的对应中断,没有对应内容和事例。

以上内容还需大师指教,先谢了。

奈何col 发表于 2016-3-17 08:56

书中有论述,这是个伪事件,并不能实时响应

badboyback 发表于 2016-3-17 15:49

伪中断,两次loop之间执行一次serial.Event(),可以看官方的函数说明

ardino_chen 发表于 2019-9-17 22:00

是否可以理解为,执行顺序为loop ---事件----loop这样一个循环??

长野惊风 发表于 2020-2-19 11:46

在arduino安装目录下hardware\arduino\avr\cores\arduino文件夹里我找到main.cpp这个文件
/*
main.cpp - Main loop for Arduino sketches
Copyright (c) 2005-2013 Arduino Team.All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA
*/

#include <Arduino.h>

// Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (* /*func*/ )()) { return 0; }

// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }

void setupUSB() __attribute__((weak));
void setupUSB() { }

int main(void)
{
        init();

        initVariant();

#if defined(USBCON)
        USBDevice.attach();
#endif
       
        setup();
   
        for (;;) {
                loop();
                if (serialEventRun) serialEventRun();
        }
      
        return 0;
}



由此得知,串口事件在两次loop之间执行。
应该没错。
页: [1]
查看完整版本: 读书 串口事件疑问