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

Serial interrupt won't receive

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







Serial interrupt won't receive
PostPosted: Thu May 16, 2002 9:06 am     Reply with quote

I'm using a 16C74B and am having trouble getting the serial interrupt routine to receive anything. It seems to send data out just fine. I have my board connected to the serial port on my PC and can monitor the serial data using hyperterminal and other software. If I send anything to the 16C74B it doesn't seem to receive anything. I took the example code for the serial interrupt routine and simplified it. Please look at the code below and let me know if you see anything incorrect.

#include <16c74b.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=12288000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, enable=PIN_C5)


#define BUFFER_SIZE 32
byte buffer[BUFFER_SIZE];
byte next_in = 0;
byte next_out = 0;


#int_rda
void serial_isr()
{
int t;

buffer[ next_in ] = getc();
t = next_in;
next_in++;

if( next_in == BUFFER_SIZE )
{
next_in = t; // Buffer full !!
}
}


main()
{
printf("\r\n\Running...\r\n");

enable_interrupts(int_rda);
enable_interrupts(global);

// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay

while (TRUE)
{
delay_ms(10000);

disable_interrupts(int_rda);

printf("\r\nBuffered data (\%d, \%d)", next_in, next_out );

while(next_in != next_out)
{
printf("\r\nBuffered data (\%d, \%d) =>\%c", next_in, next_out, buffer[next_out++] );
}
printf("<= Buffer End\r\n" );

next_in = next_out = 0;

delay_ms(1000);

printf("\r\n\Running...\r\n");
enable_interrupts(int_rda);
}
}

I'm new to the microchip devices, but have programmed other micro-controllers. I appreciate any help you can give.

Thanks,
Ric
___________________________
This message was ported from CCS's old forum
Original Post ID: 4401
JB
Guest







Re: Serial interrupt won't receive
PostPosted: Thu May 16, 2002 9:43 am     Reply with quote

Are you using a level shifter between the PIC and the PC?


:=I'm using a 16C74B and am having trouble getting the serial interrupt routine to receive anything. It seems to send data out just fine. I have my board connected to the serial port on my PC and can monitor the serial data using hyperterminal and other software. If I send anything to the 16C74B it doesn't seem to receive anything. I took the example code for the serial interrupt routine and simplified it. Please look at the code below and let me know if you see anything incorrect.
:=
:=#include <16c74b.h>
:=#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
:=#use delay(clock=12288000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, enable=PIN_C5)
:=
:=
:=#define BUFFER_SIZE 32
:=byte buffer[BUFFER_SIZE];
:=byte next_in = 0;
:=byte next_out = 0;
:=
:=
:=#int_rda
:=void serial_isr()
:={
:= int t;
:=
:= buffer[ next_in ] = getc();
:= t = next_in;
:= next_in++;
:=
:= if( next_in == BUFFER_SIZE )
:= {
:= next_in = t; // Buffer full !!
:= }
:=}
:=
:=
:=main()
:={
:= printf("\r\n\Running...\r\n");
:=
:= enable_interrupts(int_rda);
:= enable_interrupts(global);
:=
:= // The program will delay for 10 seconds and then display
:= // any data that came in during the 10 second delay
:=
:= while (TRUE)
:= {
:= delay_ms(10000);
:=
:= disable_interrupts(int_rda);
:=
:= printf("\r\nBuffered data (\%d, \%d)", next_in, next_out );
:=
:= while(next_in != next_out)
:= {
:= printf("\r\nBuffered data (\%d, \%d) =>\%c", next_in, next_out, buffer[next_out++] );
:= }
:= printf("<= Buffer End\r\n" );
:=
:= next_in = next_out = 0;
:=
:= delay_ms(1000);
:=
:= printf("\r\n\Running...\r\n");
:= enable_interrupts(int_rda);
:= }
:=}
:=
:=I'm new to the microchip devices, but have programmed other micro-controllers. I appreciate any help you can give.
:=
:=Thanks,
:=Ric
___________________________
This message was ported from CCS's old forum
Original Post ID: 4402
RicPeterson
Guest







Re: Serial interrupt won't receive (w/ MAX485)
PostPosted: Thu May 16, 2002 10:24 am     Reply with quote

:=Are you using a level shifter between the PIC and the PC?
:=
:=

The PIC is connected to a MAX485 chip. I'm running the lines through a 485-232 converter to connect to the PC serial port. I know that this part is working as the PC does receive data sent from the PIC as expected with no errors.

The PIC connection to the MAX 485 is as follows:
PIC MAX485
RC7/RX/Pin 26 <-> RO/Pin 1
RB1 <-----------> RE/Pin 2
RC5/Pin 24 <----> DE/Pin 3
RC6/TX/Pin 25 <-> DI/Pin 4

My #use rs232 line is set up to drive DE high on transmit. I added a line of code in my program to drive RB1 low, as the RE pin on the MAX485 requires a low for receive enable. When DE goes high that disables receive, according to the MAX485 specs. For some reason I'm still not seeing anything.

