Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Mega (sorry, not Teensy) usage of Timer Three and AltSoftSerial together

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Posts
    3

    Mega (sorry, not Teensy) usage of Timer Three and AltSoftSerial together

    Hi,

    This project barely exists as some test code that sends out serial messages, so I'm asking ahead of time before I put more time into this if I'm ok doing what I'm doing.

    Here's what I intend to use and why:

    Requirements: I need to communicate with four rs-232 devices, controlled from udp/ip over wired ethernet, and I need timeouts on the serial ports. They don't have to be accurate to 1 ms, but I generally need to know when so many seconds are up. I also *would like* to use a serial port for regular debugging.

    - Mega 2560: Because it has 4 hardware serial Ports
    - W5100 Shield: Because it has Wired Ethernet, and uses SPI - so therefore pins 10, 11, 12, and 13 (I think) on the Mega
    - Use Serial for normal uploading and debug printing
    - Use Serial1, Serial2, Serial3, and AltSoftSerial on pins 46 and 48 of the Mega to talk to the four devices
    - Can't use Timer1 due to AltSoftSerial using the 16 bit Timer 1 (If I understand correctly)
    - Using PJRC's Timer3 due to the above 16 bit timer issue. I figure it's better than the stock Timer3, and more likely to work together with Paul's AltSoftSerial.

    Questions and comments:

    Where am I being stupid?
    Note: as long as I can get second accuracy or so I don't care if my timer is 8 bit or 16 bit.
    Alternatively I could use Serial, Serial1, Serial2, and Serial3 to communicate with my four devices via the hardware ports and use the AltSoftSerial port as a debugging port if I had to - this has the disadvantage of not being able to use the built-in, while-connected to USB Serial debug stuff, and the advantage that all four devices will get the exact same handling via serial (all using hardware ports) if that's truly useful (may not be worth the effort).
    I could use SoftwareSerial instead of AltSoftSerial and transmit out the port only for debug.

    I didn't see a Mega (or non-Teensy) forum, so I posted here anyway...sorry.

    THANK YOU!
    Jeff

  2. #2
    Junior Member
    Join Date
    Sep 2019
    Posts
    3

    Just making sure it's clear

    I mostly need to know that the TimerThree and AltSoftSerial libraries can co-exist working on the Mega. \

    Thank you!
    Jeff


    Quote Originally Posted by DrychronRed View Post
    Hi,

    This project barely exists as some test code that sends out serial messages, so I'm asking ahead of time before I put more time into this if I'm ok doing what I'm doing.

    Here's what I intend to use and why:

    Requirements: I need to communicate with four rs-232 devices, controlled from udp/ip over wired ethernet, and I need timeouts on the serial ports. They don't have to be accurate to 1 ms, but I generally need to know when so many seconds are up. I also *would like* to use a serial port for regular debugging.

    - Mega 2560: Because it has 4 hardware serial Ports
    - W5100 Shield: Because it has Wired Ethernet, and uses SPI - so therefore pins 10, 11, 12, and 13 (I think) on the Mega
    - Use Serial for normal uploading and debug printing
    - Use Serial1, Serial2, Serial3, and AltSoftSerial on pins 46 and 48 of the Mega to talk to the four devices
    - Can't use Timer1 due to AltSoftSerial using the 16 bit Timer 1 (If I understand correctly)
    - Using PJRC's Timer3 due to the above 16 bit timer issue. I figure it's better than the stock Timer3, and more likely to work together with Paul's AltSoftSerial.

    Questions and comments:

    Where am I being stupid?
    Note: as long as I can get second accuracy or so I don't care if my timer is 8 bit or 16 bit.
    Alternatively I could use Serial, Serial1, Serial2, and Serial3 to communicate with my four devices via the hardware ports and use the AltSoftSerial port as a debugging port if I had to - this has the disadvantage of not being able to use the built-in, while-connected to USB Serial debug stuff, and the advantage that all four devices will get the exact same handling via serial (all using hardware ports) if that's truly useful (may not be worth the effort).
    I could use SoftwareSerial instead of AltSoftSerial and transmit out the port only for debug.

    I didn't see a Mega (or non-Teensy) forum, so I posted here anyway...sorry.

    THANK YOU!
    Jeff

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,554
    Look for the file known_16bit_timers.h. Maybe you can make TimerThree not conflict by editing those defines.

    I also put a similar config file in AltSoftSerial. But most of the other timers on Mega are unusable. You would need to solder wires to the pins Arduino decided not to route.

    Again, I can't say for sure if this will work. The most support I can give you for customizing on Arduino Mega is this quick mention of the files to edit, and the pin limitations for AltSoftSerial. If you do get it to work, or learn more, maybe reply here to share that Mega-specific knowledge?

  4. #4
    Junior Member
    Join Date
    Sep 2019
    Posts
    3
    Paul et all,

    Ok, that's exactly what I needed to hear. In that case, I am going to use TimerOne for the timings I need, and not use AltSoftSerial at all. I will send debug messages out the UDP port and monitor them from a PC program on a certain logical port.

    Thank you. Again, that's exactly what I needed to know. I was wrongly thinking that the documentation was saying that only Timer 1 (16 bit) was taken up by AltSoftSerial. I am glad I can spend the time coding the UDP messages and not struggling with getting a fifth serial port to work at all while having proper timeout timings.

    Thanks so much for your time!

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,554
    Maybe try a Teensy for the next project? So much more capability than Mega!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •