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

Hypertermial Showing Garbage Despite Correct Baud Rate
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mka879



Joined: 30 Oct 2015
Posts: 34

View user's profile Send private message

Hypertermial Showing Garbage Despite Correct Baud Rate
PostPosted: Fri Oct 30, 2015 1:49 am     Reply with quote

I wrote the following Hello World program but the hyperterminal is showing garbage.
Code:

#include <gsm test.h>
#include<string.h>
#use rs232(baud=9600,xmit=PIN_c6,rcv=PIN_c7,PARITY=N,BITS=8,STOP=1)
void main()
{
     output_bit(pin_b7,1);  //initialization indicated by LED
     delay_ms(1000);
     output_bit(pin_b7,0);
     delay_ms(1000);
      printf("Hello World");
   while(TRUE)
   {
   }     
}

the gsm.h file is as follows
Code:

#include <16F877A.h>
#device ADC=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(crystal=20000000)

I am using CCS PCWHD version 5.015 and a serial to usb converter. I checked a GSM module on teratrum(terminal software) and successfully send and receive messages using the same serial to usb converter and the terminal program so the converter and software cannot be faulty. Baud rate on the terminal program is 9600. Why am I not getting correct output? Please help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 2:07 am     Reply with quote

What have you got to do the voltage level conversion from TTL to RS232 on the PIC?.

A PIC _does not generate 'RS232'_. It generates 'async TTL serial', that can be converted to 'RS232', using a chip like a MAX232. Without this the output will be inverted compared to what a PC serial port expects.

It's always been to me a little bit confusing the way 'RS232' is referred to in the CCS driver, but 'async TTL serial', doesn't really help explain it, and they assume that people will realise that they need a driver chip.
mka879



Joined: 30 Oct 2015
Posts: 34

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 2:36 am     Reply with quote

[quote="Ttelmah"]What have you got to do the voltage level conversion from TTL to RS232 on the PIC?.

A PIC _does not generate 'RS232'_. It generates 'async TTL serial', that can be converted to 'RS232', using a chip like a MAX232. Without this the output will be inverted compared to what a PC serial port expects.

It's always been to me a little bit confusing the way 'RS232' is referred to in the CCS driver, but 'async TTL serial', doesn't really help explain it, and they assume that people will realise that they need a driver chip.[/quote
]

I am using serial to uab converter instead of max232. Doesn't the converter handle the conversion? If the converter couldn't do this how did gsm module communicated which outputs TTL signals?
mka879



Joined: 30 Oct 2015
Posts: 34

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 2:37 am     Reply with quote

Ttelmah wrote:
What have you got to do the voltage level conversion from TTL to RS232 on the PIC?.

A PIC _does not generate 'RS232'_. It generates 'async TTL serial', that can be converted to 'RS232', using a chip like a MAX232. Without this the output will be inverted compared to what a PC serial port expects.

It's always been to me a little bit confusing the way 'RS232' is referred to in the CCS driver, but 'async TTL serial', doesn't really help explain it, and they assume that people will realise that they need a driver chip.


I am using serial to usb converter instead of max232. Doesn't the converter handle the conversion? If the converter couldn't do this how did gsm module communicated which outputs TTL signals?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 2:45 am     Reply with quote

mka879 wrote:
Ttelmah wrote:
What have you got to do the voltage level conversion from TTL to RS232 on the PIC?.

A PIC _does not generate 'RS232'_. It generates 'async TTL serial', that can be converted to 'RS232', using a chip like a MAX232. Without this the output will be inverted compared to what a PC serial port expects.

It's always been to me a little bit confusing the way 'RS232' is referred to in the CCS driver, but 'async TTL serial', doesn't really help explain it, and they assume that people will realise that they need a driver chip.


I am using serial to uab converter instead of max232. Doesn't the converter handle the conversion? If the converter couldn't do this how did gsm module communicated which outputs TTL signals?


No.

The USB converter is usually a USB to RS232 converter.
It allows USB only PCs to behave like legacy PCs with a real RS232 port.

So you probably still need a MAX232 (or equivalent) for your PIC.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 3:32 am     Reply with quote

If you look at modules like this:

<http://www.ebay.com/bhp/gsm-modem-rs232>

These output RS232, _not_ TTL. You can get TTL ones, but have to look for this specifically. Then 99% of USB to serial PC adapters output/input RS232, not TTL. Again there are a few special ones that do use TTL, but these have to be carefully looked for. Such as:

<https://www.sparkfun.com/products/12977>
temtronic



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

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 5:12 am     Reply with quote

Sounds like you have a USB<>RS232 module and you need a USB<>TTL module.

You have a couple options.

1) Buy a USB<>TTL module and connect directly to the PICs UART pins. I've done this for almost a decade.Simple and easy.

2) Buy a 'MAX232' type chip and connect between the PIC and your USB<>RS232 module.This does require more parts(MAX232 + 4 caps) and wiring but would allow the PIC to have a true RS232 interface.

