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

PIC16F18857 require sending characters to receive characters
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
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

PIC16F18857 require sending characters to receive characters
PostPosted: Tue Sep 26, 2017 7:54 am     Reply with quote

I am using CCS PCM 5.070 compilier for quite new PIC16F18857 for my old servo controller.

It has quite high internal clock ( 32MHz) and lot of flash code ( 57kB).
The price is same as my old PIC16F886.

I have tested it few days and get new code working, almost.

I need to send three characters for 8 servos to control by 9600 bps serial data.

1. a sync character 0xFF
2. a channel charcter 0-7
3. a value 0-0x7E

This is simulation for the fly control servos.

Every thing works fine, but I need to send four characters to get my receiver UART working.
I have to send serial data from PIC to Uart.

The code is
printf("\r123"); // this must be on, why? It must have 4 char

Can somebody to explain this new UART?
=========
Here is my code
Code:

#include <16F18857.h>
#device ADC=10
#FUSES RSTOSC_HFINTRC           //internal clock
#FUSES NOWDT                    //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WDTCLK_HFINTRC          // aseta 32MHz sisäinen kello
#FUSES NOMCLR                  // Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NODEBUG                  //No Debug mode for ICD
 
#use delay(internal=32000000)

#use FIXED_IO( C_outputs=PIN_C0, PIN_C1,PIN_C2 )
#use FIXED_IO( A_outputs= PIN_A0 )
#use FIXED_IO( B_outputs= PIN_B0,PIN_B1,PIN_B2,PIN_B3, PIN_B4,PIN_B5,PIN_B6,PIN_B7 )
 
#pin_select U1TX=PIN_C6   
#pin_select U1RX=PIN_C7   
 
#use rs232(baud=9600,parity=N,UART1, errors)// aseta sarjaliikenne
 
#define PORT_A 5
#define PORT_B 6
#define PORT_C 7
#byte PCL = 0x02
#byte OPTION_REG = 0x81
#byte TMR0 = 1
#byte STATUS = 3
#bit  RP0 = STATUS.5
#byte INTCON = 0x0b
#bit  T0IF =  INTCON.2
#bit LED = PORT_C.1
#BYTE LATB = 0x17
#BYTE LATC = 0x18
#BYTE CCDNB = 0x1F4C 
#BYTE CCDPB = 0x1F4D 
#BYTE ODCONA = 0x1F3A
#BYTE ODCONB = 0x1F45
#BYTE ODCONC = 0x1F50
#BYTE ANSELB = 0x1F43
#BYTE ANSELC = 0x1F4E

#zero_ram
 
#define SERVO_ZERO_RELOAD 125

#define SERVO_CENTRE_PRELOAD (125/2 )   
 
#define BUFFER_SIZE 8   
 
#define BUFFER_SIZE_MASK 0x7
 
#define START_CHAR 0xff

#use FAST_IO( A )
#use FAST_IO( C )
#use FAST_IO( B )
 
#byte io_porta = PORT_A
#byte io_portb = PORT_B
#byte io_portc = PORT_C
 

//byte servo_on[ BUFFER_SIZE ];
//byte servo_off[ BUFFER_SIZE ];
//byte servo_base[ BUFFER_SIZE];

