|
|
View previous topic :: View next topic |
Author |
Message |
adalucio
Joined: 16 Mar 2009 Posts: 29
|
interrupt rs232 18F26K80 |
Posted: Sun Oct 27, 2013 5:25 am |
|
|
Hi all,
I want to setup interrupt on rs232 data received for both streams BT2 and BT4. How can I do that? I have tried this code, but it doesn't work. PIN_LED_A and PIN_LED_B never get on.
Thanks
Code: |
#include <18F26K80.h>
#FUSES NOWDT // No Watch Dog Timer
#FUSES NOXINST // Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES INTRC_IO // Internal RC Osc, no CLKOUT
#FUSES NOBROWNOUT // No brownout reset
#FUSES WDT_NOSLEEP // Watch Dog Timer, disabled during SLEEP
#FUSES NOPUT
#FUSES NOMCLR
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=BT2,RESTART_WDT,DISABLE_INTS)
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_B6,rcv=PIN_B7,bits=8,stream=BT4,RESTART_WDT,DISABLE_INTS)
#int_rda
void RDA_isr()
{
char c;
output_high(PIN_LED_A);
output_high(PIN_LED_B);
c = getc();
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_4(T4_DISABLED,0,1);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1)
{
delay_ms(1000);
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Oct 27, 2013 7:41 am |
|
|
1) Get rid of disable_ints in the RS232 declaration.
2) In your INT_RDA, you need to read the correct stream. So fgetc(BT2) for INT_RDA, and fgetc(BT4) for INT_RDA2.
3) The second serial interrupt is INT_RDA2.
4) Look at the I/O port list for the pins in the data sheet. Realise that for each pin, things lower down the list take 'priority' over those above. You need to disable everything that has higher priority than the serial port. setup_spi(FALSE); setup_ccp3(OFF); (for the first port).
Same applies for the second port.
5) You don't show the declarations for PIN_LED_A or B, so we can't comment on whether these can be driven high. |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sun Oct 27, 2013 10:56 am |
|
|
Thank you very much Ttelmah.
I made some changes, but it doesn't work.
Code: |
#include <18F26K80.h>
#FUSES NOWDT // No Watch Dog Timer
#FUSES NOXINST // Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES INTRC_IO // Internal RC Osc, no CLKOUT
#FUSES NOBROWNOUT // No brownout reset
#FUSES WDT_NOSLEEP // Watch Dog Timer, disabled during SLEEP
#FUSES NOPUT
#FUSES NOMCLR
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=BT2,RESTART_WDT)
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_B6,rcv=PIN_B7,bits=8,stream=BT4,RESTART_WDT)
#define PIN_LED_A PIN_A6
#define PIN_LED_B PIN_A7
#int_rda
void RDA_isr()
{
char c;
output_high(PIN_LED_A);
c = fgetc(BT2);
}
#int_rda2
void RDA2_isr()
{
char c;
output_high(PIN_LED_B);
c = fgetc(BT4);
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_4(T4_DISABLED,0,1);
setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
setup_ccp3(CCP_OFF);
enable_interrupts(INT_RDA|INT_RDA2);
enable_interrupts(GLOBAL);
delay_ms(1500);
while(1)
{
delay_ms(1000);
}
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Oct 27, 2013 12:42 pm |
|
|
Code: | #use rs232(baud=9600,parity=N,stop=1,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=BT2,RESTART_WDT) | Why restart the WDT when watchdog is disabled anyway?
I don't think it causes your problem but it adds unwanted complexity.
Code: | setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED); | This is not what Ttelmah told you and is the wrong parameter. SS stands for 'Slave Select', a parameter only to be used in combination with a SPI Slave configuration. Now the SPI configuration is invalid and can lead to strange results.
Where did this come from? We know the old CCS Configuration Wizard generated this code but I don't know if the current versions still do. Which leads to the question: Which CCS version are you using???
Forum rule is to always post your version number!!!
adalucio wrote: | I made some changes, but it doesn't work. | This is not very helpful info. You are sitting there with the hardware in front of you.
What doesn't work?
And perhaps more importantly: what does work?
Have you confirmed your processor is running?
And have you confirmed it is running at your expected frequency?
These questions can easily be confirmed when you add a 1 second blinking LED to your main routine. Simple, but very effective to proof the basic functions are working. |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sun Oct 27, 2013 1:06 pm |
|
|
ckielstra wrote: | Code: | #use rs232(baud=9600,parity=N,stop=1,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=BT2,RESTART_WDT) | Why restart the WDT when watchdog is disabled anyway?
I don't think it causes your problem but it adds unwanted complexity.
|
Because I will use it after rs232 works
ckielstra wrote: |
Code: | setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED); | This is not what Ttelmah told you and is the wrong parameter. SS stands for 'Slave Select', a parameter only to be used in combination with a SPI Slave configuration. Now the SPI configuration is invalid and can lead to strange results.
Where did this come from?
|
I take it from program help
Code: |
Syntax:
setup_spi (mode)
setup_spi2 (mode)
Parameters:
mode may be:
SPI_MASTER, SPI_SLAVE, SPI_SS_DISABLED
SPI_L_TO_H, SPI_H_TO_L
SPI_CLK_DIV_4, SPI_CLK_DIV_16,
SPI_CLK_DIV_64, SPI_CLK_T2
SPI_SAMPLE_AT_END, SPI_XMIT_L_TO_H
Constants from each group may be or'ed together with |.
|
ckielstra wrote: |
We know the old CCS Configuration Wizard generated this code but I don't know if the current versions still do. Which leads to the question: Which CCS version are you using???
Forum rule is to always post your version number!!!
|
sorry. version is 5.007
ckielstra wrote: |
adalucio wrote: | I made some changes, but it doesn't work. | This is not very helpful info. You are sitting there with the hardware in front of you.
What doesn't work?
|
PIN_LED_A and PIN_LED_B never get on.
ckielstra wrote: |
And perhaps more importantly: what does work?
Have you confirmed your processor is running?
And have you confirmed it is running at your expected frequency?
These questions can easily be confirmed when you add a 1 second blinking LED to your main routine. Simple, but very effective to proof the basic functions are working. |
Yes all is running fine except for rs232 interrupts. I checked rs232 before without interrupts and it was working.
Thanks |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sun Oct 27, 2013 1:09 pm |
|
|
with
Code: |
setup_spi(FALSE);
setup_spi2(FALSE);
|
still don't work |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Oct 27, 2013 1:15 pm |
|
|
And what about my other questions?
Did you add the blinking LED to your main function and is it working?
Post your compiler version number!!!
It might be a known problem in your compiler version.
Without an answer to this question I refuse to further help you. |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sun Oct 27, 2013 1:20 pm |
|
|
sorry but I've already answered your questions in my previous post, including the version number |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 27, 2013 1:43 pm |
|
|
Quote: | enable_interrupts(INT_RDA|INT_RDA2); |
This is wrong. It has to be done with sequential calls to enable_interrupts()
for each INT_xxx. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Oct 27, 2013 2:21 pm |
|
|
How are your LED's wired?.
You have not answered the question whether you have tried flashing the LED first. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Oct 27, 2013 3:21 pm |
|
|
adalucio wrote: | sorry but I've already answered your questions in my previous post, including the version number | I'm sorry too. I only saw your last post and didn't see you posted another one a few minutes before.
I'm used to people editing their post when they are the last ones to respond in a thread. |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sun Oct 27, 2013 3:33 pm |
|
|
PCM programmer wrote: | Quote: | enable_interrupts(INT_RDA|INT_RDA2); |
This is wrong. It has to be done with sequential calls to enable_interrupts()
for each INT_xxx. |
Really thanks! now it works
Code: |
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Oct 28, 2013 1:07 am |
|
|
As a general comment, restarting the watchdog, in the serial routines, rather 'ruins' the 'point' of the watchdog....
Done 'properly', the watchdog should _only_ be reset, if the chip is running, and correctly doing what it should be doing. The reset code should also only actually be 'reachable', when everything is working right.
Sticking 'restart_wdt' instructions inside each call to putc/getc, means that you could (for example), sit in a routine waiting for data to arrive, have the serial actually locked up, yet still sit restarting the watchdog....
Also having restart_wdt instructions in the code in general, means that the code can go completely 'wrong', and walk the wrong path through the routines, yet still hit restart instructions....
Designing code properly to use the watchdog, is not a case of just turning it on, and restarting it all over the code. This is basically pointless.
The normal way to design a watchdog routine, that has a chance of doing something useful, is to have a single routine, containing in sequence, tests for every aspect of the code working correctly. Have characters been received?. Have counters updated?. etc. etc.. Followed by a single 'restart_wdt', which is only executed if _all_ the conditions are true. This way if the code goes on a 'random walk' getting to part it should not reach, it still can't reach the actual restart instruction, since the conditions are false.
Using the watchdog, requires _thought_.
Best Wishes |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Oct 28, 2013 8:34 am |
|
|
"Using the watchdog, requires _thought_. " ...
and even then it can go wrong. Remember one of the Martian probes that part way to Mars started continuously resetting/rebooting? They finally tracked that one down to being too tight on the timing - the normal operation was to do normal calculations, check things including the file system THEN reset the watchdog. Unfortunately, when it had taken enough pictures, the file system check could not complete in the required time and the watchdog kept rebooting it. They finally figured it out and managed to send commands to delete lots of images so it could complete in time. Almost lost that one. Watchdogs are great ways of saving a stuck processor, but things can go wrong even with the best planning
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Oct 28, 2013 9:36 am |
|
|
Yes, and _very_ true with the PIC. Note the tolerance on the watchdog timings. The default 18mSec timeout, has a tolerance on most chips between something like 7mSec and 22mSec.....
Sent to 'get you' when something changes like the weather.
Best Wishes |
|
|
|
|
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
|