UART Issue - Page 1
Forum section: electronics / general

author: yukon101
author_rank: Newbie
timestamp: September 10, 2020, 03:27:28 pm
content: A bit of background about me, I am a certified aircraft mechanic but no longer want to pursue that with how easy the industry is to send into turmoil. I scored a job with a startup aerospace company as an electrical engineering technician with all my prior experience being hobiest and highschool. The first action I was given was to learn C and develop the firmware for our microcontroller. I have made leaps and bounds with learning all of this and actually understand what I am looking and without referring back to my notes from 2 months of leaning. Now onto the issue...Our project uses a PIC18F25K83 I have written everything up in C and believe it to be relatively bug-free, however the entire thing is controlled via UART and with the development board I am using, Microchip Explorer 8, I receive absolutely nothing over UART. Within MPLAB X/MCC I have configured UART to run 9600 baud and configured STDIO to UART so I can use printf();. I have used both the UART_Write("F"); and printf(); to try and send something but nothing is received.All the initial learning I did was with a PIC16F1719 which sends and receives single letter commands perfectly fine on the same development board.I downloaded a sample project for a PIC18F25K42 and compiled it for the 18F25K83 and the LCD and everything works perfectly fine, when I load up the UART1 peripheral and do the same thing as last time I receive nothing.Thoughts?

author: ledtester
author_rank: Super Contributor
timestamp: September 10, 2020, 04:08:31 pm
content: What really helps for questions like these is the smallest program which doesn't work for you. Small is important - it helps in understanding the program as well as pin-pointing where the problem is.

author: yukon101
author_rank: Newbie
timestamp: September 10, 2020, 07:32:19 pm
content: So I setup a new project just as a test, all that is in it is UART initialize and UART Write F under a while loop, then just to make sure I can even program it I brought one of the LED pins high. While the LED is high I receive nothing via UART. I uploaded the test project. Maybe I completely blew past something that I got lucky with, with the older microcontroller?

author: yukon101
author_rank: Newbie
timestamp: September 10, 2020, 08:50:45 pm
content: So in my test code I moved the printf outside of the while loop and it suddenly works. However I am receiving double on the computer side, I am not sure why that is.

author: yukon101
author_rank: Newbie
timestamp: September 10, 2020, 09:19:34 pm
content: My full code to be used works completely as intended thus far without the production board. I have no idea what changed between this morning and now besides unplugging and replugging the development board must've not been fully seated I guess. Oh well...

author: TomS_
author_rank: Frequent Contributor
timestamp: September 14, 2020, 01:44:28 pm
content: Quote from: yukon101 on September 10, 2020, 07:32:19 pmI would suggest not attaching a .zip file - people tend to be a bit wary about downloading such files.Grab yourself a github/gitlab/or similar account (if you're moving into software, no better time to learn about versioning systems!) and put your code there, or attach the source code file in question, or you can even paste it in-line on the page if its small enough, just wrap it in [ code ] tags (# on the tool bar when writing a message).

author: TomS_
author_rank: Frequent Contributor
timestamp: September 14, 2020, 02:28:35 pm
content: Been looking at the source, got to say, what were the people that were writing the code generator thinking? They've written a lot of expressions in a very strange way, as in the opposite to how you would normally read code, like "if (0 == something)" .....Makes for a real head ache to read it... If someone knows of a legit reason for doing that, I would like to hear it.If you have a debug tool (PICkit or ICD), I would suggest putting some breakpoints in through the UART related code and make sure that the correct code paths are being executed.You say when you move the UART write out of the loop it works .. does the LED still come on when you try to turn it on from inside the loop?

author: oPossum
author_rank: Super Contributor
timestamp: September 14, 2020, 03:20:00 pm
content: It is to prevent the common mistake ofif (something = 0)Many compilers will warn of this and require double parens to eliminate the warning.

author: JoeyG
author_rank: Regular Contributor
timestamp: September 14, 2020, 04:23:57 pm
content: In the uart.h header file is an example in the documented comments