/**************************************************************************
  entry:
  exit:
****************************************************************************/
void  main(void)
{
    unsigned int16 timeout;
    unsigned int8 servo_index;
    unsigned int8 desired;
    unsigned int8 temp_on, temp_off, temp_base;
    setup_oscillator(OSC_HFINTRC_32MHZ, 0);
    setup_adc(  ADC_CLOCK_INTERNAL  );
    setup_adc_ports(NO_ANALOGS  );
    setup_spi(SPI_SS_DISABLED);
    setup_comparator(NC_NC_NC_NC); // T0_INTERNAL
    setup_timer_1 ( T1_DISABLED );  // 1 ja 2 timer1 an dtimre2 off
    setup_timer_2 ( T2_DISABLED ,T0_INTERNAL , 2);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|T0_8_BIT);//T0_8_BIT,T0_16_BIT, RTCC_8_BIT);
 
    set_tris_a( 0b11111110 );   //   
    set_tris_b( 0b00000000 );   //  output on B-port 
    set_tris_c( 0b10000000 );   //   rx RC.7 ja tx
 
    io_portb = 0xFF;

    set_rtcc( -SERVO_ZERO_RELOAD ); 
  //  enable_interrupts( INT_TIMER0 );
    enable_interrupts( GLOBAL );

    while( TRUE )
    {                         
        restart_wdt();
        if( kbhit() )
        { 
            if(  getc() == START_CHAR )      // wait for sync 255
            {
             
                printf("\r123");                // this must be on, why? It must have 4 char
                timeout = 0xff;
                while( --timeout )              //  wait 0..7
                {                               //
                    restart_wdt();
                    if( kbhit() )
                    {   
                        servo_index =  getc();   // read servo address
                     
                        if( servo_index == 255 ) // no 255
                            break;
                        servo_index &= 0x7;      //   mask  over 7                     
                        timeout = 0xff;          // 
                        while( --timeout )
                        {
                            restart_wdt();
                            if( kbhit() )         // wait  servo  value
                            {
                                desired =  getc(); // lue servon arvo 0-254
                             
                                if( desired == 255 )        // no  sync char
                                    break;
                                if( desired < 20 ) // 
                               {
                                   temp_base = ~( SERVO_ZERO_RELOAD - 20 );//   
                                   temp_on = ~( desired + 20 );              // 
                                }
                                else
                                {
                                    temp_base = ~( SERVO_ZERO_RELOAD ); // 
                                    temp_on = ~( desired/2 );              // 
                                }
                                if( desired > 235 )              //   
                                    temp_off = ~( 255 - 235 );  //
                                else
                                    temp_off = ~( 255 - desired/2 ); // 
                               
                                 
                            }
                       
                    }
                }
            }
        }
    }
}
}

/* end of file servo.c */
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 9:31 am     Reply with quote

I've reposted part and made some comments inline:
Code:

#include <16F18857.h>
#device ADC=10
#FUSES RSTOSC_HFINTRC //internal clock
#FUSES NOWDT //Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WDTCLK_HFINTRC // aseta 32MHz sisäinen kello
#FUSES NOMCLR // Master Clear pin not enabled
#FUSES NOCPD //No EE protection
#FUSES NODEBUG //No Debug mode for ICD


#use delay(internal=32000000)
#use FIXED_IO( C_outputs=PIN_C0, PIN_C1,PIN_C2 )
#use FIXED_IO( A_outputs= PIN_A0 )
#use FIXED_IO( B_outputs= PIN_B0,PIN_B1,PIN_B2,PIN_B3, PIN_B4,PIN_B5,PIN_B6,PIN_B7 )


#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7




#use rs232(baud=9600,parity=N,UART1, errors)// aseta sarjaliikenne

//Some of these addresses are _wrong_.
//Port A for example is 0xC on this chip.
//If you must use register addresses, either use the compiler's
//ability to do this for you, or double check the data sheet.....
#define PORT_A 5
#define PORT_B 6
#define PORT_C 7
#byte PCL = 0x02
#byte OPTION_REG = 0x81
#byte TMR0 = 1
#byte STATUS = 3
#bit RP0 = STATUS.5
#byte INTCON = 0x0b
#bit T0IF = INTCON.2
#bit LED = PORT_C.1
#BYTE LATB = 0x17
#BYTE LATC = 0x18
#BYTE CCDNB = 0x1F4C
#BYTE CCDPB = 0x1F4D
#BYTE ODCONA = 0x1F3A
#BYTE ODCONB = 0x1F45
#BYTE ODCONC = 0x1F50
#BYTE ANSELB = 0x1F43
#BYTE ANSELC = 0x1F4E
#zero_ram

#define SERVO_ZERO_RELOAD 125

#define SERVO_CENTRE_PRELOAD (125/2 )


#define BUFFER_SIZE 8

#define BUFFER_SIZE_MASK 0x7

#define START_CHAR 0xff

//Now we have another problem. You have both fixed IO
//and fast IO selected. Should only be one.

#use FAST_IO( A )
#use FAST_IO( C )
#use FAST_IO( B )

#byte io_porta = PORT_A
#byte io_portb = PORT_B
#byte io_portc = PORT_C


//byte servo_on[ BUFFER_SIZE ];
//byte servo_off[ BUFFER_SIZE ];
//byte servo_base[ BUFFER_SIZE];






