View previous topic :: View next topic |
Author |
Message |
silentwol
Joined: 13 Jul 2008 Posts: 4
|
Please help me get serial working |
Posted: Sun Jul 13, 2008 10:30 am |
|
|
I'm using a 16F88 (int osc) with the hardware UART (9600 buad) and a MAX232. Using v4.074 of the compiler. I can send data using printf.
The problem is that I can't seem to receive data. When I connect R1 of the MAX232 to RX of the pin, my voltmeter reads 0.1V between RX and GND. If I disconnect it and measure just R1, it reads 4.57V, my supply voltage. Also, if I measure the current with R1 is connected to RX, it's about 5 mA... which seems awfully high.
I'm guessing this is the problem, as RX should always be high when nothing is being received, right?
Any help greatly appreciated!
Here's he code:
Code: |
#include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#use delay(internal=8M)
#use rs232(uart1, baud=9600)
void main()
{
char c;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
while(1<2)
{
output_high(pin_B0); //blink the LED:
delay_ms(250);
output_low(pin_B0);
delay_ms(250);
printf("getting next char:");
c = getc();
printf(c);
}
}
|
Last edited by silentwol on Sun Jul 13, 2008 10:58 am; edited 2 times in total |
|
|
silentwol
Joined: 13 Jul 2008 Posts: 4
|
|
Posted: Sun Jul 13, 2008 10:41 am |
|
|
Oh, one more thing. When I run this, it always outputs "getting next char:" twice and the LED flashes twice. I.e. it is doing two iterations of the loop. Could this be related at all? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 13, 2008 11:00 am |
|
|
That's not the correct way to use printf() to display a character.
Research it and change it to the correct way. |
|
|
silentwol
Joined: 13 Jul 2008 Posts: 4
|
|
Posted: Sun Jul 13, 2008 11:09 am |
|
|
Ah ok, fixed and changed to:
putc( getc() );
Still no joy though. Have I set up the UART properly? I've tried with the following line instead, but that also isn't working:
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 13, 2008 11:17 am |
|
|
Delete the setup_spi() statement. It's changing the TRIS on pin B2
to be an output pin.
This statement, put in by the Wizard, doesn't need to be there, and is
one of the biggest causes of problems. Delete it. |
|
|
silentwol
Joined: 13 Jul 2008 Posts: 4
|
|
Posted: Mon Jul 14, 2008 2:40 pm |
|
|
Thanks very much, that's working now |
|
|
|