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 CCS Technical Support

Who can help me ? UART PIC18F4620 and ZigBee

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



Joined: 10 May 2013
Posts: 16
Location: Việt Nam

View user's profile Send private message AIM Address

Who can help me ? UART PIC18F4620 and ZigBee
PostPosted: Tue May 14, 2013 4:17 am     Reply with quote

Code:
#include <Coordinator.h>
#include "def_18f4620.c"
#include "slave_2_tx_rx.h"


#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;
INT COMMAND,adress_surport=0x01;
const int IP_request=0x00,ip_surport=0x10;
#INT_EXT
void ngat_RB0()
{   
   temp = read_ZIGBEE_short(INTSTAT); // Read and flush register INTSTAT
   if ((temp&(1<<3))==(1<<3))
   {  rc0=rd3=!rd3;
      read_RX_FIFO();     
      command=data_rx[0];
      switch (command)
      { 
      case IP_request:
         adress_surport++;
         PAN_ID_destination[0] = PAN_ID[0];
         PAN_ID_destination[1] = PAN_ID[1];
         address_short_destination[0] =   rfd_address_short[0];
         address_short_destination[1] =   rfd_address_short[1];
         PAN_ID_source[0] = PAN_ID[0];
         PAN_ID_source[1] = PAN_ID[1];
         address_short_source[0] = coord_address_short[0];
         address_short_source[1] = coord_address_short[1];
         data_tx[0]=ip_surport;
         data_tx[1]=adress_surport;
         write_TX_normal_FIFO();
      break;
      }
   }
   DISABLE_INTERRUPTS(INT_EXT);
}


void main()
{
   TRISB1=TRISB2=TRISB3=1;
   TRISC0=TRISD3=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
   rc0=rd3=1;
   
   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
   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT);
   ext_int_edge(H_to_L);
   while (1)
      {
      enable_interrupts(INT_EXT);
      }

}


I do not know what the above command made ​​the connection to the computer. To transfer data to and from RFD to Coodinator computer.

---> Who can help me ? what line code ?
_________________
Thinh
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 14, 2013 6:00 am     Reply with quote

Without seeing what's in these files...
#include <Coordinator.h>
#include "def_18f4620.c"
#include "slave_2_tx_rx.h"
... it's nearly impossible to help you.

It appears that a Zigbee module is connected via SPI mode to a PIC and that 'something' interrupts the PIC on the B0 pin,triggering the ISR,'stuff' is done including...
write_TX_normal_FIFO();
...which may or may not be sending Zigbee data to the PC..

again, very very hard to figure out unless the 3 files are shown.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue May 14, 2013 6:08 am     Reply with quote

and the code is appalling.
What is the point of sitting in a loop continuously enabling an interrupt. Why is it ever turned off?. Then the 'form' suggests this has possibly been ported from another compiler, by someone who has little or no knowledge of CCS.
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