Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F4550 to MRF24J40MA

Status
Not open for further replies.

abhisheksaini

Newbie level 2
Joined
Apr 3, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
Hi,

I am want to use PIC18F4550 to send data to MRF24J40MA ( just a simple P2P connection).

Here is my hardware schematic which just shows connections between the PIC uController and the ZigBee module. I am using 20MHz crystal as my PIC will talk to USB of a computer.

Hardware:

circj.png




For now I just want to send some text message from PIC to ZigBee module. Here is the code I developed/got from MiWi datasheet.
Code:
//The following is code is based on the Flow Chart (Page 28) of MiWi Datasheet.
void main(void)
{
	Initiazation();//Initialize hardware platform and P2P stack
	SetChannel(myChannel);//set the channel to operate
	
	EnableNewConnection();//accept new P2P connection
	
	CreateNewConnection(2);//establish a connection with another device
	
	while (1)
	{
		if(ReceivedPacket())//check if a packet has been received
		{
			LED_1 = rxFrame.PayLoad[0]; //processing the packet, setting the LED according to received packet
			
			
			DiscardPacket();//discard the packet to ready to recieve the next
		}
		else
		{
		
			BYTE PressedButton = ButtonPressed(); //check if a button pressed
			
			if(PressedButton) //if a button has been pressed
			{
			
			
				//All the lines below demonstrate a method of transmitting 
				//a packet.
				
				
				FlushTx(); //reset the transmitting buffer
				
				for(i=0;i<65;i++)
				{
				
					//The function call, WriteData, will fill the transmitter
					//buffer one byte at a time. If there are 20 bytes to be
					//transmitted in the packet, the function will be called
					//20 times.
					WriteData(P2P[i]);//fill the transmitting buffer
				}
				
				
				//The line below uses the method of unicast with an index of 
				//connections through the function UnicastConnection
				UnicastConnection(0,FALSE,TRUE);//unicast sends data
				
				
			}
		}
	}
	
	
}

I believe that the above is is developed to be used on some sort of demo board. In my hardware schematic...there is not LED indicator or button so far.
Regarding the code above I have few questions:
1) In the line
Code:
SetChannel(myChannel);//set the channel to operate
we can specify any channel from 11-26. Lets say I want to set channel 12. Do I just write the DWORD instead of myChannel..like b'0000 0000 0000 0000 0000 1000 0000 0000?

2) In the code
Code:
LED_1 = rxFrame.PayLoad[0]; //processing the packet, setting the LED according to received packet
we process the packet and also light the LED accordingly. What exactly is happening to LED at this point? Is tt just lighting when the packet is being transmitted? If I do now want LED to function, can I just process the packet by just saying...
Code:
rxFrame.PayLoad[0];
?

3) In the code
Code:
if(PressedButton) //if a button has been pressed
....pressing the button means "Send the packet"?. In my hardware there is not button, so should I just get rid of this if statement for now and send the packet cont. I think that would work.

4) In the code, why the for loop is running 65 times? Do we need this for loop? In the line
Code:
WriteData(P2P[i]);
are just filling the buffer with 0,1, 2, 3, 4,...65; Cant I just put some text message in the bugger to transfer.

5) In the code,
Code:
UnicastConnection(0,FALSE,TRUE);//unicast sends data
0 is the connection index, FALSE tells if the packet is the command packet, and TRUE tells if the encryption is required. Why there should be 0 for the connection index and since I intend to use no encryption can I have FALSE instead of TRUE?

=> To run the above code should I use libraries etc from the MiWi stack located in
Code:
C:\Microchip Solutions\P2P\P2P Node 1
?


thanks for your time!

- Abhishek Saini
 

Ahmed.Egypt

Newbie level 1
Joined
Apr 3, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top