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.
Serial receive using PIC18F4620 not working
-
- 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
- Attachments
-
- Simple RX test.fcfx
- (9.9 KiB) Downloaded 446 times
-
- Matrix Staff
- Posts: 1913
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 619 times
- Been thanked: 644 times
Re: Serial receive using PIC18F4620 not working
Hi, chezkrimles.
If I was you , I would use either UART RX interrupt 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.
If I was you , I would use either UART RX interrupt 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
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 684 times
Re: Serial receive using PIC18F4620 not working
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.
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.
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;
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.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 9
- Joined: Thu Jan 14, 2021 7:12 pm
- Has thanked: 2 times
Re: Serial receive using PIC18F4620 not working
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.
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 (99.31 KiB) Viewed 6274 times
-
- Waveform V5.JPG (74.75 KiB) Viewed 6274 times
-
- Relay_test__V9.fcfx
- (8.77 KiB) Downloaded 468 times
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: Serial receive using PIC18F4620 not working
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
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
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 684 times
Re: Serial receive using PIC18F4620 not working
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.
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.
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel