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

ex_crc.c question

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



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

ex_crc.c question
PostPosted: Mon Jan 15, 2007 5:28 pm     Reply with quote

Hi,

I am implementing this example verbatim. I am using a 18F2680 but pin assignments are the same for this example.

In main .. interrupts are enabled :

Code:

ext_int_edge(H_TO_L);                        // init interrupts
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);


and the int_ext isr function is:

Code:

#INT_EXT
void ext_isr()
{
   ext_buffer[ext_buffer_next_in] = getc();     // get a byte, put it in buffer

   if(++ext_buffer_next_in == BUFFER_SIZE)      // increment counter
      ext_buffer_next_in = 0;
}


my TX PIC will hang at the interrupt at the getc() .. but I don't understand why what is causing the interrupt .. i tried disconnecting the wires to the interrupt pins B2-B0 but still it hangs .. then eventually it continues ??

thoughts?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 6:07 pm     Reply with quote

Make certain that pin B0 is set as a digital pin. Use the NOPBADEN fuse
to make Port B come up as all digital at power-on reset.
Humberto



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

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 6:11 pm     Reply with quote

Quote:

my TX PIC will hang at the interrupt at the getc()


1) How did you determine that the program hang in getc ?

2) To stay in getc implies that the interrupt was triggered by a falling signal but
the expected character never end arriving.

3) Pls tell us what kind of data are you receiving.

4) Pls tell us something regarding your hardware in the Rx path.


Humberto
pwhitey86



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 7:02 pm     Reply with quote

Humberto wrote:
Quote:

my TX PIC will hang at the interrupt at the getc()


1) How did you determine that the program hang in getc ?

2) To stay in getc implies that the interrupt was triggered by a falling signal but
the expected character never end arriving.

3) Pls tell us what kind of data are you receiving.

4) Pls tell us something regarding your hardware in the Rx path.


Humberto


1) in the isr routine i placed output_high(pin_A1) before the getc line on one build and it goes high and then after the getc line in another build and it won't go high .. so i figured that getc was blocking

2) ya .. my question is why did the interrupt trigger in the transmitting pic when it is the only one sending characters

3) the data that is being passed to the receive pic is from the example
Code:

packet_buffer[0] = SEND_ADDRESS;
         packet_buffer[1] = MACHINE_ADDRESS;
         packet_buffer[2] = 0;
         packet_buffer[3] = 0;
         packet_buffer[4] = 9;
         packet_buffer[5] = 'H';
         packet_buffer[6] = 'i';
         packet_buffer[7] = ' ';
         packet_buffer[8] = 't';
         packet_buffer[9] = 'h';
         packet_buffer[10] = 'e';
         packet_buffer[11] = 'r';
         packet_buffer[12] = 'e';
         packet_buffer[13] = '!';
         send_packet(packet_buffer, 14);        // send message


4) from the TX pic to the RX pick B0 goes to B1 and B1 goes to B0 .. just a straight line .. they also have common ground

---

Also, it seems that the RX pic is resetting when it gets to this line in the ex_crc.c example:
Code:

if(get_packet(packet_buffer))             // if valid packet


i say that it resets because i have and LED that blinks once at turn on and it continues to blink

thanks for the help .. i will try the other suggestion as well
Humberto



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

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 7:39 pm     Reply with quote

According to your description I guess you would have a problem regarding the
power pins, faulty GND, decoupling capacitors not present, noisy power supply and/or
something wrong in the Reset circuit path.

I would include the restart_cause() control function, in this device
it will give you up to 7 reason.
Sorry for not being more concise. I only can give you just some tips for focusing the
problem.


Humberto
Ttelmah
Guest







PostPosted: Tue Jan 16, 2007 6:00 am     Reply with quote

What is the #USE_RS232 defintion for the getc?...

Best Wishes
Humberto



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

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 6:43 am     Reply with quote

Quote:

2) ya .. my question is why did the interrupt trigger in the transmitting pic when it is the only one sending characters

Does the receiver is echoing something while receiving ?


Humberto
pwhitey86



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 6:47 am     Reply with quote

Ttelmah wrote:
What is the #USE_RS232 defintion for the getc?...

Best Wishes


From the ex_crc.c example in the example folder the #use rs232 line for pic to pic comm is

Code:

#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0)
pwhitey86



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 6:50 am     Reply with quote

Humberto wrote:
Quote:

2) ya .. my question is why did the interrupt trigger in the transmitting pic when it is the only one sending characters

Does the receiver is echoing something while receiving ?


Humberto


Actually yes .. the RX pic is supposed to send back a NACK or ACK etc .. but still the interrupt in the TX pic gets tripped but then it gets stuck at the getc waiting for a character (or this is what i surmise)

but it still hangs even if there is nothing connected to the TX/RX (B0/B1) pins on the TX pic
Humberto



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

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 6:56 am     Reply with quote

Quote:

but it still hangs even if there is nothing connected to the TX/RX (B0/B1) pins on the TX pic


Hook a 10K pull up in PIN_B0.

Humberto
pwhitey86



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 7:09 am     Reply with quote

I added output_low(pin_B0) and output_low(pin_B1) to both RX and TX chips and that seems to solve the issue .. pin B0 went high on the RX chip at turn on and caused the int on the TX
Humberto



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

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 7:24 am     Reply with quote

Quote:

So I put a 10k pull down resistor on B0 and that seems to correct the issue ..


Good news! but it should be tied to +5V (pull up) not a pull down, according to your code:
Code:

   ext_int_edge(H_TO_L);                        // init interrupts
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);


Humberto

Edited: When I posted this answer the quoted phrase suddenly was changed.(???)
pwhitey86



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 7:49 am     Reply with quote

ya .. i edited it bc the pull down did not work .. and rather what i put above did Smile
Humberto



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

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 10:14 am     Reply with quote

Quote:

added output_low(pin_B0) and output_low(pin_B1) to both RX and TX chips and that seems to solve the issue ..

This is a weak argument, according to your definition PIN_B0 is an INPUT.
Code:

#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0)



Quote:

pin B0 went high on the RX chip at turn on and caused the int on the TX

This also is a weak argument, according to your definition PIN_B0 MUST BE High
when in idle state, and a falling down must trigger the INT_EXT.

Code:

  ext_int_edge(H_TO_L);                       



Donīt want to be offensive but this is like to do pitfall playing the solitaire... Shocked


Humberto
pwhitey86



Joined: 11 Jan 2007
Posts: 9
Location: Philadelphia, PA, USA

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 5:19 pm     Reply with quote

ya .. humberto i took the statements out .. yes my reasoning was flawed

anyhow .. another question

currently I use pins b0 and b1 for RX TX .. is it possible to us b2 as say another RX pin since it is also an interrupt capable pin on the 18F2680?

ie can i do this
Code:

#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B2)


i tried but it's not working out .. keeps hanging in the interrupt.


.. and one more .. can I change the rcv pin in main()?

thanks
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