|
|
View previous topic :: View next topic |
Author |
Message |
tojape
Joined: 14 Jan 2007 Posts: 20 Location: Hungary
|
PIC16F1519 UART not receiving |
Posted: Fri Jun 21, 2013 12:49 pm |
|
|
Hi all,
I am having problem with a cheap pic micro: PIC16F1519 doesn't receive on RX pin (C7, pin 26) with the following code:
rs232test.c
Code: |
#include <rs232test.h>
void main()
{
char chin=0x55;
disable_interrupts(GLOBAL);
setup_wdt(WDT_OFF);
printf(__FILENAME__);
while(1)
{
if(kbhit())
{
chin=getc();
}
putc(chin);
delay_ms(100);
}
}
|
rs232test.h
Code: |
#include <16F1519.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES WDT_SW //No Watch Dog Timer, enabled in Software
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=11045200)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors)
|
The file name appears on the terminal screen, then the endless letter "U" comes despite of my typing on the keyboard.
Dropping a PIC18F46K22 in the socket of the PIC16F1519 works fine with the same main() function.
I tried to use the sw implementation of rs232 I/O adding "force_sw" option to the #use rs23 directive. The result is even worse.
The printf() works OK then instead of letters "U" (an 50% duty cycle waveform on the oscilloscope) 932us start level pulses appear. This is the duration of 9 bits@9600bps (1 startbit + 8 pieces of 0 bits). I am rather stuck with this problem.
Is it a bug of my compiler version (4.124) or am I doing something wrong? _________________ The computer helps solving the problems which would have never arised without computers |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Jun 21, 2013 1:30 pm |
|
|
Hi,
You are doing something wrong. When you specify a 'stream' in your #use rs232 statement, that stream name must then be used with the kbhit, getc,
and putc functions.
Try this code instead:
Code: |
while(1)
{
chin=fgetc(PORT1);
fputc(chin, PORT1);
}
|
Note, keep your COMMs test very simple until you know it's working properly, then you can add back the 'kbhit' and the delay so that you
continuously show the last character received.
John
Last edited by ezflyr on Fri Jun 21, 2013 1:31 pm; edited 1 time in total |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri Jun 21, 2013 1:30 pm |
|
|
Is your clock really this speed?
Quote: | #use delay(clock=11045200) |
Also, you specify a stream in your use statement but nowhere else... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
tojape
Joined: 14 Jan 2007 Posts: 20 Location: Hungary
|
|
Posted: Fri Jun 21, 2013 1:59 pm |
|
|
Thanks to both of you for your replies.
I didn't bother with stream name since if I don't specify it in the serial I/O functions the compiler assumes the last used "USE RS232" stream. But you are right, I have to keep the test code as simple as possible.
I reduced my code, here it is, still not operable:
Code: |
#include <16F1519.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES WDT_SW //No Watch Dog Timer, enabled in Software
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=11059200)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
void main()
{
char chin;
while(1)
{
chin=getc();
putc(chin);
}
}
|
As you can see, I corrected the crystal frequency (which was not the problem, I simply mistyped it when I created the test project. The error was ignorable)
Sending the last char informed me during the test that my program hasn't hang or whatever...
Thank you again, and do you have any other idea? _________________ The computer helps solving the problems which would have never arised without computers |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 21, 2013 3:20 pm |
|
|
In your version (vs. 4.124), the compiler start-up code leaves PortC as an
analog port, whereas in vs. 4.141 it configures it as digital. To fix your
version and make PortC be digitial, add the line shown in bold below:
Quote: |
void main()
{
char chin;
setup_adc_ports(NO_ANALOGS);
while(1)
{
chin=getc();
putc(chin);
}
} |
|
|
|
tojape
Joined: 14 Jan 2007 Posts: 20 Location: Hungary
|
|
Posted: Fri Jun 21, 2013 3:40 pm |
|
|
Thank you very much!
While you were typing I've found out the workaround adding the following code: :-)
Code: |
#ASM
CLRF 0x18E
#ENDASM
|
When I realized that the initialization is not correct in the assembly listing I tried my version and it worked.
However I will use your solution since yours doesn't depend on direct physical address.
Thank you again!
PS. Just for reference: 4.124 compiler initialization (ANSELC is missing!!!)
Code: |
001C: CLRF FSR0H
001D: CLRF FSR0L
001E: MOVLW 1F
001F: ANDWF STATUS,F
0020: CLRF rs232_errors
0021: MOVLB 03
0022: BCF BAUDCON.BRG16
0023: MOVLW 11
0024: MOVWF SPBRGL
0025: MOVLW A2
0026: MOVWF TXSTA
0027: MOVLW 90
0028: MOVWF RCSTA
0029: CLRF ANSELA
002A: CLRF ANSELB
002B: CLRF ANSELD
002C: CLRF ANSELE
|
_________________ The computer helps solving the problems which would have never arised without computers |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|