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

PIC18F4550 --> rs232 --> PC

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



Joined: 04 Feb 2016
Posts: 11

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

PIC18F4550 --> rs232 --> PC
PostPosted: Mon Feb 22, 2016 2:03 pm     Reply with quote

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! Very Happy
ezflyr



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

View user's profile Send private message

PostPosted: Mon Feb 22, 2016 3:20 pm     Reply with quote

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

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

PostPosted: Mon Feb 22, 2016 3:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 22, 2016 3:50 pm     Reply with quote

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

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

PostPosted: Mon Feb 22, 2016 4:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 22, 2016 5:24 pm     Reply with quote

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

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

PostPosted: Mon Feb 22, 2016 5:41 pm     Reply with quote

Ok guys! A lot of thanks for your answers.
I finally made it! Very Happy

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 Embarassed
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 22, 2016 6:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 22, 2016 8:53 pm     Reply with quote

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

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

PostPosted: Tue Feb 23, 2016 9:50 pm     Reply with quote

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? Confused Shocked
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 23, 2016 10:02 pm     Reply with quote

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

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

PostPosted: Wed Feb 24, 2016 2:05 am     Reply with quote

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 ) Very Happy

A lot of thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 24, 2016 6:05 am     Reply with quote

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
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