-Ric
___________________________
This message was ported from CCS's old forum
Original Post ID: 4404
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Serial interrupt won't receive
PostPosted: Thu May 16, 2002 12:05 pm     Reply with quote

:=I'm using a 16C74B and am having trouble getting the serial interrupt routine to receive anything.
----------------------------------------------

Have you proven that it can receive without using int_rda ?
Will it echo characters back to the PC ?

Here's a small test program which receives a char,
increments it, and sends it back. The increment
is done to make sure that you're really getting
an echoed character, and that you're not being
faked out because the terminal program is set
on "local echo".

Also, for initial testing, I would get rid of
all the RS-485 stuff. I would just use a MAX232A,
and keep it very simple.

main()
{
char c;

while(1)
{
c = getc();
c++;
putc(c);
}

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 4409
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

Re: Serial interrupt won't receive (w/ MAX485)
PostPosted: Thu May 16, 2002 12:22 pm     Reply with quote

Are you sure the data from the PC is working?

The PC will output data as RS-232 so unless you are using an add-in card with RS-485/422 drivers or a RS-232 to RS-485 converter the signal levels may be a problem. Also if you are using a converter that does not have auto send control then whatever software the PC is using must handle TX control, usually using the RTS line. Also RS-485 needs to be properly terminated on each end, usually 120 Ohm.

To make things easier try to get things working with straight RS-232 then progress to RS-485.

When you do use RS-485, if things are half duplex, then you can tie the !RE and DE lines together that way if you are not in TX mode then you will be in RX mode and only use 1 control signal, TXEN.

:=:=Are you using a level shifter between the PIC and the PC?
:=:=
:=:=
:=
:=The PIC is connected to a MAX485 chip. I'm running the lines through a 485-232 converter to connect to the PC serial port. I know that this part is working as the PC does receive data sent from the PIC as expected with no errors.
:=
:=The PIC connection to the MAX 485 is as follows:
:=PIC MAX485
:=RC7/RX/Pin 26 <-> RO/Pin 1
:=RB1 <-----------> RE/Pin 2
:=RC5/Pin 24 <----> DE/Pin 3
:=RC6/TX/Pin 25 <-> DI/Pin 4
:=
:=My #use rs232 line is set up to drive DE high on transmit. I added a line of code in my program to drive RB1 low, as the RE pin on the MAX485 requires a low for receive enable. When DE goes high that disables receive, according to the MAX485 specs. For some reason I'm still not seeing anything.
:=
:=-Ric
___________________________
This message was ported from CCS's old forum
Original Post ID: 4413
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

Re: Serial interrupt won't receive (w/ MAX485)
PostPosted: Sat May 18, 2002 10:37 am     Reply with quote

:=Are you sure the data from the PC is working?
:=
:=The PC will output data as RS-232 so unless you are using an add-in card with RS-485/422 drivers or a RS-232 to RS-485 converter the signal levels may be a problem. Also if you are using a converter that does not have auto send control then whatever software the PC is using must handle TX control, usually using the RTS line. Also RS-485 needs to be properly terminated on each end, usually 120 Ohm.
:=
:=To make things easier try to get things working with straight RS-232 then progress to RS-485.
:=
:=When you do use RS-485, if things are half duplex, then you can tie the !RE and DE lines together that way if you are not in TX mode then you will be in RX mode and only use 1 control signal, TXEN.
:=
:=:=:=Are you using a level shifter between the PIC and the PC?
:=:=:=
:=:=:=
:=:=
:=:=The PIC is connected to a MAX485 chip. I'm running the lines through a 485-232 converter to connect to the PC serial port. I know that this part is working as the PC does receive data sent from the PIC as expected with no errors.
:=:=
:=:=The PIC connection to the MAX 485 is as follows:
:=:=PIC MAX485
:=:=RC7/RX/Pin 26 <-> RO/Pin 1
:=:=RB1 <-----------> RE/Pin 2
:=:=RC5/Pin 24 <----> DE/Pin 3
:=:=RC6/TX/Pin 25 <-> DI/Pin 4
:=:=
:=:=My #use rs232 line is set up to drive DE high on transmit. I added a line of code in my program to drive RB1 low, as the RE pin on the MAX485 requires a low for receive enable. When DE goes high that disables receive, according to the MAX485 specs. For some reason I'm still not seeing anything.

:=:=-Ric


Ric:

Your setup connection between PIC and MAX485 are rigth except for pins 2 and 3 of the MAX, they should be tied togheter to the Tx Enable pin of the PIC (RC5) and you DON'T NEED TO HANDLE IT, the compiler does it for you when in the definition:
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, enable=PIN_C5)
you include the term ENABLE, you are telling the compiler that you are using RS485, NOT RS232.

You can see the enable action with a scope, prior to start transmiting, this pin go high to enable the 485 transciver.

If you can't get a scope to see the PIC output when it is transmitting, just hang from +Vcc a LED + 680 ohm in the TX PIN_C6 and watch for some blinking while PIC is transmitting.

After power up, make sure that the iddle state of the Rcv_PIN_C7 is HIGH, if not reverse the 485 current loop (line side)

Hope this help. Tell us your result.

Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 4438
_________________
Humber
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