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 CCS Technical Support

Can PIC receive Serial data with 2 stop bits ?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Jun 26, 2006 2:45 pm     Reply with quote

Eugeneo wrote:
PCM programmer wrote:
I tested the program shown below with HyperTerminal Private Edition
and it worked OK. I could type keys on the PC keyboard and see them
echo'ed back from the PIC and displayed on the HyperTerminal window.
http://www.hilgraeve.com/htpe/download.html

I setup HyperTerminal for:
Connection: Direct connection to Com1
Bits per Second: 300
Data bits: 7
Parity: Even
Stop bits: 2
Flow Control: None
Advanced: No fifos enabled

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=300, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7)

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

while(1)
  {
   c = getc();  // Wait for char from PC
   putc(c);   // Then send it back to PC
  }
}


Wouldn't this disable the hardware usart though since it's 7 data bits?

Not necessarily since there are actually 8 bits of data. CCS could do the same thing that I did. And in fact they do but something isn't quite right. Now if you did 7 data bits with no parity then it would have to be a soft uart.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 2:49 pm     Reply with quote

It worked for me with PCM vs. 3.249. Here is the text displayed in
the HyperTerminal window as I typed "test". However, because printf()
is within the while() loop, I had to type slowly -- otherwise, it would miss
key presses.

Quote:
t
Running...
e
Running...
s
Running...
t
Running...


Also, I can confirm that it is using the hardware UART. The .LST file
shows that it's accessing TXREG and RCREG.
Eugeneo



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 2:57 pm     Reply with quote

Mark wrote:
Not necessarily since there are actually 8 bits of data. CCS could do the same thing that I did. And in fact they do but something isn't quite right. Now if you did 7 data bits with no parity then it would have to be a soft uart.


That quite impressive that CCS would have such a workaround for the limitation in hardware. How would somebody know about something like this besides assuming the best and testing it out?

For example, I've always used Data>>16 for speed. But I found out you can actually do Data/4 and it would produce the same code.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 3:19 pm     Reply with quote

You have to look at the .LST file to see what the compiler is doing.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Jun 26, 2006 3:35 pm     Reply with quote

PCM programmer wrote:
It worked for me with PCM vs. 3.249. Here is the text displayed in
the HyperTerminal window as I typed "test". However, because printf()
is within the while() loop, I had to type slowly -- otherwise, it would miss
key presses.

Quote:
t
Running...
e
Running...
s
Running...
t
Running...


Also, I can confirm that it is using the hardware UART. The .LST file
shows that it's accessing TXREG and RCREG.


This code would not work.
Code:

#include <18F252.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7)

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

while(1)
  {
   printf("\r\nRunning...\r\n");
   c = getc();  // Wait for char from PC
   putc(c);   // Then send it back to PC
  }
}


This code would not work fully. The chars would echo back but "Running" was not displayed.
Code:

#include <18F252.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7)

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

printf("\r\nRunning...\r\n");
while(1)
  {
   c = getc();  // Wait for char from PC
   putc(c);   // Then send it back to PC
  }
}


This code would not compile. It complained about not knowing what putchar is.
Code:

#include <18F252.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7)

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

printf(putc,"\r\nRunning...\r\n");
while(1)
  {
   c = getc();  // Wait for char from PC
   putc(c);   // Then send it back to PC
  }
}


However, this code worked just fine
Code:

#include <18F252.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7)

void myputc(char c)
{
  putc(c);
}
//======================================
void main()
{
char c;

printf(myputc,"\r\nRunning...\r\n");
while(1)
  {
   c = getc();  // Wait for char from PC
   putc(c);   // Then send it back to PC
  }
}


I am also using 3.249
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 3:42 pm     Reply with quote

I don't have my 18F452 board with me. I will check it this evening
and get back to you.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Jun 26, 2006 3:54 pm     Reply with quote

PCM programmer wrote:
I don't have my 18F452 board with me. I will check it this evening
and get back to you.


Works with a 16F876 version 3.217 but not with 3.249
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 4:39 pm     Reply with quote

Hi Mark You are right it doesnt work in the Hyperterminal .

I have tried the PCM Programmer code that doesnt work. with the following settings

