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

Uart problem

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







Uart problem
PostPosted: Fri Nov 07, 2008 2:30 pm     Reply with quote

I got no idea but my tx pin is going high at reset and wont do anything

Code:
/*
   Fichier:Encoder.c   
   Date: 7 FEV 2008     
   Auteur: Julien Gingras     
   Revision: 1.0
   Compilation:
            Compilateur: CCS
            Version:     3.5.0.92
            Librairies: 

*/

/*                 ***** LISTE DES INCLUDES *****                            */
#include "Flex_LCD420.c"      //LCD driver
#use delay(clock=4000000)      // Fixer la vitesse de l'horloge
#CASE               // Met le compilateur CASE SENSITIVE
                        // Permet d'utiliser delay_ms() et delay_us()       
#FUSES HS, NOPROTECT, NOBROWNOUT, NOWDT, NOPUT, NODEBUG, NOLVP, NOWRTD, NOFCMEN, NOCPB,
#use rs232(BAUD=38400, PARITY=N, BITS=8, STOP=2)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

/*                **** LISTE DES CONSTANTES *****                           */

#define NEC_INPUT PIN_A2



//we can t use B6 and B7 because they are use by ICD2   

/*            **** LISTE DES VARIABLES GLOBALES *****                       */


   int1 nReady = 0;
   int szAnswer[150];
   int nPos = 0;


/*               ***** LISTE DES PROTOTYPES *****                           */

void main(void);
void InitPic(void);
void interrupt_RDA();
void interrupt_timer1();
void CheckRom(char *szTx, int nNum);

/*               ***** PROGRAMME PRINCPAL *****                             */

void main(void)
{           
   int k, j = 0;
   unsigned int16 i = 0;
   int nCurrent;
   unsigned int8 nAdr;
   unsigned int8 nCom;
   int1 szNEC[40];
   int szMesh[30];
   int nSeq = 1;

   setup_oscillator(OSC_4MHZ); 
   
   InitPic();
   
   
   lcd_init();
   lcd_gotoxy(1,1);
   
//Test la radio mesh
   szMesh[0] = 0xA5;    //Sync
   szMesh[1] = 2;      //Lengh
   szMesh[2] = 0xb;   //Type Get REV
   szMesh[3] = nSeq;     //Seq
   szMesh[4] = 0;      //CheckSum
   CheckRom(szMesh, 4);
   nSeq ++;
     
   delay_ms(1000);
   //get rev de la radio mesh
   for(k=0;k<5;k++)
      putc(szMesh[k]);
  printf(lcd_putc, "%s", "Alex y rock\nen sale");
   
   while(!nReady)
      delay_us(100);
   nReady = 0;
   
   printf(lcd_putc, "%02X %02X %02X %02X %02X", szAnswer[0],szAnswer[1],szAnswer[2],szAnswer[3],szAnswer[4]);   
   
   szAnswer[11] = 0;
 //  printf(lcd_putc, "%s", &szAnswer[5]);
   
   while(TRUE)   //Main Loop
   {   do
      {
         //Looping here we can check if we received something on the rs232 (an event)
         if(nReady)
         {
            switch(szAnswer[2])
            {
               case 4:
                  lcd_gotoxy(1,2);
                  printf(lcd_putc, "DATA IN %02X %02X", szAnswer[1], szAnswer[29]);
                  break;
            }               
            nReady = 0;
         }
         
         //Check the state of the remote input
         nCurrent = input_state(NEC_INPUT);
      }while(nCurrent);//Loop that wait a input
     
      i = get_timer0()*2;
      set_timer0(0);   //Reset the timer
   
      if((i>1100)&&(i<1300))
      {
         szNEC[j] = 0;
         j++;
      }     
      else if((i>2200)&&(i<2600))
      {
         szNEC[j] = 1;
         j++;
      }
      else if((i<15000)&&(i>13000))
      {
         j = 0;
      }
      while(!input_state(NEC_INPUT));
     
      if(j == 32)
      {
         nAdr = 0;
         nCom = 0;
         memcpy(&nAdr, szNEC, 1);
         for(k=0;k<8;k++)
         {
            szNEC[k] = szNEC[16+k];
         }
         memcpy(&nCom, szNEC, 1);
         lcd_gotoxy(1,3);         
         printf(lcd_putc, "Adresse = %02X", nAdr); 
         lcd_gotoxy(1,4);
         printf(lcd_putc, "Commande = %02X", nCom); 
         
         /*We also tell the mesh radio to send this to the other one (1 = pc)*/
         szMesh[0] = 0xA5;    //Sync
         szMesh[1] = 0x0E;   //Lengh
         szMesh[2] = 0x11;   //Type ML_TRANSMIT
         szMesh[3] = nSeq;     //Seq
         //Parameters
         szMesh[4] = 0x01;   //Long Adress mode
         szMesh[5] = 0x00;   //Mesh radio mac 1 is the PC
         szMesh[6] = 0x14;
         szMesh[7] = 0x77;
         szMesh[8] = 0x00;
         szMesh[9] = 0x00;
         szMesh[10] = 0x00;
         szMesh[11] = 0x00;
         szMesh[12] = 0x03;
         szMesh[13] = 0x4;   //Two byte to send
         /*szMesh[14] = nAdr&0xff;
         szMesh[15] = nCom&0xff;
         */
         szMesh[14] = 0x59;
         szMesh[15] = 0x1e;
         szMesh[16] = 0;      //CheckSum
         CheckRom(szMesh, 16);
         nSeq ++;
       //  for(k=0;k<17;k++)
       //     putc(szMesh[k]);
           
           
           
      /*   szMesh[0] = 0xA5;    //Sync
         szMesh[1] = 2;      //Lengh
         szMesh[2] = 0xb;   //Type Get REV
         szMesh[3] = nSeq;     //Seq
         szMesh[4] = 0;      //CheckSum
         for(k=0;k<4;k++)
            szMesh[4] += szMesh[k];
         szMesh[4] ^= 0xFF;
         szMesh[4]++;   
         nSeq ++;
         for(k=0;k<5;k++)
            putc(szMesh[k]);*/
           
      /*         
         while(!nReady)
            delay_us(100);
         nReady = 0;
         lcd_gotoxy(1,2);
         if(szAnswer[2] == 3)   //If PENDING
         {
            printf(lcd_putc, "PEND ");
            while(!nReady)
               delay_us(100);
            nReady = 0;   
            if(szAnswer[2] == 0)   //If Sucess
            {
               printf(lcd_putc, "Sucess");
            }     
         }
         else
            printf(lcd_putc, "Error %x", szAnswer[3]);
            */
         j = 0;
      }
   }
}

