socket Guest
|
problem serial port 18f8722 |
Posted: Mon Oct 19, 2009 5:50 am |
|
|
Hi to everyone.
I am trying to communicate a 18F8722 with a modem via serial port rs232. I have some problems because the comm does not work. I guess I have some problems with the #fuses. I wrote a very simple code to write a string to the modem. Here's my code:
-define.h file:
Code: |
//define.h
#device adc=10
#fuses NOWDT,WDT32768,H4,NOPROTECT,NOIESO,NOBROWNOUT,BORV25,NOPUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOCPB, NOEBTRB,NOEBTR,NOWRTD,NOWRTC,NOWRTB,NOFCMEN,NOLPT1OSC,MCLR,NOXINST,MCU
//-----------------------------com serie --------------------------------------
//#use delay(clock=40000000)
#use delay(clock=38400000)
#use rs232(baud=9600,parity=N,UART1, xmit=PIN_C6, rcv=PIN_C7, bits=8,STOP=1, stream=MODEM)
|
-main:
Code: |
//main.c
#include <18F8722.h>
#include <define.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
void main(void) {
setup_oscillator(OSC_32MHZ);
fputs("0104pppp",MODEM);
while(true){ }
}
|
The serial comm just does not work. Could someone give me some hints?
Thanks in advance. |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 19, 2009 10:58 am |
|
|
Quote: |
#use delay(clock=38400000)
void main(void) {
setup_oscillator(OSC_32MHZ);
fputs("0104pppp",MODEM);
while(true){ }
}
The serial comm just does not work.
|
You are setting the internal oscillator frequency to 32 MHz, but you are
telling the compiler that it's 38.4 MHz. That's wrong. The #use delay()
value must always match the oscillator frequency. The compiler uses
the #use delay() value to calculate the baud rate register value for the
UART. |
|