If you set 300,E,7

I typed ABCDEFGHIJK and got echoed
aB{sC~|~dE@ghajsk`h ~

As for hardware i have a CCS Protype Board with a BreadBoard That is soldered on to the PIC PCB By CCS . it has Label C6 and C7 where you can Insert a jumper . That is where I have Connected the Serial signal.

i don know how to Embed a Picture in the Post otherwise I would show you the whole set up .

Believe me I am geting the correct data on the PC Hypertermainal . But Not through the PIC .
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 5:04 pm     Reply with quote

Yes this code works fine on the hyperterminal . But How do i get the other code to work ???
Crying or Very sad

Code:
#include <16F877A.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=300, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7)

void myputc(char c)
{
  putc(c);
}
//======================================
void main()
{
char c;

printf(myputc,"\r\nRunning...\r\n");
while(1)
  {
   c = getc();  // Wait for char from PC
   putc(c);   // Then send it back to PC
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 5:19 pm     Reply with quote

At this point, I'm not sure what you mean by "the other code".
Your post at the start of this thread complained that the 300 baud
code didn't work. That's been solved. So what is the other code ?
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 5:33 pm     Reply with quote

This code I am still getting Garbage out with the same settings .

Thanks



Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=300, xmit=PIN_C6, rcv=PIN_C7, ERRORS, PARITY=E, BITS=7,stream=MSF)
#define BUFFER_SIZE 30
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr()
{
  int t;
 
 // Get rid of the parity.  You may want to check it.  This code doesn't!
 buffer[next_in]=(getc()&0x7F);
 t=next_in;
 next_in=(next_in+1) % BUFFER_SIZE;
 if(next_in==next_out)
   next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void putc_parity(char c)
{
  int i;
  int count = 0;

  for(i=0;i<7;i++)
  {
    if (bit_test(c,i))
      count++;
  } 
  if (bit_test(count,0))
    bit_set(c,7);
  putc(c);
}

void main() {

   enable_interrupts(global);
   enable_interrupts(int_rda);

   printf(putc_parity,"\r\n\Running...\r\n");

   // The program will delay for 10 seconds and then display
   // any data that came in during the 10 second delay

   do {
      delay_ms(10000);
      printf(putc_parity,"\r\nBuffered data => ");
      while(bkbhit)
        putc_parity( bgetc() );
   } while (TRUE);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 5:57 pm     Reply with quote

It works me with a 16F877 with PCM vs. 3.249. I could try the "A" chip
later. I also tried it with Mark's parity stuff removed, to let CCS handle
the parity, and that worked too.
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 6:47 pm     Reply with quote

Thaks PCM Programmer

I am also using 3.429 with a CCS Software board and a RS232 Module that is sending serial data .

Please let us know if you get is working with a Chip. Many Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 10:42 pm     Reply with quote

I tested the program above (the one with the putc_parity, etc.) with
a 16F877A and it works for me. I didn't make any changes at all.
I dropped it into MPLAB and compiled with PCM vs. 3.249 and
programmed it into a PicDem2-Plus board running at 4 MHz, and it
worked.


Quote:

As for hardware i have a CCS Protype Board with a BreadBoard that is
soldered on to the PIC PCB By CCS. It has Label C6 and C7 where you
can Insert a jumper . That is where I have Connected the Serial signal.


Can you post a link to the CCS webpage that shows your board ?
Is this the one you have:
http://www.ccsinfo.com/product_info.php?products_id=swprotoboard
Or is it a different one ?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Tue Jun 27, 2006 6:38 am     Reply with quote

PCM programmer wrote:
It worked for me with PCM vs. 3.249. Here is the text displayed in
the HyperTerminal window as I typed "test". However, because printf()
is within the while() loop, I had to type slowly -- otherwise, it would miss
key presses.

Quote:
t
Running...
e
Running...
s
Running...
t
Running...


Also, I can confirm that it is using the hardware UART. The .LST file
shows that it's accessing TXREG and RCREG.

I retested with a 16F876 and a 4MHz xtal. It doesn't work with Hyperterminal but does with another terminal program. I won't trust Hyperterminal ever again!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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