Page 1 of 1

UART receive problem

Posted: Fri Nov 17, 2017 1:06 pm
by howard123
Hello all

I am having a problem with a serial receive that I hope you could help me with.

I send a number to an instrument and receive data from it using channel 2 UART on a 18F46K22 using 9600 baud. One character is sent and one is received. Most often the return character is incorrect with a value of 255 or sometimes another incorrect value. The time taken for the instrument to respond it 13mS and I have set the receive timeout to 25mS. I have measured on the chip, using a logic analyser, that the timing and framing are correct and that the received byte is always the correct value. This runs within a timer interrupt and so I guess there is nothing being called to do between sending and receiving.
Capture.JPG
Capture.JPG (173.89 KiB) Viewed 4042 times
I changed to this scheme after first using a receive interrupt scheme and that too delivered similar unreliable UART reads.

Channel 1 UART does a similar bidirectional communication without a problem.


Thanks
Howard

Re: UART receive problem

Posted: Fri Nov 17, 2017 1:15 pm
by kersing
As you haven't posted your flowcard there is not much to go on. We can't look at controller settings, component settings etc. We can't see what component you are using (RS232 or UART CAL) We just see a few icons...

Re: UART receive problem

Posted: Sat Nov 18, 2017 1:33 pm
by howard123
Hi

Thank you for your interest in this.

I have attached a reduced but still UART 2 RS232 dis-functioning version of the project.

I have made a Labview simulation of the instrument and so the timing is not as previously described. To compensate, I have set the UART timeout to 50ms for this test.

The instrument is sent the number 10 and correctly replies with the number 73 as sampled at the PIC chip and shown on the logic analyser..
call 10 ans 73.JPG
call 10 ans 73.JPG (25.39 KiB) Viewed 4023 times

Here is the location of the code tested..
flowcode segment.JPG
flowcode segment.JPG (94.81 KiB) Viewed 4023 times

The UART output is either the correct value (73) or value X or 255. I can not clearly define what the causal relationship is between these 3 outputs. The value X is the same as the value the UART should be delivering from a previous call. Could this be a UART hardware buffer issue?

Thank you

Re: UART receive problem

Posted: Wed Nov 22, 2017 9:10 am
by howard123
Turns out this was a bad solder joint on the SMD receive pin of my device. Sometimes when it made a contact it would work well and when open would cause a timeout (255)

Sorry if I misled anyone
Howard