MRF24J40

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

MRF24J40

Post by Widgetman » Tue May 11, 2010 4:11 pm

Hi,
Has anyone tried to interface to the MRF24J40 2,4GHZ wireless module with the PIC 18 series parts using the swordfish compiler. I have a need to do this and was looking for some basic code to start from. Any thoughts or help would be appreciated.
Thanks

dmtulsa
Posts: 40
Joined: Fri Dec 21, 2007 1:38 pm
Location: Tulsa,OK
Contact:

Post by dmtulsa » Sun May 16, 2010 4:19 pm

Widgetman,

It would be nice if there was a library for it but for now there is not. I think someone here has gotten the MRF24J40 working with SF but has not made a library for it. I wish he would make a library (that's a lot to ask) or at least post some small sample of just sending and receiving a few bytes bytes. I am working on this using Proton PDS but it is slow going.

I would be very greatfull for a simple sample in SF or PDS since I have both. VERY GREATFULL

With the new MRF24J40MA or MB parts I think its going to be very popular since all the supporting hardware is on one small board now, its FCC & EU certified and the MA version is only $9 ea at Mouser or DigiKey

Thank You
Doug
Doug
kd5nwk

dmtulsa
Posts: 40
Joined: Fri Dec 21, 2007 1:38 pm
Location: Tulsa,OK
Contact:

Post by dmtulsa » Sun May 16, 2010 4:27 pm

Just a thought, if a library is made it would be great if it was the MiWi P2P version of Microchip's MiWi P2p stack. Yes I understand that is a lot of work and is not even needed if your just sending a few bytes from one device to another. The P2P protocol would be great if one was to network a few together.

For now all I want to do is send a few bytes.

Thank you
Doug

P.S. I'd be willing to pay for a MiWi P2P stack for SF or PDS
Doug
kd5nwk

dmtulsa
Posts: 40
Joined: Fri Dec 21, 2007 1:38 pm
Location: Tulsa,OK
Contact:

Post by dmtulsa » Sat May 29, 2010 5:06 pm

I'm working in it for Proton PDS. Its slow going but I'm 50% there. I can send you the code it you want when I'm done.

Doug
Doug
kd5nwk

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Thx Guys

Post by Widgetman » Sun May 30, 2010 1:20 pm

Hi,
That would be great DM if ya posted some code for us all after you are done. For now I am also going to work on getting the basics working for the P2P interface. Maybe between all of us we can stamp out a baseline for all to use.

dmtulsa
Posts: 40
Joined: Fri Dec 21, 2007 1:38 pm
Location: Tulsa,OK
Contact:

Post by dmtulsa » Sun May 30, 2010 2:32 pm

Widgetman,

Yes that's the goal !!! It doesn't really matter if its in SF, PDS or picBasic. Porting between them would be the easy part.

As I said I have it xmitting a packet header but I can't get it to send more, the payload (Data)

Code: Select all

'************LoadMessage***********************

LoadMessage:
  'txHeader =  TX_BUFFER_SIZE -1   set in initilize 126 = 127-1
 
  
   txRadioBuffer[txHeader] = 0xff 'AB                      'myShortAddress[1]
   Dec txHeader
   txRadioBuffer[txHeader] = 0xff 'CD                      'myShortAddress[0]  
   Dec txHeader
   txRadioBuffer[txHeader] = 0xff  >> 8                'networkTX.dext >> 8
   Dec txHeader
   txRadioBuffer[txHeader] = 0xff  & 0x00FF            'networkTX.dext & 0x00FF
   Dec txHeader
   txRadioBuffer[txHeader] = 0xff                      'myPANID[1]     
   Dec txHeader
   txRadioBuffer[txHeader] = 0xff                      'myPANID[0] 
   Dec txHeader
   txRadioBuffer[txHeader] = IEEEseqNumber             'IEEEseqNumber++ 
   Dec txHeader
   txRadioBuffer[txHeader] = FrameControl.HighByte     'framecontrol[1] 
   Dec txHeader
   txRadioBuffer[txHeader] = FrameControl.LowByte      'framecontrol[0] 
   Inc IEEEseqNumber
   

          
    'txHeader = 117   at this point
'Return
'****************SendMAC frame****************  
SendMACframe:

  'txPayLoad = 2 'if I set to anything > 0 it will not transmit
  'if txpayLoad = 0 It transmits and I see packets on the  Zena
  '// Compute and send header and frame length
  HeaderLength = TX_BUFFER_SIZE - 1 - txHeader    'headerLenght =126 - 117 (9) correct
  FrameLenght = HeaderLength + txPayLoad          'FrameLenght = 9 + 0 txPayload = 0 form Initialize 
  
  GoSub WriteLongRamAddress [0,HeaderLength]
  GoSub WriteLongRamAddress [1,FrameLenght]
  
  fifo = 2    '// FIFO write address after sending hrd & frm length

  '// Write the header to the FIFO
       While txHeader < HeaderLength '(TX_BUFFER_SIZE - 1)
          Inc txHeader  '++txHeader
          'writeLAR(fifo++, txRadioBuffer[++txHeader])
          GoSub WriteLongRamAddress [fifo,txRadioBuffer[txHeader]]
          Inc fifo  'fifo++
       Wend
       
       ' // Write the payload to the FIFO
       'for(j = 0; txPayload-- > 0; j++){
       '   writeLAR(fifo++, txRadioBuffer[j]);
     
           cnt=0
           While txPayLoad > 0 ' can't get here because txPayload = 0   
             GoSub WriteLongRamAddress [fifo,txRadioBuffer[cnt] ]
             Inc fifo
             Inc cnt
             Dec txPayLoad '= txPayLoad -1
             GoSub DisplayDebug [ "cnt", cnt]    
       Wend      
       
   '// Transmission acknowledgement request      
   'writeSAR(TXNCON,0x01);      
   GoSub WriteShortRamAddress [TXNCON, 0x01]     
         
Return  
If you look at the comments you can see that if txPayload > 0 it wont xmitt.

Next is Initialize routine

Code: Select all

Initialize:

  'do hardware reset
  Resetn = 0 'set reset low
  DelayMS 3
  Resetn = 1 'set reset high
  DelayMS 3
 
 'soft reset RF Module software
  GoSub WriteShortRamAddress [SOFTRST, 0x07]
 
'take out of reset RF Module
  bRetVal = 255
 While  (bRetVal & 0x07) != 0x00 
   
      GoSub ReadShortRamAddress [SOFTRST],bRetVal   'call read routine & return value
    '  'whats returned  ???  RS232 for debug
      GoSub DisplayDebug [ "Reset",bRetVal]
      Inc cnt
      If cnt = 5 Then Break
      
 Wend
 
  
 'Flush RX FIFO
  GoSub WriteShortRamAddress [RXFLUSH, 0x01]
 
 'Program short mac address, 0xffff
  GoSub WriteShortRamAddress [SADRL,0xff]
  GoSub WriteShortRamAddress [SADRH,0xff]
  GoSub WriteShortRamAddress [PANIDL,0xff]
  GoSub WriteShortRamAddress [PANIDH,0xff]
  
' /* Program Long MAC Address*/ 
  GoSub WriteShortRamAddress  [EADR0,0x4e] 'N
  GoSub WriteShortRamAddress  [EADR1,0x4f] 'O 
  GoSub WriteShortRamAddress  [EADR2,0x54] 'T 
  GoSub WriteShortRamAddress  [EADR3,0x42] 'B 
  GoSub WriteShortRamAddress  [EADR4,0x55] 'U 
  GoSub WriteShortRamAddress  [EADR5,0x53] 'S 
  GoSub WriteShortRamAddress  [EADR6,0x54] 'T 
  GoSub WriteShortRamAddress  [EADR7,0x4d] 'M    *****Need To change To slave  S
  
 
  GoSub WriteLongRamAddress [RFCON2,0x80]  '  PLL enabled

  GoSub WriteLongRamAddress [RFCON3,0x20]   ' -5 db power

  GoSub WriteLongRamAddress [RFCON6,0x90]  'Program RSSI ADC with 2.5mhz clock
  
  GoSub WriteLongRamAddress [RFCON7,0x80]  'sleep clock = 100khz internal
 
  GoSub WriteLongRamAddress [RFCON8,0x10]  ' enhanced VCO set
  
  GoSub WriteLongRamAddress [SLPCON0,0x01]  'disable sleep clock, int falling edge

  GoSub WriteLongRamAddress [SLPCON1,0x20]  'disable clock oout, divisor = 1

'***added 4-21*****  

'  GoSub WriteShortRamAddress [RXMCR, 0xa3]   'CRC Disable, ACK disable,no pan,no coordinator Error bit,no pkt discard*
 '***************

'/* Program CCA mode using RSSI */  
  GoSub WriteShortRamAddress [BBREG2,0x80]   'CCa mode using RSSI


'/* Program CCA mode using RSSI */  
  GoSub WriteShortRamAddress [BBREG6,0x40]   'Enable the packet RSSI

'/* Program CCA, RSSI threshold values */
  GoSub WriteShortRamAddress [CCAEDTH,0x60]   'set CCA, RSSI threshold values

  '?????????GoSub WriteLongRamAddress '[RFCTRL0,0x00]  'set channel 11
  
  GoSub WriteShortRamAddress [PACON2,0x98]   'enable FIFO, Set TXONTS = 6 (96uS)

  GoSub WriteShortRamAddress [TXSTBL,0x95]   'TX stabilixation book recommends 0x93

  bRetVal = 0x0 'clr return value
  cnt = 0

 While (bRetVal & 0xE0) != 0xA0
   
      GoSub ReadLongRamAddress  [RFSTATE],bRetVal   'read long address
      'whats returned  ???
       GoSub DisplayDebug ["RF State",bRetVal]
      Inc cnt
      If cnt = 5 Then Break
 
Wend

'continue2:
'  '*****configure transceiver interrupt control
  
  GoSub WriteShortRamAddress [INTCONT,0xF6]   'enable RX,TXN

  GoSub WriteLongRamAddress [RFCON1,0x01] 
   
  'set channel numbernot sure this is correct
  ' (((channel-11 << 4 ) | 0x02))
  channel =  ((6 << 4) | 0x02)
  GoSub WriteLongRamAddress [RFCON0,channel]  'set channel 17
  
  
 'reset RF Module
  GoSub WriteShortRamAddress [RFCTL, 0x04] 'reset
  DelayMS 1
 'take out of reset RF Module
  GoSub WriteShortRamAddress [RFCTL, 0x00]  'release reset
  DelayUS 200  'as per datasheet wait at least 192uS

  For i = 0 To TX_BUFFER_SIZE
      txRadioBuffer[i] = i '0x00   put in some data
  Next
  For i = 0 To RX_BUFFER_SIZE
      rxRadioBuffer[i] = 0x00
  Next
  
  txHeader =  TX_BUFFER_SIZE -1
  txPayLoad = 0
' // Enable RF Interrupt
'  RFIF = 0;
'  RFIE = 1;
'GIE = 1     'enable global int
'IPEN = 0    'disable high pri interupts
'INT2IP =0   'disable int2 high pri  not using priorty
'INT2IE = 1  'enable int2 portb.2
'INTEDG2 = 0 'rising
'IEEEseqNumber = 0
Return 
Doug
kd5nwk

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Thanks!!!

Post by Widgetman » Wed Jun 09, 2010 6:28 pm

Hi Doug,
Thanks a bunch for sharing. As soon as I get my design built I will play with what you have. It will be awesome to get this part working on the Swordfish compiler. The C stack Microchip provided seems like a lot of work to send simple data P2P. My particular application I am trying to build just needs to hop small packets between modules in a star topology. I am going to use a repeater to get me some distance.

dmtulsa
Posts: 40
Joined: Fri Dec 21, 2007 1:38 pm
Location: Tulsa,OK
Contact:

Post by dmtulsa » Thu Jun 10, 2010 10:49 pm

I have the transmit working correctly for the MRF24J40. I need to clean up the code then I'll post it. Next is the receive mode. If anyone wants to help let me know.

Widgetman, maybe when you get your design built you can do the Star part. Need auto channel selection and an addressing scheme, error checking ect :D :D

Doug
Doug
kd5nwk

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

MRF24J40 Debug

Post by Widgetman » Mon Jun 21, 2010 1:16 pm

Hi Doug,
I will try to help out as much as I can. let me know what you want me to cleanup or test or debug. I am still working on my design, but should be done in the next week or two.
Thanks
Widget

TonyR
Posts: 75
Joined: Fri Jan 14, 2011 11:49 pm
Location: Sydney
Contact:

MRF24J40 Zigbee Transmit Receive

Post by TonyR » Wed Jul 13, 2011 6:12 am

Good Afternoon All

Well I am about to design a small network which will use MRF24J40, and I hope to use SF and 18F87J50 sinceI know them now.

Has anyone had luck getting an MRF24J40 going with SF that could help?

I hope someone has, the datasheets look huge!

normnet
Posts: 55
Joined: Mon Jan 01, 2007 6:32 pm

Post by normnet » Thu Jul 14, 2011 11:04 pm

dmtulsa wrote:I have the transmit working correctly for the MRF24J40. I need to clean up the code then I'll post it. Next is the receive mode. If anyone wants to help let me know.
Doug
I have gotten Doug's code to work OK in Proton, both RX and TX!

Norm

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

MRF24J40 Code Available ?

Post by Widgetman » Tue Jul 19, 2011 2:10 pm

Hi All,
Is there a way to convert it to swordfish Norm ? I would like to play around with the MRF interface myself with some hobby farm ideas.
Thanks

normnet
Posts: 55
Joined: Mon Jan 01, 2007 6:32 pm

Re: MRF24J40 Code Available ?

Post by normnet » Tue Jul 19, 2011 8:55 pm

Widgetman wrote:Hi All,
Is there a way to convert it to swordfish Norm ? I would like to play around with the MRF interface myself with some hobby farm ideas.
Thanks
The code is Doug's, see Proton post at:
MRF24J40MA RF Chip

Norm

Post Reply