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

MRF24J40 Receiver

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



Joined: 03 Nov 2011
Posts: 8

View user's profile Send private message

MRF24J40 Receiver
PostPosted: Tue Nov 15, 2011 8:30 am     Reply with quote

I am working with the PIC 18F13K22 and the MRF 24J40. My compiler version is 4.114. I want to create a network where I can send data. The transmitter is working fine now. But I can't get the receiver running. I looked it up in the MRF data sheet where the reception is described.
The single steps are:

1. receive RXIF interrupt
2. disable host microcontroller interrupts
3. set RXDECINV =1 (in BBREG1) , disable receiving packets off air
4. read address 0x300
5. read RXFIFO
6. clear RXDECINV
7. Enable host microcontroller interrupts

I translated it like this:
Code:

void read_RX_FIFO()
{

   int i=0;
   SetShortRAMAddress(INTSTAT, 0b00001000);
   SetShortRAMAddress(INTCON, 0b00001000);
   SetShortRAMAddress(BBREG1, 0b00000100);
   SetShortRAMAddress(RXMCR, 0x01);
   SetShortRAMAddress(RXFLUSH, 0x00);
   for(i=0;i<128;i++)
   {
   data_RX_FIFO[i]=GetLongRAMAddress(address_RX_FIFO+i);
   }
   SetShortRAMAddress(BBREG1, 0x00);
   SetShortRAMAddress(INTCON, 0b00000000);


}


After I have called this function in the main loop. I debugged my code and recognized that it stops at this function, when I want to read out RX Fifo. The program stucked in the GetLongRAMAddress function.

Code:

int8 GetLongRAMAddress(int16 address)
{
   int8 toReturn;
   output_low(MRF24J40_CS);
   spi_write(((address>>3) & 0b01111111)| 0x80);
   spi_write(((address<<5) & 0b11100000));          //stops at this position

   toReturn = spi_read(0); 
 
   output_high(MRF24J40_CS);
   return(toReturn);
}


I thought that this should be right. Would be glad if anyone could help me.
temtronic



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

View user's profile Send private message

PostPosted: Tue Nov 15, 2011 8:38 am     Reply with quote

I don't use that device but have you manually( pen and paper) done the math to confirm that your computed spi_write(address..) is valid ?

Perhaps hard coding a 'good address' will confirm this ???
jogibaer



Joined: 03 Nov 2011
Posts: 8

View user's profile Send private message

PostPosted: Tue Nov 15, 2011 3:12 pm     Reply with quote

I also looked this function up in some other codes, for example the MRF24J40 Radio Driver. I think this should be right, because it is already working with my transmitter.

What do you mean by a 'good address'?
jogibaer



Joined: 03 Nov 2011
Posts: 8

View user's profile Send private message

PostPosted: Thu Nov 17, 2011 10:43 am     Reply with quote

I made some test and found out that the program don't stop at the Get function. I read the received values with my logic analyzer and saw strange and continuously repeating values. I have absolutely no idea what is the problem with this code. I also included in the main loop an if condition. When the data contains my value, one led should flash. otherwise another led should flash. Even if I don't transmit anything I still have a flashing led and get values in the logic analyzer. Is this still a problem of the RX buffer?
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Nov 19, 2011 12:44 pm     Reply with quote

I can read the received packet data I'm in the middle of this today.
The issue is that absent my unfinished logic of deciphering the header length I'm using fixed values not those obtained from the on air packet. I'm almost there

Code:

void read_RX_normal_FIFO(void)
{
unsigned int8 i,frame_size,frame_control;
 
   SetShortRAMAddress(INTSTAT, 0b00001000);
   SetShortRAMAddress(INTCON, 0b00001000);
   SetShortRAMAddress(BBREG1, 0b00000100);
   SetShortRAMAddress(RXMCR, 0x01);
   SetShortRAMAddress(RXFLUSH, 0x00);
   //// first byte is the frame length
   frame_size=GetLongRAMAddress(address_RX_normal_FIFO);
   
  /// next byte is the frame control ex 0xc841
  /// we will use it to get the header length
  /// Notes sure electronics uses 0xc841 and destination address of0xffff             
  /// ex 0xc841 0b 11      00    10   000100 0  001
  ///              |--------|    |+++++||--| |++++|
  ///               c              8      4      1
  ///           11   xx       10   xxx#xx x  001
  ///           long          short         data
  ///           source        destination       
   frame_control=GetLongRAMAddress(address_RX_normal_FIFO+1);
 
   for(i=0;i<(HEADER_LENGTH+DATA_LENGTH+2);i++)
   {
   data_RX_normal_FIFO[i]=GetLongRAMAddress(address_RX_normal_FIFO+i);
   }
   SetShortRAMAddress(BBREG1, 0x00);
   SetShortRAMAddress(INTCON, 0b00000000);
 ///// transfer payload to RX_DATA
  for(i=0;i<DATA_LENGTH;i++)
   DATA_RX[i]=data_RX_normal_FIFO[i+(HEADER_LENGTH+4-1)];
}
jogibaer



Joined: 03 Nov 2011
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 21, 2011 8:07 am     Reply with quote

First thank you for your code.
Very Happy
I tried to compile it, bur there is not enough for all the variables. You said that you are also working with CCS. Is that right? How can you make a printf output? It is not possible in my version.
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