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 support@ccsinfo.com

TC35 and PIC18F25K20 UART problem
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
Dempsey



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

TC35 and PIC18F25K20 UART problem
PostPosted: Mon Oct 05, 2015 12:34 pm     Reply with quote

Hello,
I have a problem with my GSM module and PIC18F25K20 UART communication. First I would like to display the RING string on the LCD. Unfortunately it doesn't work because when I call the module, only two "characters" appears on the LCD instead of RING string. http://kepfeltoltes.hu/151005/DSC_0291_www.kepfeltoltes.hu_.jpg) Anyone can help me what's wrong in my code?
Code:
#include <18f25k20.h>
#include <string.h>

#fuses put,nolvp,noprotect,intrc_io,nowdt,
#use delay (clock=16MHz)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,bits=8,parity=N,stop=1,ERRORS)

/////////////////////////////////////////////////////////////
#include<flex_lcd.c>
#include <input.c>

#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;
   if(++next_in==BUFFER_SIZE)
      next_in=0;
   if(next_in==next_out)
      next_in=t;   
}

#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(){

   lcd_init();   
   enable_interrupts(int_rda);
   enable_interrupts(global);

   do {
      delay_ms(10000);
   printf(lcd_putc,"Data:");
      while(bkbhit)
        lcd_putc( bgetc() );
   } while (TRUE);

}


ezflyr



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

View user's profile Send private message

PostPosted: Mon Oct 05, 2015 1:00 pm     Reply with quote

Hi,

Purely from a historical perspective, I'd guess that you've got a hardware interface issue between your TC35 GSM modem and your PIC. Saying that you have a 'TC35' is pretty meaningless, because most of the time (again from a historical perspective) you've actually got a TC35 module that is mounted to a breakout board that has other support components, such as TTL-to-RS232 conversion, etc. You should *really* post a link to the exact module you are using so that we can look at the schematic! I'd bet a milkshake that your Tx/Rx levels are not compatible Smile

A couple of comments about your code. Why the 10 second delay? The 'bkbhit' statement will wait until a character is available, so you really don't need this delay. Your code looks like it will basically do what you want, however, I generally try to avoid using an LCD for this type of diagnostics. LCDs can deal with some characters in unexpected ways, and will sometimes mask what you are trying to look at. I much refer to use a MAX232 device and send diagnostic messages to my PC.

I realize I'm probably sounding like 'Johnny one-note' on this GSM interfacing, but it is a perennial problem!!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Dempsey



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 5:01 am     Reply with quote

Hi,
I don't use level converter because the PIC and the GSM module are using 3,3V power supply. When I linked the PC and the PIC the communication was fine. On the PC side I used FT232R USB->Serial converter with 3,3V Rx/Tx level. I don't know what is wrong, programming or hardware error. What do you think?
temtronic



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

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 6:02 am     Reply with quote

I'm with John on this..please post a link to the TC35 you're using. It might be that the TC35 defaults to something other than 9600-8-n-1 for serial communications that the PIC is setup for.

Since your program works using a PC as the 'TC35', code should be good.
2 garbage characters from the TC35 could easily be a baudrate issue.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 7:20 am     Reply with quote

There is also the problem of timing, though the data should eventually get returned.
When a character arrives, it'll get displayed, then the code goes off and pauses for 10 seconds, before displaying the next character. At this point the following characters should be in the buffer, so should be displayed one after the other, but the approach is not a terribly 'good' way of doing things.

However it does look massively like a baud problem as Temtronic says.

What compiler version are you on?.
Dempsey



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 7:22 am     Reply with quote

Hi,
Here is the link
http://www.ebay.com/itm/New-GSM-SIEMENS-TC35-SMS-Module-Board-RS232-UART-Serial-For-Arduino-dnk-/190976532342?hash=item2c77169f76
ezflyr



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

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 7:54 am     Reply with quote

Hi,

I tried to download the datasheet for that module, but gave up after 10 minutes of trying...... Unfortunately, lack of proper & correct documentation is what plagues these 'cheap' hardware boards from Asia. Unless you are very experienced, it's often a hurdle that cannot be overcome..... Seriously, do a forum search for 'TC35' and you'll find a number of such projects using similar hardware that ultimately went no where.....

