Page 1 of 1

add a second circular buffer?

Posted: Mon Apr 03, 2023 8:08 pm
by flowcode-developer
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

Re: add a second circular buffer?

Posted: Mon Apr 03, 2023 8:54 pm
by mnfisher
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

Re: add a second circular buffer?

Posted: Mon Apr 03, 2023 9:43 pm
by flowcode-developer
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!

Re: add a second circular buffer?

Posted: Mon Apr 03, 2023 9:55 pm
by flowcode-developer
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?

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

}

Re: add a second circular buffer?

Posted: Mon Apr 03, 2023 10:09 pm
by mnfisher
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...

Re: add a second circular buffer?

Posted: Tue Apr 04, 2023 10:20 am
by BenR
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.