Hi,
I am programming an AVR ATMEGA2560 with AVR chipset. My program is supposed to poll two devices on (inspectra)ch1 and ch3(weather) via UART. There is a Modbus slave that is sending out the cleaned info on ModbusSlave ch2. I have been successful with inspectra and ModbusSlave working in tandem. I am using a circular buffer to capture the info. Now I am adding another device the weather station on ch3.
My question is since I am adding another device do I need to add a 2nd circular buffer? If I do would I add it in just like the first buffer as a interrupt?
I have attached my work below.
Thank you
add a second circular buffer?
-
- Posts: 37
- http://meble-kuchenne.info.pl
- Joined: Thu Feb 02, 2023 9:32 pm
- Has thanked: 19 times
- Been thanked: 3 times
add a second circular buffer?
- Attachments
-
- inspectra5.fcfx
- current work
- (71.78 KiB) Downloaded 296 times
-
- proof that avr is sending message
- logic_send loop1.PNG (94.45 KiB) Viewed 2643 times
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: add a second circular buffer?
Hi,
Yes - you can have multiple circular buffers. The data will be 'fed' into these from an interrupt handler (uart_rx on RXInt0 in your code). If you have data coming into a second UART - then it would be easiest to have a second buffer and use a RxInt to load the data into it on receive. Note that FC doesn't seem to give a default interrupt handler for RxInt2 (UART channel 3 :-; ) - but it is possible to handle it using custom code ..
Martin
Yes - you can have multiple circular buffers. The data will be 'fed' into these from an interrupt handler (uart_rx on RXInt0 in your code). If you have data coming into a second UART - then it would be easiest to have a second buffer and use a RxInt to load the data into it on receive. Note that FC doesn't seem to give a default interrupt handler for RxInt2 (UART channel 3 :-; ) - but it is possible to handle it using custom code ..
Martin
-
- Posts: 37
- Joined: Thu Feb 02, 2023 9:32 pm
- Has thanked: 19 times
- Been thanked: 3 times
Re: add a second circular buffer?
Hi so if I understand correctly I should not do what I did below? I need to make an RXINT2 since FC does not have one made for me to use. Is there a way I can reverse engineer RXINT1 or RXINT0 so I can make an RXINT2?
Thank you!
Thank you!
- Attachments
-
- rxUART.PNG (128.74 KiB) Viewed 2631 times
-
- Posts: 37
- Joined: Thu Feb 02, 2023 9:32 pm
- Has thanked: 19 times
- Been thanked: 3 times
Re: add a second circular buffer?
I found this article on custom interrupts for AVR. https://www.flowcode.co.uk/wiki/index.p ... upts_-_AVR
How can I customize this for channel 3?
How can I customize this for channel 3?
Code: Select all
Enable code:
UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts
Disable code:
//UCSRB &= ~(1 << RXCIE); // disable USART receive interrupts
Handler code:
ISR(USART_RXC_vect) // USART receive vector
{
FCM_%n(); // Call Flowcode Macro
}
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: add a second circular buffer?
Take a look at https://www.matrixtsl.com/wiki/index.ph ... upts_-_AVR
Also if you right click the enable interrupt block and select customise C code to look under the hood...
Also if you right click the enable interrupt block and select customise C code to look under the hood...
-
- Matrix Staff
- Posts: 1924
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 684 times
Re: add a second circular buffer?
Hello,
I've now added the missing UART interrupts for channels 3 and 4 as well as TX interrupts for all four UARTs. The update should now be available via the Help -> Library updates.
I've now added the missing UART interrupts for channels 3 and 4 as well as TX interrupts for all four UARTs. The update should now be available via the Help -> Library updates.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel