Tags:
create new tag
, view all tags
Unless the Smart Packet Radio is sending a packet, the firmware ensures that it is in a state waiting to receive a packet from another device. There are two functions which facilitate the reception of a packet, the first being rx_mode:

 *void rx_mode(void)*  
| *{*  |
| *write(0x07, 0x01); //To ready mode*  |
| *cbi(PORTC, TXANT); //Clears TXANT*  |
| *sbi(PORTC, RXANT); //Sets RXANT*  |
| *write(0x07, 0x01); //To ready mode*  |
| *write(0x08, 0x03); //Clears FIFO*  |
| *write(0x08, 0x00); //Resets FIFO*  |
| *write(0x05, 0x02); //Enables packet received interrupt*  |
| *write(0x06, 0x00);*  |
| *rx_mode_enabled = true; //Flag used to identify source of interrupt*  |
| *write(0x07, 0x05); //Places RFM22B in RX mode*  |
| *}*  |
Firstly, the above function sets the antenna to be used for receiving and resets the FIFO on the transceiver module. It then enables an interrupt that will notify the microcontroller when a valid packet has been received and also sets a flag which will help the ISR identify which interrupt has caused the interrupt service routine to be initiated. The microcontroller then sends the command that places the transceiver into receive mode.

When the device receives a valid packet, and interrupt is triggered and the interrupt service routine is initiated which sets the IRQ flag and reads the interrupt status registers. Once the microcontroller determines that the interrupt was triggered due to a valid packet being received, the following events occur:

  • The transceiver is taken out of receive mode.
  • The RX LED is turned on and a timer is started which will turn it off after an arbitrary amount of time.
  • The receive function is called.
  • The received packet is sent to the host byte by byte via USB.
  • The rx_mode function is called and the device waits for another valid packet.
The following code is the receive function:

int receive(unsigned char *rx_buffer))
{
unsigned char i;
int receive_packet_length = read(0x4B);
for(i=0; i<receive_packet_length; i++)
{
rx_buffer[i] = read(0x7F);
}
return receive_packet_length;
}

The receive function first reads the packet length from the transceiver module and then proceeds to read the received packet from the FIFO on board the module and returns the length of the packet received.

-- XiaohongWu - 2012-01-30

Topic revision: r3 - 2012-09-02 - AhmetSekercioglu
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback