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

Problems with RS232

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



Joined: 05 Aug 2014
Posts: 24

View user's profile Send private message

Problems with RS232
PostPosted: Wed Aug 06, 2014 3:22 am     Reply with quote

Hi
Im using the following setup to drive a serial port on a Pic 16F883

#use rs232(baud=1200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,enable=PIN_B2)
When the Timer1 interrupt fires the serial port is interrupted.
If I disable interupts before the 'putc(OPstat1A);' then data goes out OK but I loose the interrupt of T1.
It seems the code has setup a software port
How can I force the code to use the uart?
Thanks
Neville
_________________
Neville
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 5:11 am     Reply with quote

Get rid of the enable pin.

Handle this yourself.

Think about what the code has to do to control this. It has to sit 'polling' if the character has sent, and then change the line....
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 5:21 am     Reply with quote

Show us the the min code that reproduce the problem.

I have the exact same setup with this PIC and it works flawlessly. I let the software handles the Enable pin as you want to do it. CCS 5.024

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 5:47 am     Reply with quote

It does depend on compiler version. However safer, and easier to just control the line yourself.
temtronic



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

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 5:56 am     Reply with quote

It's also not 'RS-232', probably using RS-485 so the subject line is kinda misleading.
A FULL and complete program(with comments) would help everyone....

jay
Nevillestone



Joined: 05 Aug 2014
Posts: 24

View user's profile Send private message

RS232/ 485
PostPosted: Wed Aug 06, 2014 9:14 am     Reply with quote

Hi
Distilled the code to bare bones and have found that the problem seems to be related to the ram address of my variables
Have two versions of code first one works not the ram addresses are 30-70h
The second has ram address of 25-70h this does not work Hangs on RS232 handler.
I'm happy I solved the problem but cant understand why, that is more problematic than the solution

Anybody know why?

Code Ver1 (working)
Code:

//FFMike2 transmit routine working
#include <FFmike.h>

//'Variable definitions:
//'       ********************************* DECLARE VERIABLES 
typemod <,,,0x30,0x70> user_ram_block;
     
#type default=user_ram_block
//       ********************************* DECLARE VERIABLES
          int I ;            //    'gen index byte
        int T44Ctr ;      //'time 44mS counter
      int MSTAT;               //' GENERAL STATUS
      //#byte MSTAT = MSTAT
        #bit Mimic = MSTAT.0          //' 1 = enable lightbar mimic
        #bit Tog = MSTAT.1            //' 1 = tx to L550 (general toggle flag)
        #bit DJS = MSTAT.2            //' 1 = data just sent
        #bit WFR = MSTAT.3            //' 1 = waiting for reply
        #bit FOS = MSTAT.4            //' 1 = flasher on with siren mode
        #bit Front = MSTAT.5          //' 1 = front 0 = rear mimic display
        #bit SW_prog = MSTAT.6        //' 1 = prog mode on
        #bit PHBO = MSTAT.7           //' 1 power has been on (used for hrt off cmd)

      int MSTAT1;             //' GENERAL STATUS
        //#byte MSTAT1 = MSTAT1             //GENERAL STATUS
        #bit PEM = MSTAT1.0           //1 = in parameter enter mode
        #bit TT_EN = MSTAT1.1         //1 = two tone on               
        #bit DMA = MSTAT1.2           //1 = lightbar dimming mode active
        #bit DMAtog = MSTAT1.3        //DMA toggle bit (100 fpm)
        #bit TXNOW= MSTAT1.4          //do LX550 transmit now
        #bit TXNO= MSTAT1.5           //no transmitting during PTT
      int OPstat1A;


#type default=    //return memory allocation back to normal

//*********
//Transmit to TX550 routine
//********
void L550TX()
      {
        TXNOW = 0;
         //disable_interrupts(GLOBAL);
        putc(OPstat1A);                        //tx rs485 data to Logic 550 siren
         //enable_interrupts(GLOBAL);
        DJS =1;                                 //set "data just sent" flag
        }                                 //to exit
   

