ATMega128RFA1 Data transmission without bitcloud

Go To Last Post
34 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using Bitcloud for a few zigbee applications at the moment, however, I am wondering how to use the ATMega 128RFA1 without bitcloud.

What I want to know, is how to set up the device to transmit a packet of data, and how to set it up to recieve a packet addressed to it.

I still intend on using the PANID to filter only the desired packets.

Has anyone done basic communications with this chip?

I have a network sniffer for detecting the packets that I transmit (AVR Raven Dev Kit)

Thanks

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

Last Edited: Fri. Oct 16, 2015 - 12:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Source code to receive and transmit arbitrary frames is pretty simple. I can send you my test code that I use, it is not clean, but works.

But sending data frames in ZigBee format is not really enough. You need to send and receive whole bunch of command frames, like link status, route requests and responses, etc. Do you plan to support this also? Otherwise why implement bloated ZigBee instead of own simple protocol?

ZigBee is based on MAC layer, do you plan to implement it yourself also?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex
I have no interest in rewriting zigbee :) what I am thinking...
I am using serialnet for all routers, this works...
but for end devices, I want something much simpler, I do not need the overhead of Zigbee for just a point to point sensor, like a flow meter or a gate switch, these are simple devices in reality.
so on my routers, I will have a serialnet node, connected to a AT128RFA1 that will run all of my applications, this will also be able to act as a gateway for the simple end devices.
so I will not need any complex logic, (I don't think anyway :) )

This also means that I can run serialnet mostly unmodified for all of my routers.
The code would be much appreciated.

Thanks
Philip

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

proficnc wrote:
so I will not need any complex logic, (I don't think anyway :) )
You'll still need to handle network joining and leaving. I'd say this is a lot of code to re-implement and debug. You'll need MAC layer fully implemented at least, otherwise you'll end up with hell of inconsistent delays.

Found code at home, see attachment. This code does not pretend to demonstrate good coding practices, it was written to test some bug long ago. You need to define DEVICE (0 or 1, one receiving and one transmitting). Setting BASIC to 1 allows you to use basic operating mode (extended with BASIC = 0).

Attachment(s): 

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That looks good, I will set it up to send some data to a sniffer. (I now have the AVR Raven kit, which is really good to help solve problems due the the sniffer function)

I plan to run these sections seperatly to the Bitcloud network, on another channel. so it will be a fixed co-ordinator, and up to 16 end stations.
co-ordinator will wait for a node to wake up and listen for a command from the co-ordinator to talk, send it it's current state, the co-ordinator will send it any new data it needs, then tell it to go to sleep.

it will comunicate in a peer to peer way just to the co-ordinator, with no routers, then the co-ordinator will send it's data via UART to the zigbit module running serialnet over the real zigbee network.
so, no network joining or leaving, the system will just assume that all stations are there, and any that happen to report in will have there data sent to the real zigbee network.

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks alexru!

I've been having trouble getting this thing to transmit and the fact that your code works on it is encouraging :)

now to figure out where I went wrong... which doesn't appear to be easy... :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alexru
Is there a file "atmega128rfa1.h" that I need with this?
thanks

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

proficnc wrote:
Is there a file "atmega128rfa1.h" that I need with this?
It should be in WinAVR distributive.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
It should be in WinAVR distributive.
I'm wrong here. It is a custom made file. It is from closed source part of BitCloud, but it seems like the only lines needed from there are:

#define REG_TRX_STATUS_TRX_STATUS_MASK 0x1F
#define TRX_FRAME_BUFFER(index) (*(volatile uint8_t *)(0x180 + (index)))

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex
Also these Items are undeclared

TRX_CMD_PLL_ON
TRX_CMD_TX_ARET_ON
TRX_CMD_TRX_OFF
TRX_CMD_RX_AACK_ON

TRXPR_struct._trxrst
CSMA_SEED_1_struct._aack_set_pd
CSMA_SEED_1_struct._aack_dis_ack
IRQ_STATUS_CLEAR_VALUE
IRQ_MASK_struct._rx_end_en
PHY_CC_CCA_struct._channel
TRX_CTRL_2_struct._rx_safe_mode

Thanks
Philip

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

proficnc wrote:
Also these Items are undeclared

TRX cmds are:

#define TRX_CMD_NOP                         0
#define TRX_CMD_TX_START                    2
#define TRX_CMD_FORCE_TRX_OFF               3
#define TRX_CMD_FORCE_PLL_ON                4
#define TRX_CMD_RX_ON                       6
#define TRX_CMD_TRX_OFF                     8
#define TRX_CMD_PLL_ON                      9
#define TRX_CMD_RX_AACK_ON                  22
#define TRX_CMD_TX_ARET_ON                  25

And structures should be defined in WinAVR\avr\include\avr\iom128rfa1.h WinAVR header file.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Makefile I used:

MCU=atmega128rfa1
DMCU=__AVR_ATmega128RFA1__
LINK=-Wl,--section-start=.data=0x800200 
CC=C:/WinAVR/bin/avr-gcc.exe

all:
	$(CC) -g -O3 -D$(DMCU) -DDEVICE=$(DEVICE) -c test.c -o test.o
	$(CC) -g -Wl,--gc-sections -mmcu=$(MCU) $(LINK) test.o -o test.elf

But it was early version of WinAVR with megaRF support, so defineing internal defines should not be needed now. I don't really remember why I used it.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex
ok, just one error now
IRQ_STATUS_CLEAR_VALUE
not defined

the previous definitions have changed in the WinAVR header.
they were

TRXPR_struct._trxrst 
CSMA_SEED_1_struct._aack_set_pd 
CSMA_SEED_1_struct._aack_dis_ack 
IRQ_MASK_struct._rx_end_en 
PHY_CC_CCA_struct._channel 
TRX_CTRL_2_struct._rx_safe_mode 

but now must be

TRXPR_struct.trxrst 
CSMA_SEED_1_struct.aack_set_pd 
CSMA_SEED_1_struct.aack_dis_ack  
IRQ_MASK_struct.rx_end_en 
PHY_CC_CCA_struct.channel 
TRX_CTRL_2_struct.rx_safe_mode 

thanks

Philip

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All working
I ran this and looked at the output with the network sniffer. works perfectly.

I set IRQ_STATUS_CLEAR_VALUE to = 0
seems to work, I don't know what it's correct value is
thankyou.

now I will purchase a second 128 so I can test two way communication :)
Thanks

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

modified working code
sends number 5 as the payload

Thanks Alex

#include 
#include 
#define REG_TRX_STATUS_TRX_STATUS_MASK 0x1F 
#define TRX_FRAME_BUFFER(index) (*(volatile uint8_t *)(0x180 + (index))) 

//#define DEVICE 0
#define DEVICE 1

#define BASIC 0

#define PANID (0x1234)
#define SADDR DEVICE
#define EADDR (0xaabbccdd00000000LL | SADDR)
#define TRX_CMD_NOP                         0 
#define TRX_CMD_TX_START                    2 
#define TRX_CMD_FORCE_TRX_OFF               3 
#define TRX_CMD_FORCE_PLL_ON                4 
#define TRX_CMD_RX_ON                       6 
#define TRX_CMD_TRX_OFF                     8 
#define TRX_CMD_PLL_ON                      9 
#define TRX_CMD_RX_AACK_ON                  22 
#define TRX_CMD_TX_ARET_ON                  25 
#define IRQ_STATUS_CLEAR_VALUE              0xff




//
// Types
//
typedef struct
{
  uint8_t phr;
  uint16_t fcf;
  uint8_t seq;
  uint16_t dpan;
  uint16_t daddr;
  uint16_t saddr;
  uint8_t data;
  uint16_t crc;
} Frame_t;

//
// Variables
//
uint8_t txCnt = 0;
uint8_t payload = 5;

volatile int rxReceived = 0;
volatile uint8_t rxPayload;

volatile int txWaitInt = 0;

//
// Functions
//
void infBlink(void)
{
  long i;

  cli();
  PORTE = 0;
  while (1)
  {
    PORTE ^= 0xff;
    for (i = 0; i< 20000; i++)
      asm("nop");
  }
}

void setState(uint8_t state)
{
  TRX_STATE = CMD_FORCE_TRX_OFF;
  TRX_STATE = state;
  while (state != (TRX_STATUS & REG_TRX_STATUS_TRX_STATUS_MASK));
}

void sendFrame(uint8_t payload)
{
  int i;
  Frame_t frame;

#if BASIC
  setState(TRX_CMD_PLL_ON);
#else
  setState(TRX_CMD_TX_ARET_ON);
#endif

  frame.phr = sizeof(Frame_t)-1;
  frame.fcf = (1 << 0) /*data*/ | (1<<5) /*ackReq*/ | (1<<6) /*panIdComp*/ | (2<<10) /*dstAddrMode*/ | (2<<14) /*srcAddrMode*/;
  frame.dpan = PANID;
  frame.saddr = SADDR;
  frame.daddr = 1-SADDR;
  frame.seq = txCnt++;
  frame.data = payload;

  for (i = 0; i < sizeof(Frame_t); i++)
    TRX_FRAME_BUFFER(i) = ((uint8_t *)&frame)[i];

  txWaitInt = 1;
  TRX_STATE = CMD_TX_START;
}

ISR(TRX24_RX_END_vect)
{
  setState(TRX_CMD_PLL_ON);

  PORTE ^= (1<<3);

  rxPayload = TRX_FRAME_BUFFER(9);
  rxReceived = 1;
}

ISR(TRX24_TX_END_vect)
{
  PORTE ^= (1<<2);

  if (txWaitInt)
    txWaitInt = 0;
  else
    infBlink();
}

void rfInit(void)
{
  TRXPR_struct.trxrst = 1;

  setState(TRX_CMD_TRX_OFF);

  CSMA_SEED_1_struct.aack_set_pd = 1;
  CSMA_SEED_1_struct.aack_dis_ack = 0;

  IRQ_STATUS = IRQ_STATUS_CLEAR_VALUE;
  IRQ_MASK_struct.rx_end_en = 1;
  IRQ_MASK_struct.tx_end_en = 1;
  sei();

  PHY_CC_CCA_struct.channel = 0x0b;
  TRX_CTRL_2_struct.rx_safe_mode = 1;

  CSMA_SEED_0 = (uint8_t)SADDR;

  {
    uint16_t vPanId = PANID;
    uint8_t *panId = (uint8_t *)&vPanId;
    PAN_ID_0 = panId[0];
    PAN_ID_1 = panId[1];
  }

  {
    uint16_t vShortAddr = SADDR;
    uint8_t *shortAddr = (uint8_t *)&vShortAddr;
    SHORT_ADDR_0 = shortAddr[0];
    SHORT_ADDR_1 = shortAddr[1];
  }

  {
    uint64_t vExtAddr = EADDR;
    uint8_t *extAddr = (uint8_t *)&vExtAddr;
    IEEE_ADDR_0 = extAddr[0];
    IEEE_ADDR_1 = extAddr[1];
    IEEE_ADDR_2 = extAddr[2];
    IEEE_ADDR_3 = extAddr[3];
    IEEE_ADDR_4 = extAddr[4];
    IEEE_ADDR_5 = extAddr[5];
    IEEE_ADDR_6 = extAddr[6];
    IEEE_ADDR_7 = extAddr[7];
  }
}

int main()
{
  long i;

  DDRE = 0xff;
  PORTE = 0xff;

  rfInit();

#if DEVICE == 0
  #if BASIC
    setState(TRX_CMD_RX_ON);
  #else
    setState(TRX_CMD_RX_AACK_ON);
  #endif

  while (1)
  {
    // Wait for frames
    if (rxReceived)
    {
      for (i = 0; i < 10000; i++) // Wait a bit
        asm("nop");

      rxReceived = 0;
      sendFrame(rxPayload);

      while (txWaitInt)
        asm("nop");

      #if BASIC
        setState(TRX_CMD_RX_ON);
      #else
        setState(TRX_CMD_RX_AACK_ON);
      #endif
    }
  }
#endif

#if DEVICE == 1
  while (1)
  {
    for (i = 0; i < 1000000; i++)
      asm("nop");

    // Send frame
    sendFrame(payload);
    while (txWaitInt)
      asm("nop");

    // Wait for response
    rxReceived = 0;
    #if BASIC
      setState(TRX_CMD_RX_ON);
    #else
      setState(TRX_CMD_RX_AACK_ON);
    #endif

    for (i = 0; i < 1000000; i++)
    {
      if (rxReceived)
      {
        if (payload == rxPayload)
          payload++;
        else
          infBlink();
        break;
      }
    }
  }
#endif

  while (1);

  return 0;
}

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

Last Edited: Tue. Mar 1, 2011 - 11:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

proficnc wrote:
I set IRQ_STATUS_CLEAR_VALUE to = 0
seems to work, I don't know what it's correct value is

Correct value is 0xff, IRQ flags are cleared by writing 1 to them.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks, will fix this

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in this code transmission done is checked through tx end interrupt how do i do it by polling method will anyone please send the code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have not checked it, but it would look something like this:

IRQ_MASK_struct.tx_end_en = 0; // in the rfInit()
...
sendFrame(rxPayload);
while (0 == IRQ_STATUS_REG_s.txEnd);
IRQ_STATUS_REG_s.txEnd = 1; // clear interrupt flag

Why do you need this?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am working on a wireless boot loader this code is placed in the bootloader section so i want tx/rx interrupt free

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
I have not checked it, but it would look something like this:

IRQ_MASK_struct.tx_end_en = 0; // in the rfInit()
...
sendFrame(rxPayload);
while (0 == IRQ_STATUS_REG_s.txEnd);
IRQ_STATUS_REG_s.txEnd = 1; // clear interrupt flag

Why do you need this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks this is working

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to enable CRC calculation in this code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is already enabled if you have "#define BASIC 0".

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I am using ATmega128RFA1 controller to establish a mesh network. can i establish a mesh network using this code?.can anyone suggest the method to assign a node as coordinator and router.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, this code can not establish a mesh network, no 100-lines of code can.

Have a look at Lightweight Mesh, it is the easiest way to get a mesh network.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in this code can we receive encrypted frames and perform decryption,i have referred the data sheet but i am not clear on how to implement

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This code is the most basic code for sending and receiving data. What data you put into it is up to you - if you encrypt it, then it will be encrypted.

Again, LwMesh does implement encryption.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to use lightweight mesh to implement a co-ordinator ,router and end-device for 128rfa1.I found some code related to lightweight mesh in atmel website.But i am not sure on how to implement it on 128rfa1 evaluation board.I am using avr studio 4.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Download the LwMesh bundle.

In e.g. the subfolder ...\apps\Template\make you will find makefiles for different boards and controller/transceiver models.

And in the subfolder F...\apps\Template\astudio you will find Atmel Studio 6 projects for different boards and controller/transceiver models.

Similar arrangements are present in the other applications, e.g. Peer2Peer - which I found to be a good thing to study when I began tinkering with LwMesh.

You really should read the documentation. It holds e.g. this passage:

Quote:
Applications are located in the apps directory in the SDK. All sample applications in the Lightweight Mesh SDK come with the project files for Atmel Studio, IAR Embedded Workbench and GNU make utility.

Quote:
I am using avr studio 4.

My advice would be: Switch to Atmel Studio 6.1. (Is AVR Studio 4 at all supproting ATmega28RFA1??)

Also:

Quote:
I want to use lightweight mesh to implement a co-ordinator ,router and end-device for 128rfa1.

Once again, looking in the documentation you will find

Quote:
All demonstrations in this document will use the RCB128RFA1 board [3] and the WSNDemo sample application as an example

and
Quote:
The WSNDemo application implements a typical wireless sensor network scenario, in which one central node collects the data from a network of sensors and passes this data over a serial connection for further processing. In the case of the WSNDemo this processing is performed by the WSNMonitor PC application. The BitCloud® Quick Start Guide [2] provides a detailed description of the WSNDemo application scenario, and instructions on how to use WSNMonitor.
The majority of the information in [2] applies to the WSNDemo application running on top of Lightweight Mesh stack. However since BitCloud is a ZigBee® PRO stack, there are a few differences in the protocol:
• Device types (Coordinator, Router and End Device) are simulated on the application level; there is no such separation in Lightweight Mesh on the stack level
[...]

So it seems that the LwMesh WSNDemo might be worth a study.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everybody.. I see the code and it sets PAN_ID, SHORT_ADD, and EXT_ADD but uses TRX24_RX_END to read the receive data so I think that is a broadcast transmission because it doesn`t use TRX24_XAH_AMI interrupt for frame filtering. I do need a point to point interface beteween two Atmega128RFA1 using and addressing match procedure, someone can help me?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TRX24_XAH_AMI is asserted when address has matched, but frame reception is still in progress. You don't need this 99.999% of the time.

 

TRX24_RX_END is asserted when frame reception is complete. If frame has matched filtering or not depends on the state machine state (basic or advanced mode).

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im confused so it will be better if i explain my project. I need to make a point to point comunication so I don`t need a net layer like ZigBee . Instead I use IEEE 802.15.4 and two Atmega128RFA1. I can make a simple program using RX_ON state and don't configurate any address (PAIN_ID,SHORT_ADR,EXT_ADR) and it works, Why it works? because im on RX_ON state and it receive all the SFD frames compatible with 802.15.4?

So I need a point to point comunication using unique addresses for both MCU. As i understand what you say to me is that if i need a frame filtering i have to use de advanced mode although in bsic mode have TRX24_XAH_AMI interrupt?

Thanks a lot

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Forget about TRX24_XAH_AMI, you don't need it, believe me.

 

If you want automatic filtering to happen, use advanced mode and configure the address in the chip, otherwise use basic mode and do manual filtering. For two node network there is reallt no difference.

 

Also note that for automatic filtering to work you need to have MAC header formatted according to IEEE 802.15.4. In manual mode, it does not matter how you format your frame.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

Last Edited: Sat. Oct 4, 2014 - 06:08 PM