EEVblog® Electronics Community Forum
Electronics => Microcontrollers => Topic started by: conducteur on February 19, 2015, 11:59:44 am
-
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 (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 fine
But it doesn't. So i made a little program that sends a charachter to it:
;-------------------------------------------------------------------------------
;programma
;Controller = PIC 16F887
;-------------------------------------------------------------------------------
include 16f887
;Alle mogelijke 'fuses' voor een 16F887
;8MHz intern
pragma target OSC INTOSC_CLKOUT
pragma target clock 8_000_000 -- oscillator frequency
pragma target WDT disabled -- WDT off
pragma target LVP disabled -- no low voltage programming
pragma target PWRTE DISABLED -- power-up timer enable bit
pragma target MCLR Internal -- re3/mclr pin function select bit
pragma target CPD DISABLED -- data code protection bit
pragma target BROWNOUT DISABLED -- brown out reset selection bits
pragma target IESO DISABLED -- internal external switchover bit
pragma target FCMEN DISABLED -- fail-safe clock monitor enabled bit
pragma target DEBUG DISABLED -- in-circuit debugger mode bit
var byte char
enable_digital_io()
const serial_hw_baudrate = 9600
include serial_hardware
serial_hw_init()
include delay
forever loop
serial_hw_write(44)
delay_100ms(2)
end loop
This should fill up my display with the comma sign ","....
What is going wrong? I tried for several hours to solve it, without succes.
-
Have you tried putting a logic analyzer on the line to see what's actually being pushed out?
-
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.
-
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!
-
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.
Hmm 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.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf)
8mhz 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?
-
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.
Hmm 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.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf)
8mhz 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?
Section 4.2, Did you set the IRCF bits to '111' to get 8 MHz? Default (if not specified otherwise) is for 4 MHz.
-
thanks! i should read the ****** manual first (RTFM!)
-
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!
It's a very handy 3 channel analyzer, plus a UART tool. Really handy, too bad they did do this for the PICkit 3.