Serial receive using PIC18F4620 not working

For general Flowcode discussion that does not belong in the other sections.
Post Reply
chezkrimles
Posts: 9
http://meble-kuchenne.info.pl
Joined: Thu Jan 14, 2021 7:12 pm
Has thanked: 2 times

Serial receive using PIC18F4620 not working

Post by chezkrimles »

Hi,
In the past I have had no issues sending/receiving to smaller PIC micros using Flowcode but I'm having no luck with the EUSART in the PIC18F4620 when trying to receive a single byte char. Nothing is received. There must be some small detail I'm overlooking.
I wrote a simple program to try to figure out what could be wrong by sending a single byte at 9600B every 30ms from another device and trying to observe the LED with a scope to see if anything is received. I would expect to see small pulses.
I have gone through Microchip's setup to do this with no luck. Does anyone have an idea of what I'm missing here? I've tried everything.
Program is attached. I am 5 hours behind the UK (EST). Appreciate any help.
Attachments
Simple RX test.fcfx
(9.9 KiB) Downloaded 149 times

medelec35
Matrix Staff
Posts: 1432
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 506 times
Been thanked: 469 times

Re: Serial receive using PIC18F4620 not working

Post by medelec35 »

Hi, chezkrimles.
If I was you , I would use either UART RX interrupt
Rx Interrupt.png
Rx Interrupt.png (13.57 KiB) Viewed 3170 times
Or use UART software timer as that also uses interrupts.
Either way you will no longer have any missed characters.
There is even a circular buffer available.
That will store the received chars until they are required.
For a great example on the best way download this flowchart.
as it also shows you how to set up the RX interrupt as well as circular buffer.
Let us know if you require further help.
Martin

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Serial receive using PIC18F4620 not working

Post by BenR »

Further to Medelec's post I would suggest that the Ccode icon in your program to setup the EUSART registers is not required.

However to force the int osc to run at the speed of 8MHz you do need to add this code at the very start of your program using a C icon.

Code: Select all

OSCCON = 0x70;
The INTOSC helper component available under RunTime -> Matrix Tools is useful for helping with things like this.

For sanity you can always use the 1 second flasher test.
https://www.flowcode.co.uk/wiki/index.p ... ED_flasher

Your program waits 10ms for an incoming byte and then 500ms in between bytes and so is unlikely to receive a single value being sent. Hence Martins suggestion to use interrupts.

chezkrimles
Posts: 9
Joined: Thu Jan 14, 2021 7:12 pm
Has thanked: 2 times

Re: Serial receive using PIC18F4620 not working

Post by chezkrimles »

Following up... I managed to get the data transmit working OK in Flowcode V5, but not in V9. I suspect a bug unless there is something overlooked.
Two identical programs were written using V5 and V9 to transmit the Char 52 to turn on a relay. I could not load the V5 program here but have included the output data stream for both plus the code for V9.
Sending the Char 52 comes out correctly on V5, but not V9. The baud rate seems wrong. V5 is 920us, while V9 is 600us.
Both versions of Flowcode 'know' that the clock is 8MHz.
Any ideas what could be wrong here? Thank you both for your help on this.
Attachments
Waveform V9.JPG
Waveform V9.JPG (99.31 KiB) Viewed 3123 times
Waveform V5.JPG
Waveform V5.JPG (74.75 KiB) Viewed 3123 times
Relay_test__V9.fcfx
(8.77 KiB) Downloaded 154 times

chipfryer27
Valued Contributor
Posts: 1110
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 278 times
Been thanked: 397 times

Re: Serial receive using PIC18F4620 not working

Post by chipfryer27 »

Hi

For a baud rate of 9600, that would equate to a character being sent in approx 1mS so I would assume that v5 trace would be working. I haven't got one of those chips myself to check but I would look at configs. I know it is simplistic but an led flasher as suggested elsewhere is a good sanity check.

The IntOsc helper tool suggests for you to run at 8MHz the C-code should be OSCCON=0x70;
However you have OSCCON=0x7E;

I don't know the chip or have a datasheet to know if there are other bits that need setting within the register, but maybe try 0x70; to see how you get on?

Regards

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Serial receive using PIC18F4620 not working

Post by BenR »

Hello,

In your v9 program you are using the software UART. Can you try the hardware UART channel instead.

Software UARTs can be a pain to get bang on the nose whereas a hardware UART can easily do this.
Uart.jpg
Uart.jpg (22.92 KiB) Viewed 3077 times
If you need to use a software UART then can I suggest you instead use the UART Software (Timer) component. This uses a timer interrupt to allow you to get the timings just right.

Post Reply