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

PIC16F628A RS232 PC => PIC doesn´t work

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



Joined: 22 Feb 2013
Posts: 6

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

PIC16F628A RS232 PC => PIC doesn´t work
PostPosted: Fri Feb 22, 2013 12:20 pm     Reply with quote

Hello

I´m using the PIC16F628A with build-in UART in order to receive data from a PC with Hyperterminal. I can send strings using printf(); to the PC, but my code to flash a Led by hitting an 'A' at the Hyperterminal doesn´t work.
Code:

void main(){

printf("/r/nHello, I´m PIC16F628A");
while(TRUE){
char answer;
do {
answer = getch();
}while(answer != 'A');

output_high(PIN_B3);
delay_ms(1000);
output_low(PIN_B3);
delay_ms(1000);
}
}

My MAX232 Driver is working fine, if I take out my pic out of my board and make a bridge between B1 and B2 (Uart pins) and type something in the Hypterterminal it comes back.

I would really looking forward to an answer.

MartinS
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 12:44 pm     Reply with quote

Post your fuses and #rs232 setup. There are a couple of things here that could cause problems.
Add setup_spi(FALSE) to your code. The pins are shared with the SPI on this chip, and though it should default to off, better to be sure.

Best Wishes
MartinS



Joined: 22 Feb 2013
Posts: 6

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

PostPosted: Fri Feb 22, 2013 12:57 pm     Reply with quote

Here my fuses and the rs232 setup

Code:

#FUSES NOWDT
#FUSES HS
#FUSES NOBROWNOUT
#FUSES NOLVP

#use delay(clock=12000000)

#use rs232(baud=2400,parity=N,uart,bits=8,stream=PC)



Adding setup_spi(FALSE) has as a result a compiler error that says:
Code:
Undefined identifier -- setup_spi
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 1:46 pm     Reply with quote

Key thing add ERRORS to the RS232 setup.
Without this, if the RS232 line goes low during the boot-up, or at any time in the long pauses, the receive part of the UART _will_ be hung.

I thought that chip had SPI obviously it doesn't.

Best Wishes
MartinS



Joined: 22 Feb 2013
Posts: 6

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

PostPosted: Fri Feb 22, 2013 3:32 pm     Reply with quote

Thanks for your information.
But unfortunately, with the ERRORS in the rs232 setup it doesn´t work.
I tried some other code:
Code:

...
int is_charakter_ready;
do{
is_charakter_ready = kbhit();
}while(is_charakter_ready == 0);
...

But the Pic simply don´t want to receive my character.

The Pic is definitely getting the signal from the max232, because if i put a led between GND and the receive Pin, it is flashing a little bit, while I'm hitting keys.

MartinS
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 3:56 pm     Reply with quote

Hi,

What version is your compiler??? You can find the version number at the
top of the .lst file. It's in the format x.xxx, eg., 4.104.

For "test code", you sure do seem to favor "odd" configurations! Why not
keep it totally simple?

Put a While() loop in Main() like this:

Code:

While(1){

  putc(getc());

}



This code should echo back to the PC any characters that are received by
the PIC.

If it still doesn't work, can you post your schematic? If you've got a scope,
take a look at the Rx pin on the PIC while your send data from the PC.

John
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 4:37 pm     Reply with quote

As suggested: keep it simple.
Also, things are way easier when you always post the complete code. That way we know your exact configuration and can easily copy/paste your code.

Code:
#include <16F628A.h>
#FUSES NOWDT
#FUSES HS
#FUSES PUT
#FUSES NOLVP

#use delay(clock=12000000)

#use rs232(baud=2400, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

void main()
{
   while(1)
   {
      putc( getc() );
   }
}
Note how I added the PUT fuse and removed NOBROWNOUT.
Personal preference is to always mention the UART pin numbers instead of using the 'UART' keyword. It helps me remember the correct connections. Disadvantage (or advantage if you want to) is that the CCS compiler will generate a software UART when I define the wrong pin numbers.

When the above posted program fails for you, then it is either your compiler (always post the compiler version number) or the hardware.
MartinS



Joined: 22 Feb 2013
Posts: 6

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

PostPosted: Sat Feb 23, 2013 4:13 am     Reply with quote

Hi

My compiler version is 4.130. It still don´t works, even with the simple echo
Code:
 putc(getc());
. Maybe you find a problem with my schematic. I already tryed a new PIC16F628A but there is no character recived by the pic.

@ckielstra If i use the pin numbers instead of UART in the rs232 setup the PC is reciving some character bullshit.

Here the schematic:
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Sat Feb 23, 2013 5:06 am     Reply with quote

Some little comment things:

1) No loading capacitors shown on the crystal.
2) No HF blocking capacitors anywhere. Bigger is not always better. Electrolytic capacitors have poor HF performance. Look at a PC motherboard, and you will see the large electrolytic capacitors around where the supply comes in, but then dozens (even hundreds!) of small (normally ceramic or polyester) capacitors round the board. Usually one every couple of IC's. These are designed to block the HF, which each IC generates, and can otherwise cause problems (both in RFI, and in functional terms). You should _always__ have something like a 0.1uF ceramic by the supply legs of the PIC. As close as possible, and the same wherever there is an IC that does any significant amount of high frequency work. The MAX232, should have another 1uF, right by the chip to between ground and the Vcc. If you look at the data sheet, it shows five capacitors.
3) You should be driving all the pins that are currently floating. Either drive them in code, or add a pull up/down resistor. Leaving lines floating is not recommended.

Best Wishes
MartinS



Joined: 22 Feb 2013
Posts: 6

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

PostPosted: Sat Mar 02, 2013 7:46 am     Reply with quote

Finally i've found the problem. I never thought of checking this, because if i took out the PIC and made a bridge I got a brilliant echo.
On my Max232 adapter i had two LEDs (not in the schematic because i thought they never could cause problems) with the same GND. After i put a diode there it was working fine.

Big thanks to you guys for your fast help.

MartinS
Very Happy Very Happy Very Happy
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Mar 02, 2013 8:59 am     Reply with quote

Diodes? on A MAX232? what for?
_________________
CCS PCM 5.078 & CCS PCH 5.093
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