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

Startup troubles

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



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

Startup troubles
PostPosted: Mon Nov 15, 2004 8:02 am     Reply with quote

Hello,

I have a strange problem with my application : when I turn off the power and turn on again, my program works well sometime and doesn't work the others time... I have debug LED's that light up sometimes (not always) even if my program have a good reset... Crying or Very sad

I send you my source if you want to see...

#include "...header.h"
#include <stdio.h>
#include <lcd.c>

typedef struct
{
int8 longueur[2];
int8 prim[2];
int8 param[32];
int8 header;
int8 CRC;
int8 SuId;
int8 TxSeq;
int8 RxSeq;
int8 IC;
int8 PF;
} BUSMAIL;
BUSMAIL PIC, CVM;

int8 etat=0, i=0, traitement=0, init=0, linestatus=0;
int8 CVM_Result_CRC;
int8 SABM[5]={0x10,0x00,0x01,0xC0,0xC0};
int16 *CVM_length, *Primitive;

void send_SABM();
void send_control(int8 SuId, int8 RxSeq, int8 PF);
void API_FP_INVOKE_ACCESS_RIGHTS(int8 TxSeq, int8 RxSeq);
void API_FP_CONNECT_REQ(int8 TxSeq, int8 RxSeq);
void CVM_FP_AUDIO_OPEN_REQ(int8 TxSeq, int8 RxSeq);

#int_rda // Cette interruption detecte et gere une trame
void serial_isr()
{

if (!traitement)
{
switch (etat)
{
case 0: // Lecture du Frame Char
if(getc()==0x10) etat=1;
else etat=0;
break;

case 1: // MSByte of Length
CVM.longueur[1]=getc();
etat=2;
break;

case 2: // LSByte of Length & constitution de length (16 bits)
CVM.longueur[0]=getc();
CVM_length=(int16*)CVM.longueur;
etat=3;
break;

case 3: // Header
CVM.header=getc();
etat=4;
if(CVM.header==0xC8) { etat=0; traitement=1; }
break;

case 4: // 1er octet du mail
if(getc()==0xFC) etat=5;
else etat=0;
break;

case 5: // 2eme octet du mail
if(getc()==0x00) etat=6;
else etat=0;
break;

case 6: // LSByte of Primitive
CVM.prim[0]=getc();
etat=7;
break;

case 7: // MSByte of Primitive
CVM.prim[1]=getc();
etat=8; i=0;
break;

case 8: // CRC ou Parametre?? Etudier la longueur Header+Mail
if(*CVM_length-i>5)
{
CVM.param[i]=getc();
i++;
etat=8;
}
else if(*CVM_length-i<=5)
{
CVM.CRC=getc();
traitement=1;
etat=i=0;
}
break;
}
}

if(traitement) // Si on a une trame � traiter...
{
disable_interrupts(INT_RDA); // interruption interdite dans ce "if"

CVM.IC=((CVM.header)&0x80)>>7; // Info Frame ou Control Frame ?

//////////////////////////////INFO FRAME//////////////////////////////////
if(CVM.IC==0)
{
CVM_Result_CRC = CVM.header+0xFC+CVM.prim[0]+CVM.prim[1];
for(i=0;i<((*CVM_length)-5);i++)
{ CVM_Result_CRC = CVM_Result_CRC + CVM.param[i] ; }

Primitive=(int16*)CVM.prim;
if((*Primitive==0x2F41)&&(CVM.param[0]==0x82)) linestatus=1;

if(CVM_Result_CRC==CVM.CRC) // Si le CRC est bon
{
CVM.TxSeq=(CVM.header&0x70)>>4; // Numero de l'info recue
CVM.RxSeq=(CVM.header&0x07); // Ce que le PIC enverra...
PIC.TxSeq=CVM.RxSeq; // Le PIC enverra l'info attendue

if(CVM.TxSeq!=PIC.RxSeq) // Ce n'est pas l'info attendue par le PIC
{ send_control(1,PIC.RxSeq,0); } // REJ = rejet

else // C'est bien l'info attendue
{
PIC.RxSeq++; // On attend l'info suivante
CVM.PF=(CVM.header&0x08)>>3; // PF ou noPF ?

if(PIC.RxSeq==8) PIC.RxSeq=0; // Rx va de 0 � 7 seulement

if(CVM.PF) { send_control(0,PIC.RxSeq,0); } // on accuse...
}
}
}
//////////////////////////////////////////////////////////////////////////

/////////////////////////////CONTROL FRAME////////////////////////////////
if(CVM.IC==1)
{
if (CVM.header==0xC8) { send_SABM(); init=1; } // SABM

else
{
CVM.SuId=(CVM.header&0x30)>>4; // RR, REJ ou RNR
CVM.RxSeq=(CVM.header&0x07); // Cependant, tjrs RR
PIC.TxSeq=CVM.RxSeq; // Le PIC enverra ce qu'attend le CVM
}
}
//////////////////////////////////////////////////////////////////////////

traitement=0; // Il n'y a plus rien � traiter, on ressort et on attend

}

enable_interrupts(INT_RDA);

}