/**************************************************************************

entry:
exit:
****************************************************************************/
void main(void)
{
unsigned int16 timeout;
unsigned int8 servo_index;
unsigned int8 desired;
unsigned int8 temp_on, temp_off, temp_base;
setup_oscillator(OSC_HFINTRC_32MHZ, 0);
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports(NO_ANALOGS );

//This is enabling the SPI with slave select disabled.
//The syntax to disable the SPI is
//setup_SPI(FALSE);

setup_spi(SPI_SS_DISABLED);
setup_comparator(NC_NC_NC_NC); // T0_INTERNAL


Start with a much simpler basic test to just talk to the UART. If you still have problems with this then we can look at this, not pages of other stuff.

You are currently writing to the indirect register, not PortB. This may well be affecting almost anything.....
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

replay with shoterd program
PostPosted: Tue Sep 26, 2017 10:45 am     Reply with quote

Ttelmah
Thank you for noting diffent addressing in PIC16F18857 from normal PIC16F PICs

I tried to make the program simpler.

Still it has the reguirement for sending printf("\r123");, otherwise it don't go futher.
I know that it is my fault, but I can't find it.

Code:
 
#include <16F18857.h>
#device ADC=10
#FUSES RSTOSC_HFINTRC           //internal clock
#FUSES NOWDT                    //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WDTCLK_HFINTRC          // aseta 32MHz sisäinen kello
#FUSES NOMCLR                  // Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NODEBUG                  //No Debug mode for ICD

 
#use delay(internal=32000000)
#pin_select U1TX=PIN_C6   
#pin_select U1RX=PIN_C7   
 
#use rs232(baud=9600,parity=N,UART1, errors)// aseta sarjaliikenne
 
#define PORT_A 0xc  // note PIC1F8857 diffente addresses!
#define PORT_B 0xd
#define PORT_C 0xe
 
 
/**************************************************************************
 
****************************************************************************/
void  main(void)
{
   
    unsigned int8 servo_index;
    unsigned int8 desired;
 
    setup_oscillator(OSC_HFINTRC_32MHZ, 0);
    setup_adc(  ADC_CLOCK_INTERNAL  );
    setup_adc_ports(NO_ANALOGS  );
    setup_spi(SPI_DISABLED);
    setup_comparator(NC_NC_NC_NC); // T0_INTERNAL
    setup_timer_1 ( T1_DISABLED );  // 1 ja 2 timer1 an dtimre2 off
    setup_timer_2 ( T2_DISABLED ,T0_INTERNAL , 2);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|T0_8_BIT);//T0_8_BIT,T0_16_BIT, RTCC_8_BIT);
 
    set_tris_a( 0b11111110 );   //   
    set_tris_b( 0b00000000 );   //  output on B-port 
    set_tris_c( 0b10000000 );   //   rx RC.7 ja tx


    while( TRUE )
    {                         
 
        if( kbhit() )
        { 
            if(  getc() == 0xff )      // wait for sync 255
            {
             printf("\r123");                // this must be on, why? It must have 4 char
                    if( kbhit() )
                    {   
                        servo_index =  getc();   // read servo address
                        desired=  getc();        // read servo value         
                        printf("\rindex=%u servo=%u",servo_index,desired); //if printf("\r123"); donot exixis, thisdonot print
                     
                    }
               
            }
        }
    }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 11:44 am     Reply with quote

I'd start by delaying before starting the code.

Generally RS232 transceivers (assuming you are using such), take a while to wake up and charge their supplies.
Also because of this, the PIC itself will often receive garbage characters at boot. '255', is a very likely one to get received accidentally. This is why characters like 0xAA are generally better for this.

So I'd delay for 100mSec, then clear any received characters, before starting to look for the real data.
Code:


    delay_ms(100);
    while (kbhit())
        getc();

    while( TRUE )
    { 
        if( kbhit() )
//etc..


There is nothing in this port involving 4 bytes. It has the standard one character transmit buffer, and couple of characters on receive. I'd be more suspicious that it is starting a lot earlier than other chips you have used, before the other circuitry is ready. It starts working at perhaps half the voltage of older PIC's.
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

No help in delay at start, or reading characters
PostPosted: Tue Sep 26, 2017 2:18 pm     Reply with quote

I try to delay 100ms at start and read character at start.
They do not help.

The printf("\rtest"); do not come at start.

It still require four characters when I try to read my data.
Then the code works perfectly.

What can be wrong?



Code:



#include <16F18857.h>
#device ADC=10
#FUSES RSTOSC_HFINTRC           //internal clock
#FUSES NOWDT                    //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WDTCLK_HFINTRC          // aseta 32MHz sisäinen kello
#FUSES NOMCLR                  // Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NODEBUG                  //No Debug mode for ICD

 
#use delay(internal=32000000)
#pin_select U1TX=PIN_C6   
#pin_select U1RX=PIN_C7   
 
#use rs232(baud=9600,parity=N,UART1, errors)// set  serial
 
#define PORT_A 0xc  // note PIC1F8857 different addresses from normal PICs!
#define PORT_B 0xd
#define PORT_C 0xe
 
 
/**************************************************************************
 
****************************************************************************/
void  main(void)
{
   
    unsigned int8 servo_index;
    unsigned int8 desired;
 
    setup_oscillator(OSC_HFINTRC_32MHZ, 0);
    setup_adc(  ADC_CLOCK_INTERNAL  );
    setup_adc_ports(NO_ANALOGS  );
    setup_spi(SPI_DISABLED);
    setup_comparator(NC_NC_NC_NC); // T0_INTERNAL
    setup_timer_1 ( T1_DISABLED );  // 1 ja 2 timer1 an dtimre2 off
    setup_timer_2 ( T2_DISABLED ,T0_INTERNAL , 2);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|T0_8_BIT);//T0_8_BIT,T0_16_BIT, RTCC_8_BIT);
 
    set_tris_a( 0b11111110 );   //   
    set_tris_b( 0b00000000 );   //  output on B-port 
    set_tris_c( 0b10000000 );   //   rx RC.7 ja tx
    delay_us(100);
    output_bit(PIN_B3 ,1);
   
    if( kbhit()) getc();
 
    printf("\rtest");                // test  do not show
    delay_ms(1000);
    while( TRUE )
    {   
 
 
        if( kbhit() )
        { 
            if(  getc() == 0xff )      // wait for sync 255
            { 
             // printf( "\r123");                // this must be on, why? It must have 4 char
                    if( kbhit( ) )
                    {   
                        servo_index =  getc();   // read servo address
                        desired= getc();        // read servo value   
                        if (desired>128)
                          output_bit(PIN_B3 ,1);
                          else
                          output_bit(PIN_B3 ,0);
                        //printf("\rindex=%u servo=%u",servo_index,desired); //if printf("\r123"); do not exist, this do not print
                     
                    }
               
            }
        }
    }
}
 
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 2:52 pm     Reply with quote

You are not doing what I suggested,

You are only waiting 100uSec before trying to read. I suggested 100mSec. It needs to be long enough for the RS232 transceiver to have fully powered up, before you try to read/write.

Then " if (kbhit()( " will only flush _one_ character. The 'while' will flush anything waiting.

I think the UART is actually becoming locked at the start. The getc then clears this, but it is taking the data output to fully reset the transmit side.

I have seen similar things on other UART's and it has always come down to timing or hardware issues with the interconnection circuitry.
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

while ( kbhit()) getc(); do not help.
PostPosted: Wed Sep 27, 2017 12:57 am     Reply with quote

Hey, I made while (kbhit()) getc(); but it don't help.

I reguire printf("\r123"); for every time.
Code:

#include <16F18857.h>
#device ADC=10
#FUSES RSTOSC_HFINTRC           //internal clock
#FUSES NOWDT                    //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WDTCLK_HFINTRC          // aseta 32MHz sisäinen kello
#FUSES NOMCLR                  // Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NODEBUG                  //No Debug mode for ICD

 
#use delay(internal=32000000)
#pin_select U1TX=PIN_C6   
#pin_select U1RX=PIN_C7   
 
#use rs232(baud=9600,parity=N,UART1, errors)// set  serial
 
#define PORT_A 0xc  // note PIC16F18857 different addresses from normal PICs!
#define PORT_B 0xd
#define PORT_C 0xe
 
/**************************************************************************
 
****************************************************************************/
void  main(void)
{
     byte i=0;
    unsigned int8 servo_index;
    unsigned int8 desired;
 
    setup_oscillator(OSC_HFINTRC_32MHZ, 0);
    setup_adc(  ADC_CLOCK_INTERNAL  );
    setup_adc_ports(NO_ANALOGS  );
    setup_spi(SPI_DISABLED);
    setup_comparator(NC_NC_NC_NC); // T0_INTERNAL
    setup_timer_1 ( T1_DISABLED );  // 1 ja 2 timer1 an dtimre2 off
    setup_timer_2 ( T2_DISABLED ,T0_INTERNAL , 2);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|T0_8_BIT);//T0_8_BIT,T0_16_BIT, RTCC_8_BIT);
 
    set_tris_a( 0b11111110 );   //   
    set_tris_b( 0b00000000 );   //  output on B-port 
    set_tris_c( 0b10000000 );   //   rx RC.7 ja tx
    delay_us(1000);
   
    while( kbhit())
            getc();
 
    output_bit(PIN_B3 ,1);

    while( TRUE )
    {   
        if( kbhit() )
        { 
            if(  getc() == 0xff )      // wait for sync 255
            { 
              printf( "\r123");                // this must be on, why? It must have 4 char
                    if( kbhit( ) )
                    {   
                        servo_index =  getc();   // read servo address
                        desired= getc();        // read servo value   
                        if (desired>128)
                          output_bit(PIN_B3 ,1);
                          else
                          output_bit(PIN_B3 ,0);
                        //printf("\rindex=%u servo=%u",servo_index,desired); //if printf("\r123"); donot exixis, thisdonot print
                     
                    }
            }
        }
    }
}

Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Sep 27, 2017 6:40 am     Reply with quote

