Atmel transceiver (RF212B) communication using microcontroller SAM D21 - Page 1
Forum section: electronics / general

author: CharvRastogi
author_rank: Newbie
timestamp: March 13, 2016, 11:26:04 am
content: Hello,I am working on a project to implement communication between two Atmel transceiver (AT86RF212B) boards, I am programming the boards using spi interface between them and SAM D21 (microcontroller). I am able to send and receive data using the LWmesh peer2peer sample project given by Atmel studio 7. But the issue is the data received and the data sent are not the same, the code somehow changes the data entirely. I am using a hyper terminal to send and look at the received data.Could you please tell me why am I not receiving the correct data? Could it be the encryption scheme that is in-built in Atmel (AES)?Thank you.Link to the preface of the sample project -http://asf.atmel.com/docs/latest/thirdparty.wireless.avr2130_lwmesh.apps.peer2peer.sam4lc4c_reb233_xpro/html/index.html(Note - this project is also available for the devices I have mentioned above)

author: ataradov
author_rank: Super Contributor
timestamp: March 13, 2016, 08:43:28 pm
content: Quote from: CharvRastogi on March 13, 2016, 11:26:04 amIt is highly likely that you have problems with UART baudrate mismatch. Have you verified your data inside the sending device (using debugger or otherwise)?AES can be used but mismatch of security settings will be detected by the stack and invalid frames will be discarded.PS: There is no need to cross post.

author: CharvRastogi
author_rank: Newbie
timestamp: March 14, 2016, 06:54:11 am
content: Thank you! I was using the configured Baudrate between the microcontroller and the transceiver instead of the USART host baudrate.The data is sent correctly now.I had another doubt. I was trying to locate the exact point in the code that is used to send the data to the transceiver from SAM D21 using breakpoints and by hard coding the values, but I could not succeed. The code seems to involve many underlying protocols. Is it the sio2host subprogram? Hard coding the output didn't help here either. Would you have some light to shed on this?PS: Sorry about the cross posting.

author: ataradov
author_rank: Super Contributor
timestamp: March 14, 2016, 06:58:49 am
content: Quote from: CharvRastogi on March 14, 2016, 06:54:11 amMy original code is much simpler and easier to understand. You can look at standalone version of LwMesh herehttp://www.atmel.com/tools/lightweight_mesh.aspx. The actual communication with the radio happens in the PHY layer, specifically phy.c file and PHY_DataReq() function. In the standalone version it calls HAL SPI access functions directly. In the ASF version it goes through more layers.sio2host is a serial communication part, it is not related to the radio in any way.

author: CharvRastogi
author_rank: Newbie
timestamp: March 14, 2016, 08:12:07 pm
content: Please correct me if I am wrong,1. the function AppSendData() in the main program file (Peer2Peer.c) is used to send the data via the transceiver to the other transceiver at the receiving end.2. the function appDataInd prints the data received from the radio on the host PC through UART.How is the role of transmission divided between appSendData() and phy_datareq(). PHY_datareq seems to use the frame created in the nwk_tx.c program file, so I am assuming this is the frame that needs to be transmitted by the transceiver finally?To hard code the output we implemented this method -I, basically, hard coded the value of rx_data and fed it to both appsenddata() and sio2host_putchar(), and I expected this to print the data on the transmitting pc terminal (which it did) but it was not received by the receiving pc. Does this mean we would have to edit the frame_tx that I mentioned above in nkw_tx to alter the data being sent over the radio?MY CODE -int count;static void APP_TaskHandler(void){switch (appState) {case APP_STATE_INITIAL:{appInit();appState = APP_STATE_IDLE;}break;case APP_STATE_IDLE:break;default:break;}count++;if(count%20001==1){count=1;}if(count%20000==19999){sio_rx_length = 5;for (uint16_t i = 0; i < sio_rx_length; i++) {rx_data=('A'+i); //put A,B,C}rx_data=0x00;//sio_rx_length = sio2host_rx(rx_data, APP_RX_BUF_SIZE); //until buffer is filled, 0 is returned. Buffer size is 20 bytes, defined in config.hif (sio_rx_length) {for (uint16_t i = 0; i < sio_rx_length; i++) {sio2host_putchar(rx_data); //Echo back on the tx pcif (appUartBufferPtr == sizeof(appUartBuffer)) //Send the packet when the buffer is full{appSendData();}if (appUartBufferPtr < sizeof(appUartBuffer)) //Append to the packet to be sent, the size of which is sizeof(appUartBuffer){appUartBuffer[appUartBufferPtr++] = rx_data;}}SYS_TimerStop(&appTimer);SYS_TimerStart(&appTimer);}

author: ataradov
author_rank: Super Contributor
timestamp: March 14, 2016, 09:06:47 pm
content: Quote from: CharvRastogi on March 14, 2016, 08:12:07 pmThat's the high-level idea.Quote from: CharvRastogi on March 14, 2016, 08:12:07 pmappDataInd() is the callback that is called when data is received.Quote from: CharvRastogi on March 14, 2016, 08:12:07 pmappSendData() is an application level function. It was convenient to implement it this way for this application, but you are expected to change things depending on your application needs. NWK_DataReq() is the ultimate stack API.The rest of the functions add necessary headers and figure out how to route the frame before it is physically sent using PHY_DataReq().Quote from: CharvRastogi on March 14, 2016, 08:12:07 pmYou really need to properly design your application, don't just adopt to Peer2Peer. Look at SimpleRemote, for example. It has a very simple and clean implementation of just the wireless part.

author: kavita
author_rank: Contributor
timestamp: April 07, 2016, 12:40:17 pm
content: HII am using atmel AT86RF233 1 C. For the testing purpose can i only transmit only one array with using only using physical layer i mean one end to another end without using stack.

author: ataradov
author_rank: Super Contributor
timestamp: April 07, 2016, 03:47:06 pm
content: Quote from: kavita on April 07, 2016, 12:40:17 pmSure. Just use the code from phy.c from LwMesh. That's the lowest level PHY driver. You will need do to at least PHY_Init() and use PHY_DataReq() to send the data.

author: kavita
author_rank: Contributor
timestamp: April 08, 2016, 07:43:51 am
content: HIThis is my source code .I am able to read write registers and frame buffer, DIG3 LED is turned on .In this if any data is transmitted from UART data is written in frsme buffer. By transmitting interrupt register shows TX_END.and DIG4 blinks slidely but DIG3 is not turned off.i dont know what is happening because at receiving end i am not able to receive data.

author: ataradov
author_rank: Super Contributor
timestamp: April 08, 2016, 05:46:24 pm
content: There is a number of issues I see with this code.1. You never actually wait for completion of the frame transfer.2. You are using advanced TX mode, but you never configure the address/PAN_ID and your payload does not match standard format, which radio expects in the advanced mode. You are receiving in the basic mode, so the frame will be received, but TX will fail, and you need to check the status code.3. You never set a channel.

author: kavita
author_rank: Contributor
timestamp: April 09, 2016, 05:25:34 am
content: thank you..can you please tell me what kind of changes i have to do in this....I have to set channel ,PAN ID?

author: ataradov
author_rank: Super Contributor
timestamp: April 09, 2016, 05:32:33 am
content: For basic mode you only need to set channel.And then transmit without ARET.

author: ataradov
author_rank: Super Contributor
timestamp: April 09, 2016, 06:15:43 am
content: Quote from: kavita on April 09, 2016, 05:40:58 amThere is no CRC value, but you need to set frame size including CRC size (2 bytes). With the auto CRC the radio will put it there automatically.

author: kavita
author_rank: Contributor
timestamp: April 09, 2016, 10:39:45 am
content: this is my new code i have set channel and PAN ID.IS this ok?by doing his DIG3 blinks slidely..

author: kavita
author_rank: Contributor
timestamp: April 09, 2016, 01:03:16 pm
content: HEYI have successfully done it.thank you so much.can you please tell me if I want to use extended operating mode which additional setting I have to do for this.

author: ataradov
author_rank: Super Contributor
timestamp: April 09, 2016, 08:37:02 pm
content: Quote from: kavita on April 09, 2016, 01:03:16 pmUse states that correspond to the advanced mode. Just like LwMesh does.In addition to this you will need to make sure that the header of your payload is formatted in accordance with IEEE802.15.4.

author: kavita
author_rank: Contributor
timestamp: April 11, 2016, 05:57:32 am
content: hiAs mentioned in data sheet that when device in tx mode,DIG4 blinks and DIG3 will turn off but in my case it is not happening.can you please tell me what is the problem.I have checked all connections and hardware is ok.

author: ataradov
author_rank: Super Contributor
timestamp: April 11, 2016, 05:58:54 am
content: Quote from: kavita on April 11, 2016, 05:57:32 amHave you actually enabled them? Read the datasheet entirely, especially register description. DIG pins do nothing by default, you need to enable them.

author: kavita
author_rank: Contributor
timestamp: April 11, 2016, 06:32:32 am
content: phyWriteRegister(TRX_CTRL_1_REG,(1<<TX_AUTO_CRC_ON) | (3<<SPI_CMD_MODE) | (1<<IRQ_MASK_MODE)|(1<< PA_EXT_EN) );I have done this setting,connected led to both this pins and initialy led is connected to 3.3V when this pin goes low LED will turn On.Now DIG3 is on when this device is ideal I mean no tx and rx.

author: ataradov
author_rank: Super Contributor
timestamp: April 11, 2016, 06:36:21 am
content: Quote from: kavita on April 11, 2016, 06:32:32 amDIG 3 and DIG4 are complimentary, so if enabled, there are only two states - RX (even if radio is not actually receiving anything or not even in receive mode) and TX (when frame is transmitted). There is no in-between state.

author: kavita
author_rank: Contributor
timestamp: April 11, 2016, 07:07:35 am
content: OK,so if I want that while doing tx LED should on.any extra setting I have to do?

author: ataradov
author_rank: Super Contributor
timestamp: April 11, 2016, 07:10:08 am
content: No, PA_EXT_EN is enough. Keep in mind that TX time of a maximum payload is ~5 ms. You won't see that on an LED with your eyes.

author: kavita
author_rank: Contributor
timestamp: April 11, 2016, 07:18:54 am
content: okk thank you alex..

author: kavita
author_rank: Contributor
timestamp: April 11, 2016, 08:46:42 am
content: how can i set maximum gain?Is it already set to maximum beacuse initially PHY_TX_PWR=0x0.

author: ataradov
author_rank: Super Contributor
timestamp: April 11, 2016, 04:36:11 pm
content: Quote from: kavita on April 11, 2016, 08:46:42 amIt is a bit complicated, since total TX power in 212B is a combination of PA_BOOST, GC_PA and TX_PWR settings.Table 9-15 shows recommended settings based on your location and used modulation scheme.

author: kavita
author_rank: Contributor
timestamp: April 12, 2016, 09:12:06 am
content: hii alex i have started using lwmesh protocol and modified my nwkframe.h like this..this shows sizeof(NwkFrameHeader_t)=0x12andsizeof(NwkFrame_t)=0x94i am sending buffer with 6 elements.is this ok

author: kavita
author_rank: Contributor
timestamp: April 12, 2016, 09:22:17 am
content: I have started working on lwmesh peer to peer example and modify this file like this.i am sending data by using NWK_DataReq(&appDataReq);..my data is {0,1,2,3,4,5}but in PHY_DataReq while writing frame buffer this data does not appear in that frame.physical frame looks{41,88,01,00,67,45,ff,,ff,00,00,06,02,00,00,ff,ff,00,00,02,00,00,00,01,02,00,ff,fc,02}

author: ataradov
author_rank: Super Contributor
timestamp: April 12, 2016, 04:27:16 pm
content: I don't understand what you are doing exactly. There is only a header file attached, no actual code.

author: kavita
author_rank: Contributor
timestamp: April 13, 2016, 09:52:37 am
content: hi alex my problm was packing of structure..i have solved it.now i want to use extended operating mode..I have attached two files in tx i am transmitting one array and in another side receiving that ..but i am not able to receive it in extended mode..I Am not using lwmesh but array is same as created by lwmesh..

author: ataradov
author_rank: Super Contributor
timestamp: April 13, 2016, 10:28:12 pm
content: That's a lot of poorly written code. I'm not going to study that in details. My advice is to use phy.c as is without any modifications and do a proper port to your platform by substituting functions in halPhy.h / halPhy.c.

author: kavita
author_rank: Contributor
timestamp: April 14, 2016, 05:42:14 am
content: hii alexI am transmitting frame...and it is transmited successfullytransmit_buffer={0x41,0x88,0x01,0x67,0x45,0xFF,0xFF,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x11,0x06,0,1,2,3,4,5};0x44,0x88 for broadcast frame control0x01 sequence noOX45,0X67 PAN ID0xff,0xff MAC destination address0x00,0x00 MAC source address0X00 frame control0x01 sequence no0x00 ,0x00 NWK source address0x00,0x01 NWK destination address0x11 source and destination endpoint0x06 no of data0,1,2,3,4,5 actual databut at the receiving end with using RX_AACK I AM NOT RECEIVING ANYTHING..is there any problm in this frame if yes then please correct me..

author: ataradov
author_rank: Super Contributor
timestamp: April 14, 2016, 06:46:15 am
content: Again, I don't know what's wrong with your code because it is unreadable mess. I'm not going to waste my time decoding constructions like "if(reg_read & 0x08)". I have no idea what 0x08 is.Take phy.c as is, make a proper port for your platform by providing functions HAL_PhySpiXXX() and see that this code works.

author: kavita
author_rank: Contributor
timestamp: April 15, 2016, 08:09:37 am
content: hey thanxby using lwmesh I have successfully done peer to peer communication..can u plz tell me what is the purpose of the timers in that code...

author: ataradov
author_rank: Super Contributor
timestamp: April 15, 2016, 04:03:12 pm
content: To create eventQuote from: kavita on April 15, 2016, 08:09:37 amIn what code? Generally timers have descriptive names.

author: kavita
author_rank: Contributor
timestamp: April 18, 2016, 05:55:34 am
content: what happens if i remove all the timers form lwmesh..

author: ataradov
author_rank: Super Contributor
timestamp: April 18, 2016, 06:27:28 am
content: Quote from: kavita on April 18, 2016, 05:55:34 amThis is a strange question. Things will break. What exactly will break depends on the timer, of course.If timers were not needed, they would not be there in a first place.

author: kavita
author_rank: Contributor
timestamp: April 18, 2016, 11:46:02 am
content: yes i got it..i have set appDataReq.options = NWK_OPT_ACK_REQUEST;then how do i know that ack is received...in my code appDataInd(NWK_DataInd_t *ind) is called even if i dont got acknowledgement...

author: ataradov
author_rank: Super Contributor
timestamp: April 18, 2016, 04:00:18 pm
content: appDataInd() is an indication of the received data frame.The fact that ACK was received is indicated though a status code in the confirmation handler you provide as part of the data requests.BTW, all of this is described in the LwMesh documentation.

author: kavita
author_rank: Contributor
timestamp: April 19, 2016, 08:19:11 am
content: but appDataInd is not called at reception of ack...

author: ataradov
author_rank: Super Contributor
timestamp: April 19, 2016, 08:21:06 am
content: Quote from: kavita on April 19, 2016, 08:19:11 amSo what? Reception of an ACK is handled as a part of the data request. So when confirmation callback is called, you know that ACK was either received, or there was a timeout. The status code will tell you which one it is.

author: kavita
author_rank: Contributor
timestamp: April 19, 2016, 11:13:28 am
content: i got it..thank u

author: kavita
author_rank: Contributor
timestamp: April 20, 2016, 11:35:09 am
content: i have a problem.when i continuously transmit form one side and receive on the another the data transfer stops aftr some time...

author: ataradov
author_rank: Super Contributor
timestamp: April 20, 2016, 03:05:43 pm
content: Not enough information. You will have to do some debugging and tell me more if you actually want help and not just complaining.

author: kavita
author_rank: Contributor
timestamp: April 21, 2016, 05:17:01 am
content: I am transmitting data of 100 bytes form one side and after getting callback appdataconf sending another 100 bytes data...this way i am continuously transmitting data.after some time program hangs.i have set controller frequency 25 Mhz.I have enable dynamic frame buffer protection.what happens if i increse NWK_BUFFER_AMOUNT ?

author: ataradov
author_rank: Super Contributor
timestamp: April 21, 2016, 04:06:51 pm
content: Quote from: kavita on April 21, 2016, 05:17:01 amHangs in what state? Confirmation is never returned? Can you publish the code you are using?Quote from: kavita on April 21, 2016, 05:17:01 amWhat's the SPI clock frequency?Quote from: kavita on April 21, 2016, 05:17:01 amStack will work better with large networks.

author: kavita
author_rank: Contributor
timestamp: April 22, 2016, 05:18:47 am
content: it hangs in phyState=PHY_STATE_TX_WAIT_ENDand last transmitted frame state=NWK_TX_STATE_WAIT_CONFafter that no conformation callback is received..my spi clk frequency is 6.25Mhz.moreover i have set data rate 2Mbpswhile (1){sys_TaskHandler();if(flag==0) //initially zero{HAL_UART_Receive_IT(&huart3,&data,5); //uart receiver enableflag=1;}else if(flag==1){if(huart3.RxXferCount==0){flag=2; //if something received from uart}}else if(flag==2){if(ack_flag==0) //first tym it is zero{appSendData(&data1,100); //sending data i have changed this function as belowack_flag=1;}else if(ack_flag==2) //if callback function is called{ack_flag=0;}}void appDataConf(NWK_DataReq_t *req) //this is called after successful transmission{ack_flag=2;(void)req; //this parameter is unused to shut up the warning}void appSendData(uint8_t* tx_data,uint8_t tx_size){appDataReq.dstAddr =0x01;appDataReq.dstEndpoint = APP_ENDPOINT;appDataReq.srcEndpoint = APP_ENDPOINT;appDataReq.options = NWK_OPT_ACK_REQUEST;appDataReq.data = tx_data;appDataReq.size =tx_size;appDataReq.confirm = appDataConf;NWK_DataReq(&appDataReq);}

author: ataradov
author_rank: Super Contributor
timestamp: April 22, 2016, 09:19:39 am
content: Quote from: kavita on April 22, 2016, 05:18:47 amIt looks like a SPI communication issue or your SLP_TR pulse is not wide enough.Quote from: kavita on April 22, 2016, 05:18:47 amHave you verified this in any way? Frequency meter or oscilloscope?Quote from: kavita on April 22, 2016, 05:18:47 amIt should not affect anything here, but I would debug with default settings.

author: kavita
author_rank: Contributor
timestamp: April 22, 2016, 10:11:55 am
content: i have put one variable that counts howmany tym irq status regi gives tx complete.where my program hangs it shows that for the last frame irg status register is not showing any tx complete...

author: ataradov
author_rank: Super Contributor
timestamp: April 22, 2016, 04:30:25 pm
content: You have not answered any of my questions.

author: kavita
author_rank: Contributor
timestamp: April 23, 2016, 06:30:44 am
content: my spi clk frequency is ok..I have increased slp_tr pulse width.but problem is same.how much pulse width is necessary for slp_tr?

author: ataradov
author_rank: Super Contributor
timestamp: April 23, 2016, 06:33:17 am
content: Quote from: kavita on April 23, 2016, 06:30:44 amIt is all in the datasheet.There is no way for me to tell what may be wrong. Read the state register when this happens and check what state the radio is in. This may set a proper direction for debugging.

author: kavita
author_rank: Contributor
timestamp: April 26, 2016, 07:23:15 am
content: hiii am currently using interrupt at physical layer.means phyhandler is in my ieq handler.In my setup i have placed this modules side by side and send them data one by one (when conformation callback of one comes send data to other )at some time when i send data to dome dest addrs like 0x04, other device keep routing but that perticular device is not responding.status regi shows TRAC_STATUS_SUCCESS.is there any deadlock happenes?

author: ataradov
author_rank: Super Contributor
timestamp: April 26, 2016, 07:26:26 am
content: Quote from: kavita on April 26, 2016, 07:23:15 amI have no idea what you just described. You need to be more specific.In general, routing on high level is not directly related to sending individual frames and their status.And what do you mean by "keeps routing"? And what addressed your devices have?

author: kavita
author_rank: Contributor
timestamp: April 26, 2016, 08:36:44 am
content: my devices have addresses like 1,2,3,4,5,6,7.I am sending data from 1 to 2,3,4,5,6,7 continuously one after another.

author: ataradov
author_rank: Super Contributor
timestamp: April 26, 2016, 04:18:21 pm
content: Ok, I'm not going to reply anymore unless you start fully describing what you are doing and write all the observed results. And respond to all my questions.

author: kavita
author_rank: Contributor
timestamp: May 09, 2016, 10:13:44 am
content: ohh that one buffer overflow causes hard fault..i am transmitting data from one device to another.but last byte of data recived if different than data transmitted.i have enabled fcs and frame buffer safe mode