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

#int_tbe

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



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

#int_tbe
PostPosted: Thu Aug 16, 2007 5:22 am     Reply with quote

can anybody please tell me why this doesn't want to work
i just want to transmit the message.

Code:


#include <16F883.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#define T_BUFFER_SIZE 8

//// Receive Variables
char charRecMessage; //Message received

///Transmit Variables
byte t_buffer[T_BUFFER_SIZE];
byte t_head= 0;
byte t_tail = 0;
byte txbyte = 0;


void send_byte(txbyte)
{
      t_buffer[t_head] = txbyte;
      t_head++;
      
      if(t_head = T_BUFFER_SIZE)
               t_head = 0;
               enable_interrupts(INT_TBE);

}



void CheckReceived_Message()
   {
   
       char command = 0;
         command = charRecMessage; //command to send to pic to trigger action.
         printf("\r\n die command is");
         putc(command); //checkmessage return die regte command van die interrupt routine.
            if(command == 's')
               {
             printf("\r\n Start transmitting the saved values" );
               }
}



void main() {
  //Set up interrupts
  enable_interrupts(INT_RDA); //Allow charaters to be received on RS-232 port
  enable_interrupts(GLOBAL); //Enable global interrupt handler
 
 
     while(1) {
   
              byte message = 0b11111111;
                CheckReceived_Message();
              send_byte(message);
                 delay_ms(2000);
            }

}



#INT_RDA
rda_handler() {
//interupt handler for receiving a character on the rs232 port

               charRecMessage = getc(); //die waarde word in checkmessage gereflekteer.
              }



#INT_TBE
t_handler(){

   if(t_head == t_tail)

         disable_interrupts(INT_TBE);
         

         else {
                    putc(t_buffer[t_tail]);
               t_tail++;
               if(t_tail == T_BUFFER_SIZE)
               t_tail = 0;
              }
}
 
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 5:45 am     Reply with quote

Quote:
if(t_head = T_BUFFER_SIZE)
Change to '=='
Eeprom_programmer



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 6:42 am     Reply with quote

Thank you for spotting that error, but i am afraid that isn't the problem.....

any futher ideas...?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 6:52 am     Reply with quote

Eeprom_programmer wrote:
Thank you for spotting that error, but i am afraid that isn't the problem.....
You may be afraid, but have you tested it?

Code:
      if(t_head = T_BUFFER_SIZE)
               t_head = 0;
Because of the error the if-statement is always true. This causes t_head to always stay equal to zero.
In your TBE_interrupt handler you have
Code:
   if(t_head == t_tail)

         disable_interrupts(INT_TBE);
t_head == 0 and t_tail == 0. Nothing will be transmitted and the interrupt is disabled again.
Exactly the behaviour you are describing.....
Eeprom_programmer



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 7:16 am     Reply with quote

Thx for the detailed explanation, but I tested it the moment i got your reply...And unfortuanetly it didn't work. I still get the same behavior.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 10:29 am     Reply with quote

I tested the code in the MPLAB simulator and it works like a charm. How are you testing the transmission? Maybe your receiving program can not display the 0xFF value you are transmitting?

What is your compiler version?
Ttelmah
Guest







PostPosted: Thu Aug 16, 2007 10:50 am     Reply with quote

Put a dummy 'getc', in the receive interrupt code. Otherwise, if the RX line is not high, this will get called, will never clear, and the processor will deadlock, looping, and not receiving the character.

Best Wishes
Eeprom_programmer



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 1:52 pm     Reply with quote

I use version4.0227 i test it using hyperterminal and connecting it to my board. Is it possible that this routine cant work for the pic16f883?

Al it seems to do is, go into the INT_RDA interrupt and then into sent_byte but never into the INT_TBE?

I dont understand what you mean Ttelmah...what is a dummy getc? Sorry but i am totally new to the serial interrupts
Eeprom_programmer



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 1:54 pm     Reply with quote

I also just want to add that the #INT_RDA interrupt works very good, but it doesn't transmit anything.
Ttelmah
Guest







PostPosted: Thu Aug 16, 2007 2:10 pm     Reply with quote

At present, your #int_rda, does nothing.
Now, _if this interrupt occurs, the only way to clear the interrupt, is to receive the character_. If you don't receive the character, the interrupt will remain set. On exit, the interrupt will immediately be called again, and the transmitter interrupt will never get called.
Hence, the minimum #int_rda, is:
Code:

#int_rda
void receive_int(void) {
   int8 dummy;
   dummy=getc();
}


Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 4:07 pm     Reply with quote

TTelmah,
The tab size in the given code is very large but if I'm reading it correctly he has a dummy getc() in his int_rda() function ???

Eeprom_programmer,
v4.0227 is an invalid version number, there should be only 3 digits after the dot. Anyway, it is an old and unstable compiler version. The early v4.0xx versions had many bugs and this may be just one of them. The compiler started to become more or less useable at version v4.030.

Hyperterm is a terrible program. I have spent a lot of time searching for bugs in my PIC programs when it was just Hyperterm doing weird things. Try Siow.exe that is provided with the compiler.
Also, sending 0xFF is a non-visible character. Try sending another data byte instead.
Eeprom_programmer



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

PostPosted: Mon Aug 20, 2007 7:05 am     Reply with quote

Again - you were correct, the moment i changed the value 0xff the program worked. The version i use now is v4.033
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