Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2233
    Avatartheremino
    Keymaster

    Hi everyone,
    I know quite well the CPP but I have no experience with Arduino, so I come here to seek help from experts.

    We wrote a library and a communication protocol with PC. The implementation went without much difficulty, but there is a detail that we could not solve in the intended way. We then had to resort to a solution that involves a greater workload of the CPU Arduino. Now the library is complete and works well, but since I'm a bit fussy, I can only suspect that there might be a better solution.

    – – –

    Everything stems from the function “serialEvent()”, that event is not, but only polled every lap of “loop()”.

    So, to make asynchronous serial communication, and independent of what the user types in “loop()”, we have prepared a second mode of operation called “AsyncMode”.

    In this operating mode, the buffer control of the serial is called by the interrupt of the timer zero comparator, that is, “ISR(TIMER0_COMPA_vect)”

    L'”AsyncMode” It is not always a good idea because it decreases the efficiency of a communication 25% and it might even create problems with some libraries that use the TIMER0_COMPA_vect.

    So the AsyncMode should be enabled only if necessary.

    So it would be a clean solution “#define AsyncMode” In the file “.ino”, and a conditional compilation in CPP library file, with someone “#ifdef AsyncMode”, to build only the necessary parts.

    – – –

    Ma, apparently, the files are compiled separately, and nothing of what is written in the file “.ino” You can change the behavior of pre-compilation of a library.

    We tried everything, #define, etc. constants.. We also tried to include a file “.h” definition… But the fundamental problem remains, no information passes from the file “.ino” the library during pre-compilation.

    Some idea?

    #7133
    Picmicro675Picmicro675
    Moderator

    L’idea, although a little later, would be to put an interrupt on the RX pin, as indeed the serials already do, even the soft-serial if I'm not mistaken. So when the signal goes low, for the start bit the serial is taken into consideration. No need to query timer0, but just note (in time) the falling edge of RX.
    However the define method is admissible and therefore can give the desired result. Although the compiler should only include what is actually instanced.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.