View previous topic :: View next topic |
Author |
Message |
germans
Joined: 04 Feb 2016 Posts: 11
|
PIC18F4550 --> rs232 --> PC |
Posted: Mon Feb 22, 2016 2:03 pm |
|
|
Hi guys, I'm trying to do a simple program: Sending data from a PIC to the PC via rs232.
I'm using a PIC 18f4550 and a USB-UART Converter (it has 6 pins: 3.3, RST, 5, Tx, Rx, Gnd). I'm also using "Termite 3.2" as my terminal program in PC.
So, here is my (simple) code:
Code: |
#include <18f4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,DEBUG,USBDIV,PLL1,CPUDIV4,VREGEN,MCLR,ICSP1
#use delay(clock=16M)
#use rs232(baud=9600,xmit=PIN_D0,rcv=PIN_D1,bits=8)
void main(void)
{
while(1)
{
output_toggle(pin_A3);
printf("Hola\n\r");
delay_ms(1000);
}
}
|
Fuses "HSPLL, USBDIV, PLL1 and CPUDIV4" are declared cause I'm using a 4 MHz crystal and i want CPU clock = 16 M.
Termite is configured as follow: "COM3 9600bps 8N1" (In Device Manager in my PC i found "CP210x USB to UART Bridge" in COM3)
I connected:
D0 pin (from PIC) to Rx pin (from Converter)
D1 pin (from PIC) to Tx pin (from Converter)
Gnd pin (from PIC) to Gnd pin (from Converter)
Termite program says: "Termite is initialized and ready.
Type a string in the edit line (below) and press <Enter>
(or wait for the remote device to send data)."
The problem is i do not receive anything in Termite. Can anyone please help me?
Thanks a lot! |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Feb 22, 2016 3:20 pm |
|
|
Hi,
You need to learn to troubleshoot a problem like this. Is this a timing issue, or is it a serial communications issue?
You don't even say if the PIC is running? Remove the printf from your loop, and time the pulses of an LED connected to A3. They should be 1 second On and 1 second Off. Does this work as expected? You should do this for every PIC project you create!
You should also post a link to your serial-to-USB adapter. That will help us to verify your connections.
The pins you've selected for Tx and Rx will cause the compiler to create a 'software' serial port rather than use the internal hardware UART of the PIC. Is that what you intend? _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
germans
Joined: 04 Feb 2016 Posts: 11
|
|
Posted: Mon Feb 22, 2016 3:37 pm |
|
|
Hello,
It is a serial communications issue. (Led in A3 is 1 second on and 1 second off). The PIC is running. I need to create a software serial port (its just a part of a whole project).
USB - UART Converter: Silicon Labs CP2102 USB to UART BRIDGE
https://www.sparkfun.com/datasheets/IC/cp2102.pdf |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Feb 22, 2016 3:50 pm |
|
|
Hi,
That's the chip datasheet, how about a link to the actual serial-to-USB converter module? _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
germans
Joined: 04 Feb 2016 Posts: 11
|
|
Posted: Mon Feb 22, 2016 4:03 pm |
|
|
Thats exactly the same module: http://www.uv3r.com/Projects.html
(I tested with the jumper in Tx and Rx, using Termite and the module works fine) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Feb 22, 2016 5:24 pm |
|
|
OK, you actually have a USB<>TTL module NOT a USB<>RS232 module which is good, I''ve used a lot of them over the years.
Here's an EASY way to trouble shoot.
Connect USB<>TTL module to PC.
Connect a jumper from TX to RX on the TTL pins of the module.
Now run your terminal program. Everything you type should appear on the screen.
If this works then you've confirmed that the terminal program works, PC is OK and the USB<>TTL module runs fine, all is good.
NOW connect USB<>TTL module to PIC,be sure to connect PIC TX to USB<>TTL module RCV and vice versa. Don't go TX to TX,RX to RX.
That should work.
Jay |
|
|
germans
Joined: 04 Feb 2016 Posts: 11
|
|
Posted: Mon Feb 22, 2016 5:41 pm |
|
|
Ok guys! A lot of thanks for your answers.
I finally made it!
The problem was that USB<>TTL module pins are: TXC and RXC. I connected: TXC to TX from PIC, and RXC to RX from PIC. And it works.
I tried 5 hours and i didnt mix those cables... Someone please kill me |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Feb 22, 2016 6:09 pm |
|
|
Look on the bright side, it only took you 5 hours AND it works ! I once spent 3 DAYS looking for the one and only USB A to USB B cable here. Finally found it next to the OTHER basement telephone....sigh, getting old is so much fun.
Also trying to figure what to do with 9 boxes of databooks and magazines.
Jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Mon Feb 22, 2016 8:53 pm |
|
|
I recycled all mine 10 years ago. ....Right after I moved them ~1200km. ....And I had moved them ~2500km 5 years prior to that.
I didn't feel like moving them again. |
|
|
germans
Joined: 04 Feb 2016 Posts: 11
|
|
Posted: Tue Feb 23, 2016 9:50 pm |
|
|
Well guys, my PIC program works fine when i feed the circuit with the pickit3.
The problem is that when i feed the circuit with an external power supply (5 Vdc) the rs232 communication doesn't work. (But the rest of the program works properly, LEDs signals, SPI communication with another device, etc. Just the rs232 communication with the PC - through USB <> TTL module - doesn't work).
Any ideas why? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Tue Feb 23, 2016 10:02 pm |
|
|
Not to sure why you use an external power supply. You should be able to power the PIC from the +5 available from the USB<>TTL module.
I'll have to think about it more....
it is odd....
Jay |
|
|
germans
Joined: 04 Feb 2016 Posts: 11
|
|
Posted: Wed Feb 24, 2016 2:05 am |
|
|
Fixed, it was a problem with "Gnd" from the USB<>TTL module.
I'm using an external power supply just to verify how it works. Cause in future my program will send via RS232 data to another device, not a PC (i mean, at the end i will not use an USB<>TTL module, now is just development phase )
A lot of thanks! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Feb 24, 2016 6:05 am |
|
|
whew !!! Man I'm sure you found it as I've used lots of those modules and they've always worked both for +5 and +3V PICs.
Jay |
|
|
|