Just Another Language : UART problems?  - Page 1
Forum section: electronics / general

author: conducteur
author_rank: Regular Contributor
timestamp: February 19, 2015, 11:59:44 am
content: I try to use my serial terminal to debug another project, but there seems to be a problem in the uart communication.http://www.treinbaanrian.be/html/16f887_6_Serial_tekst_commando.htm(sorry for dutch comments, but this code is for the serial terminal, 9600 baud. I can send strings to it, and then they should appear on the 16*2 lcd. When character received is higher then 127, it's a command :clear screen or set cursor. Used this code before, but had to put a new µC on the pcb. This should work just fineBut it doesn't. So i made a little program that sends a charachter to it:Code:;-------------------------------------------------------------------------------;programma;Controller = PIC 16F887;-------------------------------------------------------------------------------include 16f887;Alle mogelijke 'fuses' voor een 16F887;8MHz internpragma target OSC INTOSC_CLKOUTpragma target clock 8_000_000 -- oscillator frequencypragma target WDT disabled -- WDT offpragma target LVP disabled -- no low voltage programmingpragma target PWRTE DISABLED -- power-up timer enable bitpragma target MCLR Internal -- re3/mclr pin function select bitpragma target CPD DISABLED -- data code protection bitpragma target BROWNOUT DISABLED -- brown out reset selection bitspragma target IESO DISABLED -- internal external switchover bitpragma target FCMEN DISABLED -- fail-safe clock monitor enabled bitpragma target DEBUG DISABLED -- in-circuit debugger mode bitvar byte charenable_digital_io()const serial_hw_baudrate = 9600include serial_hardwareserial_hw_init()include delayforever loopserial_hw_write(44)delay_100ms(2)end loopThis should fill up my display with the comma sign ","....What is going wrong? I tried for several hours to solve it, without succes.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 19, 2015, 03:44:15 pm
content: Have you tried putting a logic analyzer on the line to see what's actually being pushed out?

author: macboy
author_rank: Super Contributor
timestamp: February 19, 2015, 04:39:59 pm
content: You are using the internal oscillator, which is not known for high precision. Odds are fairly high that you have framing errors due to baud rate mismatch between the PC and the PIC. Try adjusting the BRG up or down by 1 or 2 from what you have now. Better yet, measure the bit periods with a scope for both PC and PIC and compare. They need to be within 4% of each other.

author: conducteur
author_rank: Regular Contributor
timestamp: February 19, 2015, 05:21:34 pm
content: I don't have a logic analyzer (there's one in my pickit 2, but i have not used it before)... Just have a velleman psu, a old hameg analog/digital scope and a multimeter.connected the pickit 2 to my terminal board... (the lcd and 8 knobs, was intended to be a control panel for another project, but now i use it as a terminal), sending characters with the uart tool... The terminal works just fine...Sending data from the project to my terminal: on the hameg i see data, don't know if it's correct, but nothing appears on my display. So maybe I have to search a crystal in my junk box!

author: conducteur
author_rank: Regular Contributor
timestamp: February 19, 2015, 06:43:37 pm
content: Quote from: macboy on February 19, 2015, 04:39:59 pmHmm there's a strange problem here: checked the datasheet for the pic16f887, which i use for almost al projects.http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf8mhz clock internal. Changed my program to transmit "10101010" in binary, baudrate was 4800 (half of 9600). Changed the clock frequency in my program to 4mhz and now it works fine?

author: macboy
author_rank: Super Contributor
timestamp: February 19, 2015, 06:46:14 pm
content: Quote from: conducteur on February 19, 2015, 06:43:37 pmSection 4.2, Did you set the IRCF bits to '111' to get 8 MHz? Default (if not specified otherwise) is for 4 MHz.

author: conducteur
author_rank: Regular Contributor
timestamp: February 19, 2015, 07:07:17 pm
content: thanks! i should read the ****** manual first (RTFM!)

author: BlueBill
author_rank: Regular Contributor
timestamp: February 19, 2015, 10:04:34 pm
content: Quote from: conducteur on February 19, 2015, 05:21:34 pmIt's a very handy 3 channel analyzer, plus a UART tool. Really handy, too bad they did do this for the PICkit 3.