/**********************************************************************************
Set port direction
We set a timer for the remote decoding
***********************************************************************************/
void InitPic(void)
{   
   setup_adc(ADC_OFF);
   set_tris_a(0x04);//A2 as input
   set_tris_c(0x80);//Rx(C7) as input
   output_high(PIN_A1);
   delay_ms(5);
   //Set timer 0 in 16 bit to count the uS between input
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);   //1 at timer value mean 2uS
   set_timer0(0);
   
   //Set timer 1 to make the led flash
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   set_timer1(15536);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER1);
   
   //Empty the rx buffer (how could data be in)
   while(kbhit())
      getc();
   //Interrupt in RX for RS232
   nPos = 0;
   enable_interrupts(INT_RDA);
}

/*
Interrupt when something is received by rs232
*/
#INT_RDA
void interrupt_RDA()
{
   unsigned char nChar;
   do
   {
      nChar = getc();
      if((nChar == 0xA5)&&(nPos == 1))
      {
         nPos = 0;
      }
      szAnswer[nPos] = nChar;
      if(nPos >= 1)
      {
         if (nPos == szAnswer[1]+2)
         {
            nReady++;
            nPos = 0;
         }
      }
      nPos++;
   }while(kbhit());
   clear_interrupt(INT_RDA);
}

/*
Interrupt of timer 1
We toogle the led and reset it
*/
#INT_TIMER1
void interrupt_timer1()
{
   output_toggle(PIN_A4);
   set_timer1(15536);
   clear_interrupt(INT_TIMER1);
}


/*
Calculate the checksum for mesh radio
*/
void CheckRom(char *szTx, int nNum)
{
   int i;

    szTx[nNum] = 0;
    for(i=0;i<nNum;i++)
        szTx[nNum] += szTx[i];
    szTx[nNum] ^= 0xFF;
    szTx[nNum]++;
}


I know it pass by the putc function since my lcd show the message
so why its not transmitting anything?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 07, 2008 2:45 pm     Reply with quote

Make a small test program that works. Then add in portions of your
code until it fails. Then you will know the section of code that is causing
the problem.
Juls
Guest







PostPosted: Fri Nov 07, 2008 7:20 pm     Reply with quote

I will try this probably monday

so you are telling me that the uart part is ok?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 07, 2008 9:14 pm     Reply with quote

No. I'm saying that you need to prove that the UART works OK
in a small test program. Then start adding in the other parts of
your code.
Juls
Guest







PostPosted: Wed Nov 12, 2008 3:38 pm     Reply with quote

do work now
in the use
I never said UART1
....
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