#int_TIMER1
void  TIMER1_isr(void)
{
//void LEDSCAN()
      setup_timer_1(T1_DISABLED);                //stop timer1
        set_timer1(64000);                         //reload for 2mS
      T44Ctr++;      //for 44mS flash time
           if (T44Ctr > 240)
         {
         T44Ctr = 0;
         TXNOW = 1;
         }
         if (I==0)
            {
            output_high (LED_R1);       //turn led row 1 on
              output_low (LCOL2);         //enable led col 2
            I=1;
            }
            else
            { 
            output_low (LED_R1);       //turn led row 1 on
              output_low (LCOL2);         //enable led col 2
            I=0;
            } 
        setup_timer_1((T1_INTERNAL|T1_DIV_BY_1));     //restart timer1}


void main()
{           
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_8MHZ);
    set_timer1(44000);                         //reload for 2mS
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      //32.7 ms overflow
      enable_interrupts(INT_TIMER1);
      enable_interrupts(GLOBAL);

   TXNOW = 0;
   TXNOW = 1;
   OPstat1A= 0XAA;
   

//       **************************************** TX DATA TO L250 SIREN
//       ****************************************
 
While (1)
   {      
      if (TXNOW == 1)   {L550TX();}
   }


Code sample 2 (not working)
Code:

//FFMike2 transmit routine working
#include <FFmike.h>

//'Variable definitions:
//'       ********************************* DECLARE VERIABLES 
typemod <,,,0x25,0x70> user_ram_block;
     
#type default=user_ram_block
//       ********************************* DECLARE VERIABLES
          int I ;            //    'gen index byte
        int T44Ctr ;      //'time 44mS counter
      int MSTAT;               //' GENERAL STATUS
      //#byte MSTAT = MSTAT
        #bit Mimic = MSTAT.0          //' 1 = enable lightbar mimic
        #bit Tog = MSTAT.1            //' 1 = tx to L550 (general toggle flag)
        #bit DJS = MSTAT.2            //' 1 = data just sent
        #bit WFR = MSTAT.3            //' 1 = waiting for reply
        #bit FOS = MSTAT.4            //' 1 = flasher on with siren mode
        #bit Front = MSTAT.5          //' 1 = front 0 = rear mimic display
        #bit SW_prog = MSTAT.6        //' 1 = prog mode on
        #bit PHBO = MSTAT.7           //' 1 power has been on (used for hrt off cmd)

      int MSTAT1;             //' GENERAL STATUS
        //#byte MSTAT1 = MSTAT1             //GENERAL STATUS
        #bit PEM = MSTAT1.0           //1 = in parameter enter mode
        #bit TT_EN = MSTAT1.1         //1 = two tone on               
        #bit DMA = MSTAT1.2           //1 = lightbar dimming mode active
        #bit DMAtog = MSTAT1.3        //DMA toggle bit (100 fpm)
        #bit TXNOW= MSTAT1.4          //do LX550 transmit now
        #bit TXNO= MSTAT1.5           //no transmitting during PTT
      int OPstat1A;


#type default=    //return memory allocation back to normal

//*********
//Transmit to TX550 routine
//********
void L550TX()
      {
        TXNOW = 0;
         //disable_interrupts(GLOBAL);
        putc(OPstat1A);                        //tx rs485 data to Logic 550 siren
         //enable_interrupts(GLOBAL);
        DJS =1;                                 //set "data just sent" flag
        }                                 //to exit
   


#int_TIMER1
void  TIMER1_isr(void)
{
//void LEDSCAN()
      setup_timer_1(T1_DISABLED);                //stop timer1
        set_timer1(64000);                         //reload for 2mS
      T44Ctr++;      //for 44mS flash time
           if (T44Ctr > 240)
         {
         T44Ctr = 0;
         TXNOW = 1;
         }
         if (I==0)
            {
            output_high (LED_R1);       //turn led row 1 on
              output_low (LCOL2);         //enable led col 2
            I=1;
            }
            else
            { 
            output_low (LED_R1);       //turn led row 1 on
              output_low (LCOL2);         //enable led col 2
            I=0;
            } 
        setup_timer_1((T1_INTERNAL|T1_DIV_BY_1));     //restart timer1
}


void main()
{           
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_8MHZ);
    set_timer1(44000);                         //reload for 2mS
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      //32.7 ms overflow
      enable_interrupts(INT_TIMER1);
      enable_interrupts(GLOBAL);

   TXNOW = 0;
   TXNOW = 1;
   OPstat1A= 0XAA;

//       **************************************** TX DATA TO L250 SIREN
//       ****************************************
 
While (1)
   {      
      if (TXNOW == 1)   {L550TX();}
   }

}

_________________
Neville
temtronic



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

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 4:18 pm     Reply with quote

Ok , I'll take a stab... but those aren't complete, compilable programs.

you use 'putc(....)' yet I do not see a use rs232(.....) .

That alone could cause some compiler grief.

I see in the help files that typemod has been replaced with addressmod. Perhaps it's another compiler issue, trying to figure things out?
I don't know why you're using typemod for RAM...

I can see the compiler getting confused..hmm compiler version ?? That is important !!

Hay, I'm NOT a C programmer,just a regular old school hacker

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 5:02 pm     Reply with quote

He's using typemod, which is old. He hasn't told us his compiler version.
It might be buggy in his version. You'll see very few programs on this
forum using typemod or addressmod. It's usually not necessary and
not worth the risk (of bugs).
Nevillestone



Joined: 05 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Thu Aug 07, 2014 12:17 am     Reply with quote

OK
This is getting tedious but only started using typemod because I had the problem of the Compiler putting variables in the SFR area.
Second the #use RS323 is in the header file as the wizard sets up the project.
Using Ver 4.116
_________________
Neville
temtronic



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

View user's profile Send private message

PostPosted: Thu Aug 07, 2014 5:00 am     Reply with quote

1) CCS allows super easy access to the SFRs using the getenv() function. Look in the FAQ section of the help files/manual as well. Plenty examples within this forum on how it's used.

2) I never use the 'wizard'. I consider it like 'proteus'. A 3rd party program that isn't 100% reliable and buggy to say the least.If you code everything in your program then you can see everything! Nothing is more frustrating than wasting a few hours or days because some 3rd party didn't set a bit right...

hth
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