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

rs232 problem - SOLVED
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 20092

View user's profile Send private message

PostPosted: Mon Apr 28, 2014 2:06 am     Reply with quote

Yes.

My problem is the 'dross'....

A test program, should only use the timers, interrupts etc., that are actually involved in the problem.

As a test, if you want the original message, this can be done as:
Code:

#include <16F648A.h>

#FUSES NOWDT                   
#FUSES EC_IO
#FUSES BROWNOUT,MCLR,NOLVP,NOPROTECT,NOCPD,PUT                   
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,UART1,bits=8,ERRORS)

#define MESSAGE_SIZE 19;
int8 message[]={0xAA,0x55,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFF};

#int_TBE
void TBE_isr(void)
{
   static int8 ctr=0;
   putc(message[ctr++]);
   if (ctr==MESSAGE_SIZE)
   {
       disable_interrupts(INT_TBE);
       ctr=0;
   }
}

#int_TIMER0
void TIMER0_isr(void)
{
   static tick=60;
   if(tick--==0)
   {
      tick=60
      enable_interrupts(INT_TBE);
   }   
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   do
   {
      delay_us(10);
   }
   while(TRUE);
}


I seriously think you have a hardware problem. I'd suspect something like a capacitive connection to the RS232 lines, so a small 'spike' is getting through (enough to be seen as a start bit), but not the data. Hence a simple 'hello world' test should be the starting point.

As a comment to the original code, you do realise that you can code multiple identical cases as:
Code:

      case 2:
      case 3:
      case 4: //etc..
      {
         putc(0x00);
         scomtxwords++;         
      }

The single set of code, gets it's address put into the jump table for every case listed, instead of multiple routined being generated.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Mon Apr 28, 2014 2:42 am     Reply with quote

