Uart RX to 2 TX

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Uart RX to 2 TX

Post by kabouras_33 »

Hello to everyone,
I have been trying to find a way to receive a char from Uart Rx1 from pc (DB9 2pin) and transmit it to TX1 and TX2 but whatever I try fail if someone has any idea or lead?I am using flow code 6 and 18f46k80 pic

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

Please find attached my code which i used taking as a base the flowcode example uart bridge.
I am sending a nmea simulated signal from one pc to UART RX1 and i try to tranmit it on the same time from TX2 and TX1.
In simulation it works but in reality it doesnt.
I connect all grounds together.
I would really appreciate some help because it is very frustrating not to know the code problem or hardware :twisted: :twisted: :twisted:
Attachments
project.fcfx
(15.6 KiB) Downloaded 310 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Uart RX to 2 TX

Post by LeighM »

Hi,
You have got both UARTs set to the same Channel (1)

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I am really sorry i just edited without changing the channel before posting.
With correct channels it doesnt work.
I use common grounds and Rx receives and Tx1 Transmits but not Tx2

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Uart RX to 2 TX

Post by LeighM »

So you have your TX2 on UART Channel 2, on pins D6 and D7?
Does everything else work, LED flash, TX1?
Just TX2 not working?
Sounds like we need to look at your hardware and circuit.

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

Yes exactly.
LEDs works normally as they should.
And the simulation looks ok.
But in reality no.
I connected a DB9 plug to a serial port on my pc.from pin 3 of pc I take the transmit signal and connect it to c7 of the pic and from c6 I receive correct data but from d6 nothing.
I use internal oscillator at 20Mhz .and all ground cables are connected together but not with the pic 0v just together.
That's it....I cannot understand it!!

Ps thank you deeply for your interest and your prompt reply!!!

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Uart RX to 2 TX

Post by LeighM »

Hi,
That sounds like the problem then.
The signals from the D type on the PC are not 5V level, they are RS232, up to +/-12V
So you need a level convertor, such as MAX232 chip.

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Uart RX to 2 TX

Post by EtsDriver »

Do you have 5v level shifter in between of your pic and pc serial port? It may cause unexcepted things as RS232 on old days supplied 12V level at most and many these days supply start from +9V to even +12V on some motherboards.

EDIT: Leigh was faster! :lol:
Ill just keep the good work up!

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

Yes unfortunately I tried that yesterday and I connected a max232n with no difference!!

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I took the pc transmit and connect to R1in of the max232 and from R1out to c7 pic from the tx and TX2 of the pic I went to txin and TX2in respectively and from the txs out I went to a buffers 2 channels which I can monitor from another pc.
And nothing :oops: :twisted:

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I removed the pc simulator from my project and I used a GPS module I had spare and now it looks more stable the led look like everything works well.
But when I connect the GPS module tx directly to the monitor pc I can see data.When I connect to pic TX1 or TX2 no data transmit.
I am starting to thing that my programme now may have a problem probably the buffer or the type of data I receive and try to transmit.
Any thought would be highly appreciated!! :D

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

So I am still trying with no result.
I will start from scratch,the only thing I am trying to do is take nmea data to RX and transmitter to the tx as it is with no processing.
I would appreciate some help....

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: Uart RX to 2 TX

Post by Benj »

Hello,

Having worked recently with a GSM module could it be flow control that is causing you issues? When you connect to the PC is it via a RS232 cable or via a USB to serial cable? Do you connect the flow control pins?

Another problem could be baud rate, have you checked your baud rate is correct and that your micro is running at the speed you think it is? A 1 second flasher test will help to confirm if the micro is at the right speed.

https://www.matrixtsl.com/wikiv7/index. ... ED_flasher

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I serial directly as i have an old pc which has a serial port and connect only ground and transmit pin from pc to the ground and receive of my pic throught max232 or directly.
The baud rate is configured in both the pc and uart properties at 9600.
And a status Led which is in the programm flashes every 1 sec so i suppose its correct.
I configure the pic with external oscillator and 20Mhz pic and 8Mhz crystal with capacitors 22uf between osc1-2
What troubles me is the fact that flowcode simulation take the nmea signal and project it correctly to the lcd and probably to uart2,when i also load the programm to proteus (which i dont trust it but take out many variables like clock and supplies) it also doesnt work....

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

