Author Topic: UART Issue  (Read 1199 times)

0 Members and 1 Guest are viewing this topic.

Offline yukon101Topic starter

  • Newbie
  • Posts: 4
  • Country: us
UART Issue
« on: September 10, 2020, 03:27:28 pm »
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?
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: UART Issue
« Reply #1 on: September 10, 2020, 04:08:31 pm »
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.

 

Offline yukon101Topic starter

  • Newbie
  • Posts: 4
  • Country: us
Re: UART Issue
« Reply #2 on: September 10, 2020, 07:32:19 pm »
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?
 

Offline yukon101Topic starter

  • Newbie
  • Posts: 4
  • Country: us
Re: UART Issue
« Reply #3 on: September 10, 2020, 08:50:45 pm »
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.
 

Offline yukon101Topic starter

  • Newbie
  • Posts: 4
  • Country: us
Re: UART Issue
« Reply #4 on: September 10, 2020, 09:19:34 pm »
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...
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: UART Issue
« Reply #5 on: September 14, 2020, 01:44:28 pm »
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?

I 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).
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: UART Issue
« Reply #6 on: September 14, 2020, 02:28:35 pm »
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?
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: us
  • Very dangerous - may attack at any time
Re: UART Issue
« Reply #7 on: September 14, 2020, 03:20:00 pm »
It is to prevent the common mistake of if (something = 0)

Many compilers will warn of this and require double parens to eliminate the warning.
 

Offline JoeyG

  • Regular Contributor
  • *
  • Posts: 117
  • Country: au
Re: UART Issue
« Reply #8 on: September 14, 2020, 04:23:57 pm »
In the  uart.h  header file is an example in the documented  comments
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf