Pic 18f46K20 Send UART Software problem

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Pic 18f46K20 Send UART Software problem

Post by Ferla »

Hello Guys I know I can help me.
I'm having problems in passing from micro 18F46K20 (Osc.Int 16Mhz) a string "* RA" in RS232 9600,8, N, 1 to a pic 12F675 which he replies.
Attached are two files *bmp:
1- indicating transmission interpreted correctly by the Pic12F675
2- indicates that the transmission is not properly interpreted by the Pic12F675.

The strange thing is that with hypeterminal and protocol analyzer I see correctly the string "* RA".
How do I make my tramsissione equivalent to the file Trasmission OK.bmp ?
I state that I'm using UART Software UART because standard and occupied,It states that the transmission OK was taken from micro 18f46k20 original present on the circuit that communicates with the PIC12F675 without errors .My objective and replace the original 18f46K20 with what my suitably modified.
I look forward to some advice, Thanks :wink:
Ferla
Attachments
Uart.zip
(503.92 KiB) Downloaded 596 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: Pic 18f46K20 Send UART Software problem

Post by Benj »

Hello Ferla,

As your using the software channel you have to take some special considerations to ensure the data is transmitted and received correctly.

On the transmitter make sure that when you are sending out data that all interrupts are disabled. If any interrupts are active when sending out the data then you may cause the output data to be corrupted.

On the receiver you might want to use a port change interrupt or INT interrupt to catch the falling edge of the start bit. Inside the interrupt macro call the receive function. This should help to guarantee that you call the receive macro at the right moment that data is being sent. Otherwise if your not using an interrupt then you have to ensure that you return and check for incoming data at least once every bit period. At 9600 baud a single bit period is 104uS.

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Pic 18f46K20 Send UART Software problem

Post by Ferla »

Thank Benj you for your kind response.
I confirm that all interrupts are disabled.
I tried to create a macro with timer0 but can not give the right time, confirming that I have to use TMR0 preload = 48 and prescaler 1: 2 ?
I looked around the forum to try to find a solution.
You can give me a simple example.
Thank you
Ferla

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: Pic 18f46K20 Send UART Software problem

Post by medelec35 »

Hi Ferla,
In my opinion the only way to achieve desired results is to change from 12F675 to 12F1840, use RS232 in hardware mode and also use RX interrupt.
Is that possible?
If so I can help you develop flowchart.

I believe problem with receiving with port interrupt on negative edge is after negative edge has occurred the RS232 receive is then brought into action.
But since at that point negative edge has already taken place then RS232 receive macro waits for the next negative edge so will be a bit out (bits will be shifted by 1)
If using the fast timer interrupt for RS232 Receive then that would probably interfere with RS232 signals being received so you would not see correct results.
Also if timeout is any value above 0 then it will interfere with interrupt times so RS232 will no longer be checked at the required sample rate.

Martin
Martin

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Pic 18f46K20 Send UART Software problem

Post by Ferla »

Hi Martin, I am grateful for your interest to my problem and for your time.
Ok I will use the 12f1840 to interface to micro 18F46K20.
Even yesterday I tried all day to find a solution but did not succeed. Enclosed is an example, the only thing that I can not change the settings are in the C code, 'cause will be used for the rest of the project.
Can with these settings to send a string to uart with the correct timing 104uS as indicated by Benj?
thanks
Ferla
Attachments
Ferla Sempli Test RS232 Interrupt.fcf
(13.55 KiB) Downloaded 842 times

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: Pic 18f46K20 Send UART Software problem

Post by medelec35 »

Hi Ferla,
Your welcome.
Ferla wrote:Can with these settings to send a string to uart with the correct timing 104uS as indicated by Benj?
thanks
Ferla
Should do as the RS232 external properties is set to 9600 Baud.

The beauty of Flowcode is you should not require most of the C code settings.
Only osccon part should be necessary.
Flowcode should sort all analog/digital settings automatically.
When you add a ADC component all the C code settings required are done behind the scenes.
You have got sendRS232 char 42 for example which is not wrong.
Alternatively you could use sendRS232String"*" so you don't need to look up the char equivalent.

Martin
Martin

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Pic 18f46K20 Send UART Software problem

Post by Ferla »

Martin thanks for your advice, I tried to send the string, but the result was the same.
The attached file and an example of another 1000 that I did not succeed.
I have not the right time TX can help me, and here is often just a boost in that you can understand many things. On the other hand the teachers at school what we have to do, just to help you understand in other ways that can not seem to understand.
I do not give up sooner or later I'll be able to do to send the string with the right timing.
Ferla

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: Pic 18f46K20 Send UART Software problem

Post by medelec35 »

Ferla wrote:I tried to send the string, but the result was the same.
Are you using 12F1840 with RXINT enabled?
As stated earlier if using timer interrupt for RS232 receiving then I don't believe it will work.
If you have a TTL to USB converter (or a scope), then you can check transmission is ok with a terminal program like hyperterminal, Putty or TeraTerm etc.
Best to work on one side at a time.
Once you know the correct RS232 TX are being sent, then you can work on the receiving side.
Martin

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Pic 18f46K20 Send UART Software problem

Post by Ferla »

To check the times I use logic analyzer Seleae Logic8 www.saleae.com , and I have a transmission time of 102us.
as mentioned using a TTL converter max232 on com1 the string it is received correctly on the PC, but not dal12f675.
I have not the 12f1840 who will order this week, in the meantime, my purpose and convey the right time, there will be a way to do it! :roll:

Post Reply