one more think is that i tried a much simpler code which probably is wrong but in flowcode it works and in proteus and in reality the result is like the attached (same with max232 or without)
Attachments
Untitled.png
proteus snapshot
(78.07 KiB) Downloaded 9933 times
Flowcode1.fcfx
(12.18 KiB) Downloaded 204 times

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

This is what i try to achieve but through the pic so i can manipulate the transmits and receives in order to make some modes.
Now the gps module is directly connected to the virtual terminal,and its exactly the same situation that happen in reality also. :twisted: :twisted: :twisted:
Attachments
Untitled.png
(28.45 KiB) Downloaded 9933 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: Uart RX to 2 TX

Post by Benj »

I think the problem is the clock source to the micrcontroller.

Are you using a crystal or resonator on your circuit? If so then what value is it?

Or are you using the internal oscillator?

Currently your chip configuration is to use a RC driven oscillator and you have your project clock speed set to 19.6608MHz so I think this could be the cause of the problem.

As mentioned above use the 1 second flasher test to get your hardware running at the right speed, Once this is right the GPS should hopefully just fall into place.

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I have a bunch of crystal which i use but currently i tried an 8 and 10.
:shock: i just realized the configuration is wrong i should use XT,although with internal oscillator it didnt work.
When i finish work and get back home i will try the 1 sec test and inform you back!!
Once again i thank you deeply for your support and not abandon me. :)

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: Uart RX to 2 TX

Post by Benj »

Once again i thank you deeply for your support and not abandon me.
You're very welcome, just doing my job :D

For the 8MHz / 10MHz crystals you will need to select the HS (High Speed Crystal) oscillator option. Then set the clock speed in the project options to match e.g. 8000000. Once you have done this you can confirm with the 1 second flasher test.
with internal oscillator it didnt work
Under Tools on the Components toolbar is an INTOSC Helper component to allow you to experiment with the internal oscillator. Basically provides you with a line of C code you can add to the very start of your project to configure the micro to the right speed.

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

First of all thanks again for the support!!!
So i tried what you told me and you were 100% right it was the oscillator problem.
With settings 8MHz HS ( low ).
I can see at last data coming through but another problem occured (as always) which now i am trying to solve.
The input is NMEA but the output is not junk but also it is not the nmea that goes in???
second is that it creates overflow and suddenly stops working.
I think that the NMEA signals that comes in are string type so i make and extremely simpe program which outputs nmea string(find attached nmea in and out).But nothing.
And pushing my luck a little further as final i try to do this (find attached nmea in and out 2)and its my final target but then absolutly nothing at all?????
Attachments
nmea in and out double.fcfx
(10.22 KiB) Downloaded 201 times
nmea in and out.fcfx
(8.66 KiB) Downloaded 188 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Uart RX to 2 TX

Post by LeighM »

Hi,
In your second test you forgot to Initialise the RS232.
You would probably be better using ReceiveChar and SendChar in a loop,
as you will not be able to Receive a string during the time that you are sending the string.
So data from the incoming string will be missed if the time to send a string is longer than the "silent" gap between the received strings.

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I am deeply sorry for late responce,there was a health issue.
Thanks again everyone for your great support.
So i initialised the second RS232 and change in receiving and send char in a loop but nothing for some reason no data transmit at all.
Now when i use the flowcode uart bridge example and after i fixed the clock problem after your suggestion i receive data but they are not the nmea signals i inject the receive and trnsmit timing is correct but the data change on output...
I continue the research any suggestions would be highly appreciated once again :D

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

I believe it is clock problem i do not know how to calculate the oscillator value for this project... :evil: :evil: :evil:

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Uart RX to 2 TX

Post by medelec35 »

Hi kabouras_33,
This post may help you?

Don't forget if you add the osccon value to set internal oscillator to say 8MHz, then you much also change the clock speed in Build, Project Options, General Options tab to match.

Martin
Martin

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Uart RX to 2 TX

Post by kabouras_33 »

Thank you very much for your kind reply i added the c code OSCOON=0X70; and changed clock speed 8MHz internal but still same the timing of the data transfer is correct but the data that transmits are garbage.....
Attachments
Untitled.png
(41.28 KiB) Downloaded 9588 times

Post Reply