Clearly, that module has an RS232 driver chip on-board, probably a MAX232 or equivalent. The 'raw' TC35 TTL level RxD and TxD pins are probably broken out on either J5 or J6 as well? The silkscreen is not very clear, so it's hard to say for sure. Since you can communicate wit the module using your PC, at least this part is working. Are you connecting the PIC to the DB9 connector, or to pins on J5 or J6? If you are using the DB9 connector, you'll need to add a MAX232 to your PIC, and if you are using the TC35 RxD and TxD pins (presumably on J5/J6) then you'll have to disable the MAX232 on the TC35 board. You may need to find some jumpers to do this, or simply pull the MAX232 chip!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 8:08 am     Reply with quote

Even without data though, the fact it connects to the PC, and the visible MAX232, tells us why there is a problem. U2 is the MAX232 (you can just make this out in the pictures).
If the MAX232, is socketed as shown then his easiest way, would be to unplug the MAX232, and make the connections either directly to it's socket, or to the pins on JP6. If you look carefully at the pictures you can see the serial pins from the module are brought out here.

Lest make this clear to him:

RS232, is a signalling standard using (by PC standards) quite high voltages. The PIC does not develop/handle RS232.
It handles 'async serial TTL', which can be converted to RS232, using a TTL to RS232 converter chip. The MAX232 is the commonest such chip.
The TC35, also does not develop/handle RS232.
The breakout board you have has a MAX232, to convert the TTL signals, on the TC35, to RS232 to talk to a PC. The resulting signals cannot connect to a PIC without a MAX232 on the PIC.
However the TTL signals on the PIC _would_ happily connect directly to the TC35.

Currently you are feeding higher voltages than the PIC is designed to handle, directly into it's pins.... :(
temtronic



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

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 8:57 am     Reply with quote

Obviously lots of options to get the PIC connected to the TC35. I second adding a MAX232( or equal) to your PIC project.
1) NO modifications to the TC35 module,less chance of breaking it...
2) Having real RS232 on the PIC allows connecting to a PC (that has RS232)


Jay
Dempsey



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 10:46 am     Reply with quote

To be clear for everybody I attached a photo.
http://kepkezelo.com/images/y7gyugmlluwgq7fv2arh.jpg
I use these pins to communicate with the PIC. Should I use level converter or not?
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 10:56 am     Reply with quote

We can't tell.

You need to measure whether these connect to the pins on the DB-9, or to the pins on the tc35.

If they go to the pins on the tc35, then you don't need level translators, but you do need to disconnect the MAX232 on the board. If they go to the DB9, then you need to add a max232 to the PIC.
Dempsey



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 11:03 am     Reply with quote

Ok! Thank you. I understand. I'll try your advice tomorrow.
Dempsey



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 11:24 am     Reply with quote

I couldn't wait. I measured a little. Between the DB9 and the Tx/Rx pins aren't connection. The Rx pin connect to the Max232 IC's 11 pin and the Tx pin connect to the Max232 IC's 12 pin.
temtronic



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

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 12:07 pm     Reply with quote

OK the second picture is NOT the same TC35 module as the first one.
Makes life challenging......a link to the real module would really help !
One way to tell TXD is that IF it is from a MAX232 it will have -5 to -12 volts on it at idle. Pin 2 of the DE9 connector should have that voltage.

Jay
ezflyr



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

View user's profile Send private message

PostPosted: Tue Oct 06, 2015 12:20 pm     Reply with quote

Dempsey wrote:
I couldn't wait. I measured a little. Between the DB9 and the Tx/Rx pins aren't connection. The Rx pin connect to the Max232 IC's 11 pin and the Tx pin connect to the Max232 IC's 12 pin.


Are you sure about that?? I would expect the 'Tx' pin to be connected to either pin 10 or 14. These are the inputs to the two TTL-to-RS232 OUT drivers on the chip. I would expect the 'Rx' pin to be connected to either pin 9 or 12. These are the outputs to the two TTL-to-RS232 IN drivers on the chip.

Again, where is the documentation for this module? It doesn't exist, I believe? Moreover, it's interesting that your module doesn't even seem to be the same as the one shown in the eBay listing...... I'm afraid, my friend, that you are on a slippery slope here, and its going to be tough to get any traction on this issue.....

OK, so taking a step back, you have a working configuration - the RS232 output mode of the module, right? So, I'd recommend that you just add a MAX232 to your PIC and get on with your program!!
_________________
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