Receive on UART 2 and send at UART 1

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Receive on UART 2 and send at UART 1

Post by Marcel »

Hello,

I’m facing a problem with reading data from a serial sensor and sending the received data through. with a serial bluetooth module. I’m using a PIC 18f6722 and Flowcode V4.
I connect UART 1 at a bluetooth device and UART 2 at the serial sensor. The sensor send continually data. It sends 3 packets a second. Each packet contains 25 lines of 5 bytes. I read UART 2 and if the data is <= 255 I send the data with UART 1. The problem is that I’m losing data. I think that when I send the data at UART 1 I’m losing data that’s present on UART 2. Is there a solution to buffer the data at UART 2 while I’m sending at UART 1??

Thanks, Marcel

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: Receive on UART 2 and send at UART 1

Post by Benj »

Hello,

The RXINT interrupts for hardware UARTs should be available as part of the standard interrupt set for your target device. If you enable this interrupt then it will trigger a macro call every time a byte is received. If you put the received data bytes into a circular buffer then you can continue to receive bytes while you are transmitting data.

I have posted a basic example of a circular buffer onto the forums here.
http://www.matrixmultimedia.com/mmforum ... ers#p33484

In your example the 5 second delay could be replaced by transmitting data over the alternate UART.

I think you need v5 to open the file but the demo version of v5 should allow you to see how the code has been put together.

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello Ben,

I have put your cicular-buffer v5 in v4, but it will not work. Maybe I'm doing something wrong.
I have attached the program. Could you please look whats going wrong.

Kind Regards.
Attachments
Circular-buffer.fcf
(10 KiB) Downloaded 333 times

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello,

In your example I have the 5 sec. delay replaced by the UART-1 for transmitting data, I read data by UART-2.
I only receive 00 00 ...... 00
I think the interrupt will not start, it's not working. Maybe you could help me.
Thank you.

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: Receive on UART 2 and send at UART 1

Post by Benj »

Hello Marcel,

I have made some very minor changes to the program by moving the sendRS232 macro into the next while loop and disabled the Extended CPU Enable setting from the config settings. Other then that I can't really see any reason why the program wouldn't run as expected.

If this still isn't working on the hardware then maybe send me a copy of your output C file and I will compare with the file that my Flowcode is producing to make sure there is nothing going wrong with the code generation.
Attachments
Circular-buffer.fcf
(10 KiB) Downloaded 315 times

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello Ben,

If I move the sendRS232 macro into the next while loop, I receive nothing.
I have attached the program and the C file.
Attachments
Circular-buffer.c
(38.58 KiB) Downloaded 312 times
Circular-buffer.fcf
(11.5 KiB) Downloaded 326 times

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello Ben,

At the end of the c code there is this warning "This interrupt has previously been enabled, so the macro <rx_uart> may never get called."

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: Receive on UART 2 and send at UART 1

Post by Benj »

At the end of the c code there is this warning "This interrupt has previously been enabled, so the macro <rx_uart> may never get called."
This is just a warning that gets added to the Flowcode compiler messages window if the same interrupt is enabled more then once.

Maybe try adding this in a component macro in Main directly after enabling the interrupt.

UART 2 Receive Byte.

Followed by a C icon

cr_bit(pir3, RC2IF);

I've been through the datasheet but can't see any other reasons as to why the code wouldn't be working.

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello Ben,

I'am still struggling with this, the program is not working.
Do I need to fill in a return value in the component macro UART 2 Receive Byte ?
I have attached the new program.
Attachments
RS232test-circular-buffer.fcf
(11.5 KiB) Downloaded 327 times

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello,

I have test the program but the interrupt will not start. Is there a possibility to test the interrupt?
Is it possible to give an interrupt on RX2 instead of RX1?

Thanks, Marcel

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: Receive on UART 2 and send at UART 1

Post by Benj »

Hi Marcel,

I believe I may have found the cause of the problem. Try adding the following line of code in a C icon at the start of your program and I'm hoping this should allow the interrupt to fire up.

st_bit(intcon, PEIE);

We have recently tackled this problem in the FCD files and I just thought the two may be linked. Checking your C code from your FCF file it seems they are.

Is the interrupt on RX1 currently working?

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello Ben,

YES, now the interrupt on RXINT2 is working. I need now further testing.

Thanks for your help so far.

Marcel
Flowcode V4 User
Posts: 23
Joined: Wed Aug 24, 2011 1:22 pm
Has thanked: 2 times
Contact:

Re: Receive on UART 2 and send at UART 1

Post by Marcel »

Hello Ben,

The RXint2 is working like I suspect. So that problem is solved. But the next problem is already there. I like to use a timer interrupt to sample a signal on my AD pin. But this interrupt routine seem to have the same problem. In simulation it works fine but in the PIC it doesn’t work at all. Do I have to ad a line of C-code to make it work, Just like the RXint ?
Attachments
RS232test-ADC.fcf
(11.5 KiB) Downloaded 255 times

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: Receive on UART 2 and send at UART 1

Post by Benj »

Hello Marcel,

No C code for the timers but I think I have spotted the issue.

Go into the properties for the interrupt enable icon and then go into the timer interrupt properties.

In here switch the Clock source from T0CKI to Internal Clock and hopefully the interrupt should then fire up correctly.

Let me know if you have any problems.

Post Reply