Is all the testing so far from one PC?.
Can you try on another?.

I've got the 45K22 running without problems.

Also you are receiving the '255' character to start OK. It's just as if once this has been sent some part of the link is freezing, till it sees the 4 bytes sent back.

Now obviously there are two UART's involved. The one in the PIC, and the one on the PC (assuming it is a PC for now). Now I do 'worry' about your using 255. Both because it is such an easy character to have happen accidentally, and because '127', is the 'idle' or 'delete' character in some terminals, and if the PC is only using 7bit it might be seeing this.

So can you try with a different marker character?. 0xAA for example.
What are you using to actually transmit?.
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

Tray with other computer, 0xAA at start, no help
PostPosted: Wed Sep 27, 2017 2:17 pm     Reply with quote

Ttelmah

Thank you for you help.

I tried with other computer.
No help.

I tried with longer start delay (1s), no help.

My PC program sends 0xFF, servo index ( 0-7), servo value (0-0xFE).

I was using other PC serial program (my own terminal program), I put three macros
I changed my sync character to 0xAA.

0xAA,3,0xFE // full value to channel 3
0xAA,3,0x00 // zero value to channel 3
0xAA,3,0xA1 // some other value to channel 3

When I tested, they require 4 characters, before they work.
===
I use other setup for RS232, no help.
It will work, if I put these 4 characters,

