Arduino Mega 2560 Interrupts

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Arduino Mega 2560 Interrupts

Post by mnf »

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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by LeighM »

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
(29.5 KiB) Downloaded 261 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by mnf »

Many thanks,

will test it this evening....

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by mnf »

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: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by mnf »

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: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by mnf »

... 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: 110
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 9 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by maxtisc »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by Benj »

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?

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by mnf »

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

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

Re: Arduino Mega 2560 Interrupts

Post by maxtisc »

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 164 times
TTi-nelloFC7.fcfx
(16.28 KiB) Downloaded 155 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Mega 2560 Interrupts

Post by LeighM »

uart_wrong.jpg
uart_wrong.jpg (37.55 KiB) Viewed 6047 times
uart_correct.jpg
uart_correct.jpg (39.08 KiB) Viewed 6047 times

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

Re: Arduino Mega 2560 Interrupts

Post by maxtisc »

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 156 times
FC6.zip
(1.51 MiB) Downloaded 137 times

Post Reply