View previous topic :: View next topic |
Author |
Message |
Eeprom_programmer
Joined: 07 Aug 2007 Posts: 24
|
#int_tbe |
Posted: Thu Aug 16, 2007 5:22 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 5:45 am |
|
|
Quote: | if(t_head = T_BUFFER_SIZE) | Change to '==' |
|
|
Eeprom_programmer
Joined: 07 Aug 2007 Posts: 24
|
|
Posted: Thu Aug 16, 2007 6:42 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 6:52 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 7:16 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 10:29 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 10:50 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 1:52 pm |
|
|
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
|
|
Posted: Thu Aug 16, 2007 1:54 pm |
|
|
I also just want to add that the #INT_RDA interrupt works very good, but it doesn't transmit anything. |
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 16, 2007 2:10 pm |
|
|
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
|
|
Posted: Thu Aug 16, 2007 4:07 pm |
|
|
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
|
|
Posted: Mon Aug 20, 2007 7:05 am |
|
|
Again - you were correct, the moment i changed the value 0xff the program worked. The version i use now is v4.033 |
|
|
|