#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,errors)
====
How others has got PIC16F18857 and 32MHz to work with serial read?
temtronic



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

View user's profile Send private message

PostPosted: Wed Sep 27, 2017 6:04 pm     Reply with quote

It really looks like your 'PC serial program' needs incoming data before it transmits to the PIC.
I've never had a problem with RealTerm in a decade of use and without knowing what 'terminal ' program your PC is using it's difficult to debug. The other possible problem is, and I assume this, that your PC is NOT using real RS-232 , rather a USB port as no 'modern' PC has RS-232 ports.
If it is USB based, that can open up a whole new can of worms.....

You should post what hardware connects PIC to PC..

Jay
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

Some more experience
PostPosted: Thu Sep 28, 2017 11:32 am     Reply with quote

Jay

I try to use TeraTerm, but I can't get it to work with 0xff, or 0xaa.

I use my term-program
http://probyte.fi/catalog/product_info.php?products_id=31

It has all characters available from 0 to 0xff.
===
Then I used my old compiler CCS v4.04.
I compile the different program for a PIC16F886.

It was exactly same result as with my V5.070 and PICKIT3.
It require four characters before it starts to work.

I used with V4.04 a PICkit2 programmer.

The newer version v5.070 require PICKIT3 and Microchip IPE programming language.
===
I have XP standard computer with two standard communication ports COM3 and COM4.

I have also other XP, WIN7 and Win10 computers. Win7 and Win10 computers must use USB/COM-converter.
XP machine has a standard communication port.

Pekka
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Sep 28, 2017 11:57 am     Reply with quote

OK. Well doing the same with the 886, shows it is not a PIC problem.

RealTerm is another program like TeraTerm, that does allow extended characters more easily.

Try going into the com port setup on your machines and turning buffering down to the minimum. I'd suspect they are enabling 4 characters of buffering, and not actually triggering an interrupt till four characters arrive. So not automatically timing out properly. Sounds like a major bug in the package, so you really need to talk to the suppliers of this. There may well be a setting that changes this.
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