Hi Ttelmah
I made the program bellow according to Mike advice (part of it)
I am getting infinite 00, don't have any delay.
I will copy now your program and will run it.
The reason I wrote identical cases (I didn't know that I can write them as you have written) is because in the original program have different data in each case.
I think also is a hardware problem, but not with my board as I tested the previous board and have the same problem.
Maybe the FTDI USB to TTL is the problem, this is the only new component in the system because the old one I give to my friend. Maybe the driver is wrong. I try to find out.
Thanks
Joe
The program:
Code:

#include <16F648A.h>

#FUSES EC_IO   
#FUSES PUT,NOPROTECT,BROWNOUT,MCLR,NOLVP,NOCPD                 
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,ERRORS)

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   disable_interrupts(INT_TIMER1);
   disable_interrupts(INT_TIMER0);
   disable_interrupts(INT_TBE);
   disable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   rs232_errors=0;
 
   while (1)
   {
      printf ("Hello World \n\r");
      delay_ms(1000);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 20092

View user's profile Send private message

PostPosted: Mon Apr 28, 2014 4:21 am     Reply with quote

The FTDI adapters are usually about the best. Obvious thing would be that it's baud rate is set to a value like 115200bps. Then it'd see any start bit or low data bit as 8 bits of 'all low'....
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 28, 2014 5:25 am     Reply with quote

hmm.. simple thing to do..

Remove the USB<->TTL adapter and just wire it's TX to it's RX pins, effectively a 'loopback' connection. Use a PC terminal prgram and confirm typing on the PC KBD does display onto the PC screen. If you remove the loopback connection nothing should appear on the screen while typing.
This test will confirm the PC is OK, and that the USB<->TTL adapter is working correctly.

You might have the TX and RX of the PIC on the TX and RX of the USB adapter! Easy mistake, they should be RX to TX, TX to RX. I've used several 'generic' USB-TTL adapters since they're only $2 a unit these days and never had one fail yet. I do the above test on every one though as it's best to KNOW hardware does work BEFORE adding in software.

hth
jay
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Mon Apr 28, 2014 3:26 pm     Reply with quote

First I would like to apologize to every one for spending your time, myself learned a lot.
I simply connected the TTL tx to the rx as temtronic has advised me.
Sending 55,AA,FF, getting 00,00,00. Doesn't matter what I am sending, getting back just '00', at the length of my message.
I will be grateful if somebody will teach me what to do regarding the FTDI
Ttelmah, I copy your file and tried to compile but getting 46 errors starting with: USE parameter value is out of range "UART1". If I remove the UART1 remain 44 errors.
I would like to make your program operational as I can learn a lot from it.
Thanks for everybody investing his time on this topic
Joe
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 28, 2014 5:22 pm     Reply with quote

Joe
Good news is it's NOT the PIC....bad news..silly usb module, but at least you KNOW where the trouble is, which is 1/2 the battle!
I use Realterm for my terminal program,though even Hyperterminal should work fine. I don't use the FTDI product but try their website for any information regarding the 'driver' the PC needs to run it. Maybe you need a different version to operate correctly ? Also, maybe you have 'handshaking' enabled(or not) and that might be wrong.Others here have probably used the FTDI unit, maybe post the model number and see if other can help.

cheers
jay
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Mon Apr 28, 2014 6:04 pm     Reply with quote

The board have a connector to the USB cable and a male connector to TTL with all the functions, I am using just TX, RX and ground. Have also LED for TX and LED for RX
What is written on the chip is:
FTDI
1213 - C
CN 480661
FT 232 RL

Any help is appreciated.
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Mon Apr 28, 2014 6:42 pm     Reply with quote

I found an article related to the specific chip:
https://www.olimex.com/forum/index.php?topic=2031.0
Downloaded the zip file, but I don't find any .exe file to install the driver.
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Mon Apr 28, 2014 7:27 pm     Reply with quote

Problem solved
Manually changed the driver to the older version and everything works perfect.
I would like to thank again to everyone that spent time to help me.
Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 20092

View user's profile Send private message

PostPosted: Tue Apr 29, 2014 12:36 am     Reply with quote

There is one extra ';' (on the define), and one missing on one line in the code. Type missing on one variable declaration. A total of three errors:
Code:

#include <16F648A.h>

#FUSES NOWDT                   
#FUSES EC_IO
#FUSES BROWNOUT,MCLR,NOLVP,NOPROTECT,NOCPD,PUT                   
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,UART1,bits=8,ERRORS)

#define MESSAGE_SIZE 19
int8 message[]={0xAA,0x55,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFF};

#int_TBE
void TBE_isr(void)
{
   static int8 ctr=0;
   putc(message[ctr++]);
   if (ctr==MESSAGE_SIZE)
   {
       disable_interrupts(INT_TBE);
       ctr=0;
   }
}

#int_TIMER0
void TIMER0_isr(void)
{
   static int8 tick=60;
   if(tick--==0)
   {
      tick=60;
      enable_interrupts(INT_TBE);
   }   
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   do
   {
      delay_us(10);
   }
   while(TRUE);
}

Works, and makes changing what it sent much easier.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Tue Apr 29, 2014 6:07 am     Reply with quote

Thanks Ttlemah.
It works after taking out UART1, otherwise makes errors:
USE parameter value is out of range "UART1"
Undefined identifier -- putchar
#use rs232(baud=9600,parity=N,bits=8,ERRORS) works fine
I will play with the program later, will try to make the program I am improving now more small.

James
Ttelmah



Joined: 11 Mar 2010
Posts: 20092

View user's profile Send private message

PostPosted: Tue Apr 29, 2014 7:22 am     Reply with quote

What compiler are you on?.

UART1, has been allowed as an automatic definition for the UART (and is in fact 'required' on chips with selectable pins), for about 50+ versions of the compiler....
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

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

PostPosted: Tue Apr 29, 2014 5:22 pm     Reply with quote

The compiler is very old, but works very good, no bugs except one:
CCS PCM C Compiler, Version 3.249
I am not working anymore with electronics, it is just an one time project for a friend.

Joe
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 Previous  1, 2
Page 2 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