void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);

set_tris_a (0x00);
set_tris_b (0x01);
set_tris_c (0xBF);

output_low(LED0); // Permet de voir si le PIC est bien aliment�
output_low(LED1);

enable_interrupts(INT_RDA); // Interruption Port Serie
enable_interrupts(GLOBAL); // Enable Global Interrupts

//while(init==0){} // Si le SABM a bien ete recu...

/*// Les mobiles peuvent acceder � la base pour l'abonnement
disable_interrupts(INT_RDA);
API_FP_INVOKE_ACCESS_RIGHTS(PIC.TxSeq, PIC.RxSeq);
PIC.TxSeq++;
enable_interrupts(INT_RDA);*/

while(linestatus==0){}
output_high(LED0); // Permet de savoir si le programme n'a pas plant�...

/*
// FP answers an incoming call
disable_interrupts(INT_RDA);
API_FP_CONNECT_REQ(PIC.TxSeq, PIC.RxSeq);
PIC.TxSeq++; if(PIC.TxSeq==8) PIC.TxSeq=0;
enable_interrupts(INT_RDA);
delay_ms(500);
*/

// This command is used to open audio in the FP speakerphone
disable_interrupts(INT_RDA);
CVM_FP_AUDIO_OPEN_REQ(PIC.TxSeq, PIC.RxSeq);
PIC.TxSeq++; if(PIC.TxSeq==8) PIC.TxSeq=0;
enable_interrupts(INT_RDA);

while(1) {}
}


and the header.c file :

#include <16F873A.h>
#device adc=8
#use delay(clock=7372800) //7372800
/*#use fixed_io(a_outputs=PIN_A0, PIN_A1)
#use fixed_io(b_outputs=PIN_B7, PIN_B6, PIN_B5, PIN_B4, PIN_B3, PIN_B2, PIN_B1)
#use fixed_io(c_outputs=PIN_C6)*/
#fuses HS, NOWDT, NOPROTECT, NOLVP, NOBROWNOUT, NOPUT
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define LED0 PIN_A0
#define LED1 PIN_A1


Thanks by advance for your interest Smile
drh



Joined: 12 Jul 2004
Posts: 193
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Mon Nov 15, 2004 8:20 am     Reply with quote

Enable the power up timer and brownout detect.
_________________
David
YulL



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

PostPosted: Mon Nov 15, 2004 9:05 am     Reply with quote

Maybe but the problem is that I use the PIC16LF873A and my application run at 3.6V so Brown Out is not the right solution... Embarassed
Guest








PostPosted: Mon Nov 15, 2004 10:05 am     Reply with quote

I'm afraid that the problem requires a 'brownout' solution. The odds are that whatever you have as a reset circuit on MCLR, is not properly resetting the chip, if the supply is not off for a reasonable time. Remember that there is nothing to stop you implementing your own 'brownout' external to the chip. Several manufacturers (Maxim for example), do power supply supervsory IC's, that will trigger a reset. Alternatively, it is possible that using the watchdog, could allow you to force a reset if the main code is not running.

Best Wishes
YulL



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

PostPosted: Mon Nov 15, 2004 10:19 am     Reply with quote

Yes we've decided to use a MC330164D5 or LM8364 (National). I think it should explain why my program is not very stable when I disable BrownOut... Crying or Very sad

Thanks for your support Rolling Eyes
YulL



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

PostPosted: Mon Nov 15, 2004 10:41 am     Reply with quote

...and the WDTimer is not appropriate because I'm listening and driver and a component that send a start frame after being powered up... Rolling Eyes
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