View previous topic :: View next topic |
Author |
Message |
arys
Joined: 09 Mar 2007 Posts: 31
|
Rx Tx |
Posted: Thu Jan 10, 2008 8:44 pm |
|
|
Hi, I think this is a stupid question. I dont know how to start or test my HW/SW. I want to control few task from serial port of the PC.
I'm using 16f8X and max232 as interface to serial port. Do you guys know how? or just tell me the link or what ever, so I could do something. may be jjust want to light up LED.
Many thanks. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Jan 11, 2008 8:22 am |
|
|
Do you know how to write a program that sends "Hello World" out the PIC serial port? That is often the first program one writes when learning a new processor or compiler. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Tue Jan 15, 2008 1:43 am |
|
|
I'm interested about this too. I'm using 16f690 and have built a serial level converter from max232.
If there is some short tutorial, which would show a simple example how to read/write data from serial line I would be interested to hear about it. Simple getc/putc doesn't seem to work (I get some random data from PIC and can't write anything to it). |
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Tue Jan 15, 2008 3:08 am |
|
|
Actually the provided example didn't work for me. Could be hardware problem as there were on the thread. I'll double check that first. |
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Tue Jan 15, 2008 3:14 am |
|
|
may be you have to check your circuit between PC-max232-PIC.
you may check it in the net or you can find it here :
http://www.sparkfun.com/commerce/present.php?p=BEE-4-UART
then go through the link I post before. Its work. Because I prove it by myself. If not, try ask others. |
|
|
HOHOHAHA
Joined: 13 Apr 2007 Posts: 24
|
|
Posted: Tue Jan 15, 2008 3:26 am |
|
|
connect the 1uf in MAX232 properly... ie the + and - sign of the capacitors...this may be the only problem...I think... |
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Tue Jan 15, 2008 3:33 am |
|
|
I used these instructions for the max232. I understood it should work. |
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Tue Jan 15, 2008 6:27 am |
|
|
Ok, i checked the max232 part and it should be ok. After testing it I get decent replies from PIC but there is some strange behaviour. The code I'm using follows:
Code: |
char c = '0';
int i = 0b00000001;
...
while(1)
{
putc('a');
DELAY_MS(1000);
OUTPUT_C(i);
c = getc();
putc(c);
i*=2;
}
|
Now it looks like there is some sort of echoing going on. I get "61 00 61" (hex) from PIC, i.e. the letter 'a' two times with null between and after running the second led is on, not the first as I would expect. Looks like the letter PIC sends is somehow read by it and sent to PC again. Also I'm not able to send anything to PIC.
If I add putc('b') after sending letter 'a' my terminal client receives "61 62 00 61 62" in hex.
Any ideas? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jan 15, 2008 6:56 am |
|
|
One possible explanation is that your code is having startup problems. You assume the receive buffer is empty on program start but this might not be the case.
Try adding the following code just before your while loop: Code: | delay_ms(10); // Allow environment to 'stabilize'
while( kbhit() ) // Read all pending data from the UART
{
getc();
} |
Quote: | Also I'm not able to send anything to PIC. | This is very strange when you can send data to the PC. Double check your hardware, especially the Tx line from PC to the Rx pin of the PIC and everything in between. A LED breakout box is very helpful to search these type of errors. |
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Tue Jan 15, 2008 7:39 am |
|
|
ckielstra wrote: | You assume the receive buffer is empty on program start but this might not be the case. |
Yep, this solved the echoing issue. Thanks!
ckielstra wrote: | Double check your hardware, especially the Tx line from PC to the Rx pin of the PIC and everything in between. A LED breakout box is very helpful to search these type of errors. |
I changed capacitors just for trying but no effect. Could the Max232 be broken in this way?
If nothing helps I'll build another serial level converter from scratch. This is first time I'm building anything like this and could simply be some stupid mistake I have made with hw. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jan 15, 2008 8:15 am |
|
|
Quote: | I changed capacitors just for trying but no effect. Could the Max232 be broken in this way? | Everything is possible... but unlikely in this case as the capacitors are used in generating the transmit voltages and are not used in the receive part where you have problems. The RS232 standard is quiet robust, it is not easy to break the driver chips.
Try connecting a led with 180 Ohm series resistor from the Rx input of the PIC to ground. Do you see the led light up when you transmit data from the PC to the PIC?
Post your:
- chip number
- compiler version number
- #use rs232 line |
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Wed Jan 16, 2008 2:06 am |
|
|
ckielstra wrote: | Try connecting a led with 180 Ohm series resistor from the Rx input of the PIC to ground. |
Unfortunately I don't have resistor/led in hand. I'll buy some first aid- collection of miscallenius electronics.
ckielstra wrote: | - chip number
- compiler version number
- #use rs232 line |
Compiler: PCM version 4.062
Use rsr232 (current version, I have tried changing it): #use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
With chip number you mean 16F690? This is "Pickit2 started kit" with CCS compiler.
Terminal clients I'm using are Terminal v1.9 (Br@y) and Hercules. |
|
|
jji
Joined: 11 Jan 2008 Posts: 7
|
|
Posted: Fri Jan 18, 2008 2:41 am |
|
|
Interesting. If I disconnect the external power source for max232 there is no problems reading from PIC, but if it is attached I'll get garbace again. Looks like it has something to do with the problems. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
|
|