View previous topic :: View next topic |
Author |
Message |
maxD
Joined: 16 Dec 2013 Posts: 22
|
sending data to pic via max 232 by rs232 not working in prot |
Posted: Sat Dec 28, 2013 9:57 pm |
|
|
Hi guys i posted this post in two forums before i post this here
but no one gave me a answer.I know this site is only for ccs c problems not for proteus problems. so only for now please help me with this problem if you can
I need send data between pc and pic so i made this schematic using proteus wrote the very simple ccs c code for pic 18f2550.
Code: |
#include<18f2550.h>
#fuses NOWDT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,INVERT,parity=N,bits=8)
void main()
{
char a;
printf("Start typing ...\n.");
while(1)
{
a=getc();
putc(a);
}
}
|
and my schematic is goto http://obrazki.elektroda.pl/2276196000_1388233204.jpg
and when i run the code the result is like this goto http://obrazki.elektroda.pl/6774018100_1388233383.jpg
So friend before this i used ex_sisr.c with little change
Code: |
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#elif defined(__PCH__)
#include <18F2550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS,INVERT)
#elif defined(__PCD__)
#include <30F2010.h>
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, UART1A)
#endif
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_rda
void serial_isr()
{ int t;
buffer[next_in]=getc();
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 main()
{
enable_interrupts(int_rda);
#if defined(__PCD__)
enable_interrupts(intr_global);
#else
enable_interrupts(global);
#endif
printf("\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("\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE);
}
|
so proteus result for this is http://obrazki.elektroda.pl/5680434400_1388234039.jpg
So in the both above cases i clicked on rx vir: terminal pressed keyboard buttons but they (the characters i pressed) did not appear in output terminal.
If i say clearly in first case (according to my little code) i pressed keys buttons but output is like in image ("start typing" then nothing).
In second case the long code i keep pressing keys for 10s but output like the image i added ( buffered data..buffered data.. as in there).
And also i used Hyperterminal with virtual serial port software in second experiment but same results came as in image.
I'm using proteus 7.8
Think you clearly got my problem and show me how to fix this...
Please help me guys!! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 28, 2013 10:06 pm |
|
|
When using the RS232 chip (appears to be MAX232) you should not use the INVERT switch. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
maxD
Joined: 16 Dec 2013 Posts: 22
|
|
Posted: Sat Dec 28, 2013 10:11 pm |
|
|
thanks for quick replying
but here i spend two days searching websites to fix this but unable to do it.
And here if there is no INVERT the output will be wrong. I tested it before. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 28, 2013 10:32 pm |
|
|
sounds like a Proteus problem to me... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 28, 2013 10:41 pm |
|
|
Did you read the post near the top of the forum. We don't want to solve
your Proteus simulator problems. You should google for it.
In your case, you have a problem with the virtual terminal in Proteus
not working as you expected, when you use a max232 and the invert
option. So, google for this:
Quote: | Proteus virtual terminal max232 invert
|
For any Proteus questions in the future, please google for the answer. |
|
|
maxD
Joined: 16 Dec 2013 Posts: 22
|
|
Posted: Sat Dec 28, 2013 10:51 pm |
|
|
to avoid that invert case you mentioned i put the invert in # use rs232..see the result is in images
And I spent 2 days searching on web for answer. so what you guys suggest me to do? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 29, 2013 1:13 am |
|
|
Well how many inversions do you have ? The total number of inversions
must be an even number, meaning either 0 or 2.
You have one device that always inverts, which is the Max232.
Then you have the PIC, which can optionally invert.
Then you have the virtual terminal which can also optionally invert.
Since the Max232 always inverts, that means you must have only
one other inversion in the circuit. Either the PIC or the virtual terminal
must be configured to invert, but not both of them. |
|
|
maxD
Joined: 16 Dec 2013 Posts: 22
|
|
Posted: Sun Dec 29, 2013 1:30 am |
|
|
ya i used only 2 invertions..
one is by max232
other one is by pic
and you see i'm getting the output start typing buffered data=>..(look my image) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 29, 2013 2:15 am |
|
|
I can't fix Proteus problems. My suggestion is to simplify the program
and the circuit to the smallest possible size.
1. Get rid of the Max232 and the DB9 connector.
2. Get rid of the ex_sisr.c code.
3. Just have a simple program with a printf statement with "Hello World".
4. Get rid of all INVERT parameters.
i.e., Strip your test setup down to almost nothing. |
|
|
maxD
Joined: 16 Dec 2013 Posts: 22
|
|
Posted: Sun Dec 29, 2013 2:17 am |
|
|
KK got your point thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Sun Dec 29, 2013 2:47 am |
|
|
Start at the beginning.
You do _not_ want INVERT.
Key is to understand that 'TTL async serial' (which is what the PIC UART generates), is designed to connect directly to the MAX232, and is the correct way round. The 'INVERT' keyword is designed for people attempting to run without the inversion in the MAX232.
Internally the PC uses the same logic, and has a built in MAX232 (equivalent), to invert the signal before it comes out of the RS232 port. RS232, is an 'inverted' transmission standard (logic '0', is a high level on the RS232 lines), and the MAX232 generates this inversion. By adding 'INVERT', you are ending up inverting the signal three times (once in the INVERT, once in your MAX232, and once in the MAX232 in the 'virtual PC'). This won't work....
So get rid of INVERT.
Using INVERT has a much larger implication as well though. The PIC hardware cannot generate inverted serial. So as soon as you use 'INVERT', you switch to using software RS232. This will stop ex_sisr from working, since it _relies_ on using the hardware.
As PCM programmer says, 'start simple':
Code: |
#include<18f2550.h>
#fuses NOWDT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,UART1,ERRORS, parity=N,bits=8)
void main(void)
{
char a;
delay_ms(20); //The capacitors in the MAX232 take a few mSec to charge
printf("Start typing ...\n.");
while(1)
{
a=getc();
putc(a);
}
}
|
When using the hardware UART, you should _always_ have the ERRORS keyword, unless _you_ explicity handle errors yourself.
Since I'm using the hardware UART, I can just use 'UART1', instead of the pin names.
Note the delay at the start. Proteus does not simulate the need for this correctly, but if you start sending straight away on a 'real' MAX232, the first character may well be corrupted. It takes perhaps 10mSec for the chip to charge it's output capacitors.
This code runs correctly on a PIC18F2550, with a 20MHz crystal, and MAX232.
Best Wishes |
|
|
maxD
Joined: 16 Dec 2013 Posts: 22
|
|
Posted: Sun Dec 29, 2013 3:20 am |
|
|
K I got your point
Thank you so much !! |
|
|
|