Cost. #1 is about $2USD. #2 is about $1
Labour.#1 is easy, NONE,#2,have to wire up 5 more components.properly!

Since ALL PCs these days do NOT have a true RS232 port,just USB option #1 is probably the best choice.

Jay
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Fri Oct 30, 2015 5:27 am     Reply with quote

Keep in mind also that if it is a USB to RS232 converter, that you may have damaged your PIC's TTL pins. RS232 can run up to +- 15v. I don't remember off hand what most converters boost to (probably 5v...but just a guess). Be ready to have a spare PIC if that is the case.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Oct 31, 2015 11:58 am     Reply with quote

I've just measured the signals from a randomly selected USB to RS232 converter.
I'm getting roughly +/-8V.

I've also tried the same test on a legacy PC, and got just shy of +/-10V.

I've only used the 5V version of MAX232 so can't comment on the 3V variety.
The booster on the 5V version is trying to double and invert the supply.
So the best it could do is +/- 10V, in practice I find I get +/-7V to +/-8V.

If the OP does HAVE A USB to RS232 converter he may have stuffed the PIC.
(All depends on current capability.)

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Oct 31, 2015 12:15 pm     Reply with quote

Fortunately relatively low.
They have to produce 3v into a couple of Kohms only, so about a mA,

I've not seen a RS232 driver damage a logic gate in years.
mka879



Joined: 30 Oct 2015
Posts: 34

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 1:27 am     Reply with quote

Ttelmah wrote:
If you look at modules like this:

<http://www.ebay.com/bhp/gsm-modem-rs232>

These output RS232, _not_ TTL. You can get TTL ones, but have to look for this specifically. Then 99% of USB to serial PC adapters output/input RS232, not TTL. Again there are a few special ones that do use TTL, but these have to be carefully looked for. Such as:

<https://www.sparkfun.com/products/12977>


Thank you Mike and Ttelmah. I figured out that the sim900 mini board has a max232 installed so the ttl voltage is converted to RS232 which I didn't noticed.

I have one another problem however related to AT commands. I am using PIC16f877a and the ccs c compiler mentioned in above post. I tested my code logic first using teraterm. The code is supposed to send AT until it receives OK from modem and make pin b7 high on reception of OK. When I checked it on tera term it was sending AT and when I typed OK it stopped and raised pin b7 high. But when I checked it on hardware it did not respond as expected. I believe it has something to do with <CR> and <LF> please help. The code is as follows

#include <gsm test.h>
#include<string.h>
#use rs232(baud=9600,xmit=PIN_c6,rcv=PIN_c7,PARITY=N,BITS=8,STOP=1)
char flag[10];
int index = 0;
#int_rda
void isr_rda(void)
{
output_bit(pin_b4,1);
delay_ms(1000);
output_bit(pin_b4,0);
delay_ms(1000);
flag[index++] = getc();
clear_interrupt(int_rda);
}

void main()
{
//time for GSM Modem to initialize and register on the network
output_bit(pin_b7,1);
delay_ms(6000);
output_bit(pin_b7,0);
delay_ms(6000);
enable_interrupts(global);
enable_interrupts(int_rda);

char par[5];
par = "OK";
flag = "no";
//send AT until OK is received
while(strcmp(flag,par))
{
printf("AT\n");

}
//flag when OK is received
output_bit(pin_b7,1);

}

The LED on b4 blinks twice indicating two characters are received but b7 remains low. Please help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 2:07 am     Reply with quote

Do a search here on why you should not have delays in interrupt handlers.

Basic rule of interrupt handlers, is they should handle the job that the interrupt implies (so INT_RDA, should receive _one_ character, which is what the interrupt says is available), and then exit as fast as possible. Nothing else.
mka879



Joined: 30 Oct 2015
Posts: 34

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 3:12 am     Reply with quote

Ttelmah wrote:
Do a search here on why you should not have delays in interrupt handlers.

Basic rule of interrupt handlers, is they should handle the job that the interrupt implies (so INT_RDA, should receive _one_ character, which is what the interrupt says is available), and then exit as fast as possible. Nothing else.


Hmmm good point...... but I was wondering it should not be a significant factor in the current context since the code works as expected on tera term.
mka879



Joined: 30 Oct 2015
Posts: 34

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 3:55 am     Reply with quote

Ttelmah wrote:
Do a search here on why you should not have delays in interrupt handlers.

Basic rule of interrupt handlers, is they should handle the job that the interrupt implies (so INT_RDA, should receive _one_ character, which is what the interrupt says is available), and then exit as fast as possible. Nothing else.


Sorry I connected RX and TX of sim900 wrongly. Now the problem might be in sending AT plus "enter key". In the code I am sending AT with \n. My question is how to send enter key?
ezflyr



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

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 5:50 am     Reply with quote

Hi,

Don't fool yourself, delays inside interrupt handlers are a 'significant factor' in virtually *any* circumstance! Just don't do it!

To answer your specific question, the Carriage Return (or Enter key) can be sent with '\r'.
_________________
John

If it's worth doing, it's worth doing in real hardware!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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