Menu

More than 2 serial ports on ATMega162

Help
2022-11-07
2022-11-07
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-11-07

    Hello ... Since the Mega162 has already 2 hardware serial ports, I wonder if it should be possible to define up to 3 additional software ports ? And should these ports be numbered 1, 2, 3 or 3, 4, 5 ? Thanks for any answer ...

     
  • Anobium

    Anobium - 2022-11-07

    Software Serial (Optimised) uses the numbering scheme of 1, 2 and 3. You therefore can use the two hardware serial plus the three software serial. And, you would address using the defined scheme.

    HSerPrint "usart1", 1
    HSerPrint "usart1", 2
    Ser1Print "sw usart1"
    Ser2Print "sw usart2"
    Ser3Print "sw usart3"

    This should work.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-11-07

    Thanks, I will test as soon as I have all the hardware available ...

     
  • Chris Roper

    Chris Roper - 2022-11-07

    If you wanted to use your number sequence Then use Anobiums code as above but to make your code readable you can additionally use #Define like this:

    #define PrintPort1 HSerPrint "usart1", 1
    #define PrintPort2 HSerPrint "usart2", 2
    #define PrintPort3 Ser1Print "sw usart1"
    #define PrintPort4 Ser2Print "sw usart2"
    #define PrintPort5 Ser3Print "sw usart3"
    
     
    • Anobium

      Anobium - 2022-11-07

      Clever.... very clever. But, all the constants would be in UPPERCASE. :-)

      So, you define the constants to redefine all five serial comms line. Should work!

      What a clever idea.

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-11-07

    Meanwhile I tested the PRINCIPLE with a Mega8515, the Nextion connected to Hardware port1, an Emic 2 connected to the pins used by serial port2 on the Mega 162 (2 and 3 on PortC), with these pins defined as software port1 : IT WORKS ! And thanks to Chris Roper, but I will use all serial communications in Subs, so the main program will not be "contaminated" ...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.