Possible to have both USB Serial and UART active?
Moderator: Benj
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Possible to have both USB Serial and UART active?
I would like to use both the USB serial (PC<>MCU) and UART(MCU<>MCU) but it appears that once the USB is initialized/connected, a RS232 send or receive macro call causes a MCU lockup. Should I be able to use both?
Thanks,
Grant
Thanks,
Grant
- 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: Possible to have both USB Serial and UART active?
Hello Grant,
This should work fine, I often use both components to create a bridge between my PC and a UART based device.
Can you post your program so we can have a look into what might be going wrong.
This should work fine, I often use both components to create a bridge between my PC and a UART based device.
Can you post your program so we can have a look into what might be going wrong.
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
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Re: Possible to have both USB Serial and UART active?
Hi Benj,
Here is a pared down version of the program that acts as the bridge. I can transmit data back and forth on the UART fine until the USB is active. It seems to hang once it gets to the RS232 macros at the end of the Update_Current_Limit macro.
Here is a pared down version of the program that acts as the bridge. I can transmit data back and forth on the UART fine until the USB is active. It seems to hang once it gets to the RS232 macros at the end of the Update_Current_Limit macro.
- Attachments
-
- UART_Test.fcfx
- (22.91 KiB) Downloaded 293 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: Possible to have both USB Serial and UART active?
Hello,
I wonder if the USB interrupt is somehow interfering with your UART receive data and therefore you are getting stuck in the loop inside the Wait_for_ready macro. The UART receive buffer is very small on a PIC so it could be you are maybe missing a byte.
Here is a slightly modified version of the program which uses an interrupt to receive the UART data as it arrives and load it into a circular buffer. We can then scan the buffer for the "Ready" message using the WaitForValue component macro.
Let us know how you get on.
I wonder if the USB interrupt is somehow interfering with your UART receive data and therefore you are getting stuck in the loop inside the Wait_for_ready macro. The UART receive buffer is very small on a PIC so it could be you are maybe missing a byte.
Here is a slightly modified version of the program which uses an interrupt to receive the UART data as it arrives and load it into a circular buffer. We can then scan the buffer for the "Ready" message using the WaitForValue component macro.
Let us know how you get on.
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
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Re: Possible to have both USB Serial and UART active?
Thanks Benj, that seemed to do the trick. I am actually using the circular buffer approach on the other MCU, which leads to the next question I will post.
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Re: Possible to have both USB Serial and UART active?
I guess I spoke to soon. The first time I tried the modified test program, it seemed to work, but I cannot get it to work again. Looking at a scope I do not even see the RS232 Send String macro transmitting anything. (this is just before the Wait_for_Ready macro). On many tries, only once did I observe any activity on the UART line. The scope does show constant activity on the USB lines.
- 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: Possible to have both USB Serial and UART active?
Hello,
What happens if you change the timeout parameter for the WaitForValue component macro from 0 to say 100. This should wait 100ms for the response before timing out but should avoid any blocking type lock ups.
What happens if you change the timeout parameter for the WaitForValue component macro from 0 to say 100. This should wait 100ms for the response before timing out but should avoid any blocking type lock ups.
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
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Re: Possible to have both USB Serial and UART active?
I think I tried that yesterday, but will give it another try to be sure.
Not familiar with USB. Is it normal that I should see activity on the USB lines when not sending or receiving? It appears that there is a packet every 10usec (packets sent at at 100kHz).
Not familiar with USB. Is it normal that I should see activity on the USB lines when not sending or receiving? It appears that there is a packet every 10usec (packets sent at at 100kHz).
- 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: Possible to have both USB Serial and UART active?
USB is a whole other ball game and is automatically multiplexed and time spliced by the host to allow hubs from hubs from hubs etc. I think each USB connection can connect to up to 128 devices.
A packet could simply be a NAK so I wouldn't worry that there is a lot of periodic data.
My guess is it is the blocking code that is causing problems having played a lot with both USB and UARTs though of course I could be wrong
.
A packet could simply be a NAK so I wouldn't worry that there is a lot of periodic data.
My guess is it is the blocking code that is causing problems having played a lot with both USB and UARTs though of course I could be wrong

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
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Re: Possible to have both USB Serial and UART active?
This skips the "Wait_for_Ready" and allows the data to be sent, preventing a waitforever lockup. But it appears that the data is not received on the other end...so the receiving MCU never responds with "Ready". It appears that it is the LookforValue "NewAmps" macro where it gets stuck. Neither of the LookforValues tests proceeds if the "NewAmps" is first in the sequence. While the "CalData" works fine if it is first.Benj wrote:Hello,
What happens if you change the timeout parameter for the WaitForValue component macro from 0 to say 100. This should wait 100ms for the response before timing out but should avoid any blocking type lock ups.
- Attachments
-
- UART_receive.jpg
- (79.36 KiB) Downloaded 1519 times
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
Re: Possible to have both USB Serial and UART active?
I think I have this resolved...again. It appears that the receiving MCU was attempting to intialize/connect to USB while the other MCU had control of the switched lines. USB would not usually be connected while receiving new CalData, so that explains why there was never an issue receiving that. Too many comms to keep track of in my code! USB, UART and I2C.