No help with TeraTerm
PostPosted: Thu Sep 28, 2017 3:30 pm     Reply with quote

Jay

I tried TeraTerm.
I can use hex-characters, but it doesn't help.
The programs still require to print 4 charaters to work.

I used the original characters (0xff, 0x3, 0x10 and 0xff,0x3,0xfe)
====
I tried to put 10 counter before printf()-sentence, but the programs stops after ten operations.
===

I am a developer of the Term-program for 17-years.
I removed all buffers with Term-program at start.

Main.MSComm1.InBufferCount = 0
Main.MSComm1.OutBufferCount = 0

It has no help.
===
Do you have still some ideas?

Pekka


===
temtronic



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

View user's profile Send private message

PostPosted: Thu Sep 28, 2017 4:26 pm     Reply with quote

Ok... one idea...

get rid of the PC.....
replace with a PIC whose main program only sends the sequence you want...say every 10 seconds and loops.

simple, easy and 100% gets rid of 'funny' things happening in the PC world.


You can post your PIC 'command sender' code and other here will confirm it works.....

Jay
pekka1234



Joined: 28 May 2017
Posts: 83

View user's profile Send private message

No PC, but PIC16F873 terminal
PostPosted: Fri Sep 29, 2017 1:41 pm     Reply with quote

Jay

I replaced PC with PIC16F873 2400 bps LCD teminal.

I changed the sender code RS232 to 2400 bps, and sync charcter to '1'.
I put i-characher counter to 10, when is send printf.

I put them together with serial connecors.

Then I started them.
I could see what characters came and how PIC16F18857

When it sends 123-characters ten times the led blinks and then stops.

http://remotesmart.wikidot.com/pic16f18875

(I didn't understand how to put pictures on this post.
There was Img*, but what else? )


The sending code is here

Code:



#include <16F18857.h>
#device ADC=10
#FUSES RSTOSC_HFINTRC           //internal clock
#FUSES NOWDT                    //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES WDTCLK_HFINTRC          // aseta 32MHz sisäinen kello
#FUSES NOMCLR                  // Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NODEBUG                  //No Debug mode for ICD

#use FIXED_IO( C_outputs= PIN_C0, PIN_C1,PIN_C2 )
#use delay(internal=32000000)
#pin_select U1TX=PIN_C6   
#pin_select U1RX=PIN_C7   
 
#use rs232(baud=2400,parity=N,UART1, errors)// set  serial
 
#define PORT_A 0xc  // note PIC1F8857 diffence addressesfrom normal PICs!
#define PORT_B 0xd
#define PORT_C 0xe
 
 
/**************************************************************************
 
****************************************************************************/
void  main(void)
{
    byte i=0;
    unsigned int8 servo_index;
    unsigned int8 desired;
 
    setup_oscillator(OSC_HFINTRC_32MHZ, 0);
    setup_adc(  ADC_CLOCK_INTERNAL  );
    setup_adc_ports(NO_ANALOGS  );
    setup_spi(SPI_DISABLED);
    setup_comparator(NC_NC_NC_NC); // T0_INTERNAL
    setup_timer_1 ( T1_DISABLED );  // 1 ja 2 timer1 an dtimre2 off
    setup_timer_2 ( T2_DISABLED ,T0_INTERNAL , 2);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|T0_8_BIT);//T0_8_BIT,T0_16_BIT, RTCC_8_BIT);
 
    set_tris_a( 0b11111110 );   //   
    set_tris_b( 0b00000000 );   //  output on B-port 
    set_tris_c( 0b10000000 );   //   rx RC.7 ja tx,led
    delay_ms(100);
   
   
    while( kbhit())
            getc();
 
    output_high(PIN_C1);
 
    while( TRUE )
    {   
 
 
        if( kbhit() )
        { 
            if(  getc() == '1'/*0xFF */)      // wait for sync'1'// 0xaa
            { 
               if(i++<10) printf( "\r123" );                // this must be on, why? It must have 4 char
                    if( kbhit( ) )
                    {   
                        servo_index =  getc();   // read servo address
                        desired= getc();        // read servo value   
                        if (desired>128)
                          output_bit(PIN_C1 ,1);  // test purpose
                          else
                          output_bit(PIN_C1 ,0);   // test purpose
                       
                     
                    }
               
            }
        }
    }
}
 
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