Receive on UART 2 and send at UART 1
Moderator: Benj
Receive on UART 2 and send at UART 1
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Receive on UART 2 and send at UART 1
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.
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 366 times
Re: Receive on UART 2 and send at UART 1
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.
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.
- 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
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.
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 367 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Receive on UART 2 and send at UART 1
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.
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 349 times
-
- Circular-buffer.fcf
- (11.5 KiB) Downloaded 386 times
Re: Receive on UART 2 and send at UART 1
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."
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."
- 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
This is just a warning that gets added to the Flowcode compiler messages window if the same interrupt is enabled more then once.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."
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Receive on UART 2 and send at UART 1
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.
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 403 times
Re: Receive on UART 2 and send at UART 1
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
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
- 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
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Receive on UART 2 and send at UART 1
Hello Ben,
YES, now the interrupt on RXINT2 is working. I need now further testing.
Thanks for your help so far.
YES, now the interrupt on RXINT2 is working. I need now further testing.
Thanks for your help so far.
Re: Receive on UART 2 and send at UART 1
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 ?
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 335 times
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel