Arduino Mega 2560 Interrupts

Moderator: Benj

mnf
Valued Contributor
Valued Contributor
Posts: 503
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 278 times
Contact:

Arduino Mega 2560 Interrupts

Postby mnf » Thu Jul 18, 2019 7:17 pm

Been playing with a Wemos Mega 2560 + ESP8266 board.

The interrupts are not defined for UART2 and UART3 Rx inetrrupts. (The interrupt definitions stop at 7 - Rx for UART 3 is 9 Tx is 10 for example - see datasheet page 90 https://ww1.microchip.com/downloads/en/ ... asheet.pdf)

This makes life a little trickier as the ESP8266 is connected via UART3.

The nomenclature is also confused - in some places (interrupts) referring to UART0 (..UART3) but the UART component refers to channel 1..4 for UART0 to UART3 - it would be simpler if this was consistent?

Martin
These users thanked the author mnf for the post:
LeighM (Fri Jul 19, 2019 8:46 am)
Rating: 5.26%
 

User avatar
LeighM
Matrix Staff
Posts: 1864
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 436 times
Been thanked: 621 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby LeighM » Fri Jul 19, 2019 9:32 am

Hi Martin,
I've added Rx interrupt support for UART2 and UART3, fcd attached.
This will be an unofficial update until it gets pushed out on the auto system next week.
Hope it helps
Leigh
ps. As for the naming, this is tricky as we use the name "Channel 0" for the software UART.
It's all a bit historic and inconsistency between devices. It's something we will need think about.
Attachments
Arduino Mega 2560.fcdx
(30.13 KiB) Downloaded 17 times
These users thanked the author LeighM for the post:
mnf (Fri Jul 19, 2019 11:00 am)
Rating: 5.26%
 

mnf
Valued Contributor
Valued Contributor
Posts: 503
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 278 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby mnf » Fri Jul 19, 2019 11:01 am

Many thanks,

will test it this evening....

mnf
Valued Contributor
Valued Contributor
Posts: 503
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 278 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby mnf » Fri Jul 19, 2019 8:38 pm

Cool - that works.

I copied the new interrupt data to the mega r3 fcdx file and updated FC to use the new file (using reset data files to get it to copy the fcdx files to it's working directory- not sure this is the right way to go about this)

Then - I couldn't compile my program. I got a redefinition of __vector_54 error.

Starting again from scratch - I managed to re-enter the same program, and couldn't replicate the error. Recompiling the original program fails. New one works :-) Delete the original and carry on.

So now the Arduino side of the board can communicate with the ESP side - all is well!

Discovered why original code wouldn't work - attempting to communicate with ESP chip by sending 'AT' and receive a response (I got "AT+CIPMUX=0" success) Adding the WLAN_ESP8266 component - which uses the interrupt internally and must define using the same name :-(
. If ESP component is set up to use COM4 (correctly) then compilation fails (with redef error as above) - the WLAN_ESP8266 component is using the interrupt to retrieve data from the ESP chip. I wanted to check ESP chip was working correctly (having munged the firmware) - so wanted to just send AT commands. So need to do one or the another - manual 'AT' control or use the component. Now I know the ESP chip is working - the component beckons.... So - remove the new definitions for now.....

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 503
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 278 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby mnf » Sat Jul 20, 2019 7:01 pm

In fact the interrupt seems to set up correctly but the ESP8266 not working at all though. No response to AT commands or initialisation from ESP component.

The string received was the intialisation string sent by the ESP component - I happened to have it set to UART1 - so it just got sent to putty terminal on PC.

Anyone any success reflashing the firmware on an ESP device to run AT commands?
I can connect directly to the ESP8266 and it is not responding to AT commands - does seem to be running, it sets up a wireless network, and I can run micropython on it, so the hardware is OK.

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 503
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 278 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby mnf » Sun Jul 21, 2019 9:48 pm

... and finally got the ESP chip back up and running.

Can now run AT commands from the terminal :-) AT+GMR or AT+RST work for example.

Still can't get the Arduino and ESP sides talking however - ESP8266 component returns 0 and sending AT commands via an UART doesn't seem to have the desired result either.

An ESP-01 gives a MEM check fail on AT+RST too (via putty) - not had a succesful day :-(

Martin

maxtisc
Posts: 75
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 8 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby maxtisc » Sun Jul 21, 2019 10:19 pm

hello LeighM and everyone
I inform you that the interrupt problem of the serial port channel 2 on the rx pin of the arduino 2560 and 2560R3 is also present in the FC7 version, while in FC6 it works correctly, I hope that you solve soon

Thanks

User avatar
Benj
Matrix Staff
Posts: 14216
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4355 times
Been thanked: 4095 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby Benj » Mon Jul 22, 2019 10:19 am

Hi Martin,

Still can't get the Arduino and ESP sides talking however - ESP8266 component returns 0 and sending AT commands via an UART doesn't seem to have the desired result either.

An ESP-01 gives a MEM check fail on AT+RST too (via putty) - not had a succesful day :-(


Can you change the baud rate of the module using the terminal. 115200 is a hard baud rate for an AVR at 16MHz to achieve. Maybe start with 9600 and if this works then bump up the rate.

Hello,

I inform you that the interrupt problem of the serial port channel 2 on the rx pin of the arduino 2560 and 2560R3 is also present in the FC7 version, while in FC6 it works correctly, I hope that you solve soon


Can you send us the program that demonstrates the problem?
These users thanked the author Benj for the post:
mnf (Mon Jul 22, 2019 8:56 pm)
Rating: 5.26%
 

mnf
Valued Contributor
Valued Contributor
Posts: 503
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 278 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby mnf » Mon Jul 22, 2019 8:30 pm

Can you change the baud rate of the module using the terminal. 115200 is a hard baud rate for an AVR at 16MHz to achieve. Maybe start with 9600 and if this works then bump up the rate.


- Good idea. All working now. Program reports ESP8266 ready for action and connected to my WiFi seconds later.

Only tried 9600 (set using

Code: Select all

AT+UART_DEF=9600,8,1,0,0
sent via putty terminal to the ESP chip - will try faster later

Martin
These users thanked the author mnf for the post:
Benj (Tue Jul 23, 2019 10:34 am)
Rating: 5.26%
 

maxtisc
Posts: 75
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 8 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby maxtisc » Tue Jul 23, 2019 12:12 am

hello benji
I also attach the 2 files, precise that the files were not imported but created all over again. The function in short is that pressing the send key to arduino a key recognition code and arduino sends a code to the display to open the new page
thanks for your interest, I hope I was clear

I wanted to upload 2 short videos but he won't let me, it would have been clearer

I hope it's not just my distraction and it won't waste your time

good job
Attachments
TTi-nelloFC6.fcfx
(11.71 KiB) Downloaded 13 times
TTi-nelloFC7.fcfx
(16.28 KiB) Downloaded 16 times

User avatar
LeighM
Matrix Staff
Posts: 1864
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 436 times
Been thanked: 621 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby LeighM » Tue Jul 23, 2019 8:19 am

uart_wrong.jpg
uart_wrong.jpg (37.55 KiB) Viewed 535 times

uart_correct.jpg
uart_correct.jpg (39.08 KiB) Viewed 535 times

maxtisc
Posts: 75
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 8 times
Contact:

Re: Arduino Mega 2560 Interrupts

Postby maxtisc » Tue Jul 23, 2019 5:06 pm

hi Benji
in fact I already use channel 2 (tx port_D2 rx port D3) in both the software, I also did another test, I compiled the fc6 file with fc7 but even this didn't work, recompiling it with fc6 returns to work, I managed to attach the two videos, I hope they can help you.
Attachments
FC7.zip
(2.6 MiB) Downloaded 18 times
FC6.zip
(1.51 MiB) Downloaded 9 times