|
|
View previous topic :: View next topic |
Author |
Message |
Knight_FlyCn
Joined: 10 May 2013 Posts: 16 Location: Việt Nam
|
Interrupt in RB0 |
Posted: Mon Jun 10, 2013 12:10 am |
|
|
Interrupt in RB0 my code not working. Why ??
Code: | #include <Coordinator.h>
#include "def_18f4620.c"
#include "slave_2_tx_rx.h"
#use delay(clock = 4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#bit CS = 0xF80.4
#bit RST = 0xF82.2
#bit INT_ = 0xF81.0
#bit WAKE = 0xF82.1
#bit CS_Direction = 0xF92.4
#bit RST_Direction = 0xF94.2
#bit INT_Direction = 0xF93.0
#bit WAKE_Direction = 0xF94.1
INT temp,command1;
int new_rx;
#INT_EXT
void EXT_isr(void)
{
new_rx = true;
}
void main()
{
TRISC0=0;
CS = 0;
RST = 0;
INT_ = 1;
WAKE = 0;
////////////////
CS_Direction = 0; // Set direction to be output
RST_Direction = 0; // Set direction to be output
INT_Direction = 1; // Set direction to be input
WAKE_Direction = 0; // Set direction to be output
Delay_ms(5);
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4); // Initialize SPI module
pin_reset(); // Activate reset from pin
software_reset(); // Activate software reset
RF_reset(); // RF reset
set_WAKE_from_pin(); // Set wake from pin
set_long_address(ADDRESS_long_2);
set_short_address(coord_address_short); // Set short address
set_PAN_ID(PAN_ID); // Set PAN_ID
init_ZIGBEE_nonbeacon(); // Initialize ZigBee module
nonbeacon_PAN_coordinator_device();
set_TX_power(31); // Set max TX power
set_frame_format_filter(1); // 1 all frames, 3 data frame only
set_reception_mode(1); // 1 normal mode
delay_ms(10);
enable_int();
pin_wake(); // Wake from pin
ext_int_edge(H_to_L);
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
printf(" RESET - THIET BI THU \r\n");
while (1)
{
if(new_rx)
{
new_rx = false;
temp = read_ZIGBEE_short(INTSTAT); // Read and flush register INTSTAT
read_RX_FIFO();
command1=DATA_RX[0];
printf("|Gia tri:%D \n",command1);
delay_ms(500);
}
}
} |
_________________ Thinh |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Jun 10, 2013 2:47 am |
|
|
First, don't fiddle around using register accesses.
The whole point of using the compiler, is to help allow you to be one step further from having to worry about hardware details. Using register accesses directly, puts you back into being 'hardcoded' for one chip.
Code: |
#define CS=PIN_A4
#define RST=PIN_C2
#define WAKE=PIN_C1
//Then
output_low(CS);
output_low(RST);
output_low(WAKE);
|
sets the direction, and the value, all in one line.
Makes _supporting_ the code in the future much easier, and reduces the number of lines involved.
Nice thing is if you want to move the pin later, you only have to change one define. Everything else is done for you.
There are further problems with this, in that you have the RS232 on pins C6, and C7, then set the TRIS on C7 to zero, overriding the compiler's settings. At this point RS232 will stop receiving...
Don't use 'assembler thinking', with the compiler....
Then you have lots of fiddling around, which you don't post, and could be the problem. enable_int?. pin_wake?. etc. etc...
Then you have no 'ERRORS' in the #use_rs232. This is _required_, repeat _required_, unless you add your own code to handle RS232 errors. Without this, if RS232 data arrives, and is not read, the UART _will_ be hung permanently. Since you have several delays, and no sign of an interrupt driven RS232 routine, if more than 2 characters arrive at any point, this will have triggered.
I'd suspect that actually your interrupt is triggering fine, but there is no RS232 data received, so nothing happens.
One other thing, "setup_adc_ports(NO_ANALOGS);" a lot of modern PIC's wake up with analog inputs defaulted to analog use. Interrupt won't work if this is the case. The compiler in most cases now, does override this, but not for all chips. |
|
|
Knight_FlyCn
Joined: 10 May 2013 Posts: 16 Location: Việt Nam
|
|
Posted: Mon Jun 10, 2013 11:11 am |
|
|
I can only say that my code runs perfectly. But the RB0 interrupt is not working. It only happens when I reset the pic.
And my define, I use my own def_18F4620.c rather not use the ccs file 18F4620.h
- So I think that interrupt RB0 is not working.
- I need advice about this error. _________________ Thinh |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon Jun 10, 2013 3:25 pm |
|
|
Post a SHORT but complete compilable code which shows the problem.
We can then copy and paste to test.
It will make life so much easier for all of us.
Mike |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Jun 10, 2013 3:36 pm |
|
|
Code: |
#INT_EXT
void EXT_isr(void)
{
byte junk;
new_rx = true;
junk=input_b();
}
|
does this solve your problem or make it worse or neither ??
it would be good to know what triggers the ext int also
got schematic?
the code you DO post is not enough for a sure diagnosis though
my suggestion is just a SWAG |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Jun 11, 2013 1:37 am |
|
|
If your code ran perfectly as you claim, then you wouldn't be asking a question here.
Why are you using your own processor defines? What do you beleive is wrong with the CCS ones? Frankly, without knowing *exactly* what you've done in ALL your code, we cannot be sure what the problem is. However, if it's as simple as someone here has suggested it might be, then it shows you do not have anywhere as near as good a grasp of the processor as you'd need to be able to do away with CCS's defines, and to pronounce your code to be "running perfectly". |
|
|
|
|
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
|