CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

serial rs232 reading problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 19, 2009 7:22 pm     Reply with quote

If this program doesn't work, when typing characters in a serial terminal
window on your PC, then I'd say there is something wrong with your
hardware.
Code:
#include <18F2550.h>
#fuses HS, NOWDT, PUT, NOBROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//==========================
void main()
{
char c;

while(1)
  {
   c = getc(); // Get char from PC
   putc(c);   // Send it back to the PC
  }

}
Guest








PostPosted: Sat Feb 21, 2009 7:35 am     Reply with quote

Hi,

I hope you can help me. I used the echo routine you posted and I am able to echo character keypresses. The problem is that the characters echoed is not character that was pressed (mostly 0XFAs).

This is on a 16F690 using the internal oscillator. The exact code I am using is as follows:
Code:

#include <16F690.h>
#fuses HS, NOWDT, PUT, NOBROWNOUT,INTRC_IO
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, parity=N, rcv=PIN_C7, ERRORS)

//==========================
void main()
{
char c;

setup_oscillator(OSC_4MHZ); /* tried this with and without */

while(1)
  {
   c = getc(); // Get char from PC
   putc(c);   // Send it back to the PC
  }

}


I suspect that this is a clock/timing issue but I am at a loss what to do next.

TIA
agimat



Joined: 09 Feb 2009
Posts: 1

View user's profile Send private message Visit poster's website

Solved
PostPosted: Sat Feb 21, 2009 1:31 pm     Reply with quote

Replaced
#use delay(clock=20000000)

with
#use delay(clock=8000000)


I was using the 16F690's internal clock at 8Mhz.

That fixed it.
_________________
http://rlachenal.com
Ttelmah
Guest







PostPosted: Sat Feb 21, 2009 3:01 pm     Reply with quote

Also, as a 'comment', get rid of the HS fuse at the start of the fuse line.
You can't select both the HS (high speed crystal) oscillator, and the internal RC oscillator. On some chips, selecting multiple setups like this, will stop it working at all, it is just 'luck' that it is working.

Best Wishes
obarcia



Joined: 14 May 2009
Posts: 1

View user's profile Send private message Send e-mail

serial rs232 reading problem (problema resuelto)
PostPosted: Thu May 14, 2009 4:06 pm     Reply with quote

Esta es una solución que alguna vez utilice en la serie de PIC 16Fxxx, leyendo los comentarios de todos ustedes compañeros, he llegado hacer funcionar el PIC18F2550, también tuve problema con la RX (el usart y SPI ) están sobre el mismo pin, borrando esa línea de código setup_spi(SPI_SS_DISABLED) funcionó (PCM programmer), gracias a todos ustedes porque también me sirvió la ayuda de todos ustedes.

Code:
#include <18F2550.h>
#device adc=8
#use delay(clock=20000000)
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//------------------------- Variables Globales -------------------------\\
char C='f';

//---------------------------INTERRUPCIONES-----------------------------\\
#int_RDA
void serial_isr() {                    // Interrupción recepción serie USART
   C=0x00;                       // Inicializo caracter recibido
   if(kbhit()){                  // Si hay algo pendiente de recibir ...
      C=getc();                  // lo descargo y ...
   }
   printf("char: ");
   putc(c);
   printf("\r\n");
}

//----------------------PROGRAMA PRINCIPAL-------------------------------\\
void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(global);
   
   // TODO: USER CODE!!
   printf("Test: ");
   putc(c);
   printf("\r\n");
   while(true)
   {
   }
}


Solo lo he simulado para este pic18f2550, pero en la serie 16Fxxx si lo he cargado al pic y ha funcionado

obarcia
MONTECRISTI-MANABI-ECUADOR
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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