Hi again Alexru,
I hope you can help me Alexru.
Here I tried to sent the data of T to the router.
I want the result show in Tera Term but there is nothing happen on Tera Term.
Could you take look my code for while?
Here the code:
/***********************************************************/
Sender Part:
#include <avr/io.h>
#include <asf.h>
#include <util/delay.h>
#include "phy.h"
#include "nwk.h"
#include "config.h"
#include "sys.h"
#include "sysTimer.h"
#define FOSC 8000000
#define BAUD 9600
#define MYBAUD (FOSC/16/BAUD-1)
static uint8_t msg = 'B';
static bool networkStatus;
static NWK_DataReq_t nwkDataReq;
static SYS_Timer_t nwkStatusTimer;
void usart_init (unsigned int ubrr)
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char) ubrr;
/* Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}
void usart_transmit (unsigned char data)
{
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = data;
}
// static void dataConfigure (uint8_t *req)
// {
// if(NWK_SUCCESS_STATUS)
// {
// if(!networkStatus)
// {
// PORTB |= (1<<PINB4);
// SYS_TimerStop(&nwkStatusTimer);
// networkStatus = true;
// }
// }
// else
// {
// if(networkStatus)
// {
// PORTB &= (1<<PINB4);
// SYS_TimerStart(&nwkStatusTimer);
// networkStatus = false;
// }
// }
// }
static void sendFrameData (void)
{
nwkDataReq.dstAddr = 1;
nwkDataReq.dstEndpoint = APP_ENDPOINT;
nwkDataReq.data = &msg;
nwkDataReq.size = sizeof(msg);
nwkDataReq.confirm();
NWK_DataReq(&nwkDataReq);
PORTB ^= (1<<PINB4);
}
static bool dataIndex (NWK_DataInd_t *ind)
{
return true;
NWK_OpenEndpoint(1, dataIndex);
}
static void SendingTaskHandler (void)
{
sendFrameData();
}
static void nwkInit (void)
{
NWK_SetAddr(APP_ADDR);
NWK_SetPanId(0x4321);
PHY_SetChannel(0x0f);
PHY_SetRxState(true);
NWK_OpenEndpoint(APP_ENDPOINT, dataIndex);
}
int main(void)
{
board_init();
DDRB |= (1<<PINB4);
PORTB |= (1<<PINB4);
SYS_Init();
nwkInit();
cli();
usart_init(MYBAUD);
sei();
usart_transmit('K');
while (1)
{
SYS_TaskHandler();
SendingTaskHandler();
}
}
/*****************************************************************/
Receive Part:
#include <avr/io.h>
#include <asf.h>
#include <util/delay.h>
#include "phy.h"
#include "nwk.h"
#include "config.h"
#include "sys.h"
#include "sysTimer.h"
#define FOSC 8000000
#define BAUD 9600
#define MYBAUD (FOSC/16/BAUD-1)
static uint8_t receivedData;
/*static bool acknowledgement = false;*/
static NWK_DataReq_t nwkDataReq;
// static SYS_Timer_t nwkStatusTimer;
static void usart_init (unsigned int ubrr)
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char) ubrr;
/* Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
return UDR0;
}
static bool dataIndex (NWK_DataInd_t *ind)
{
PORTB &= (1<<PINB4);
for(uint8_t i = 0; i<=ind->size; i++)
{
while ( !(UCSR0A & (1<<UDRE0)) );
UDR0 = ind->data[i];
}
return true;
NWK_OpenEndpoint(1, dataIndex);
}
static void receivedFrameData (void)
{
nwkDataReq.srcAddr = 0;
/*nwkDataReq.dstAddr = 0;*/
nwkDataReq.dstEndpoint = APP_ENDPOINT;
nwkDataReq.srcEndpoint = APP_ENDPOINT;
nwkDataReq.data = &receivedData;
nwkDataReq.size = sizeof(receivedData);
PORTB ^= (1<<PINB4);
}
static void receivedInit (void)
{
NWK_SetAddr(APP_ADDR);
NWK_SetPanId(0x4321);
PHY_SetChannel(0x0f);
PHY_SetRxState(true);
NWK_OpenEndpoint(APP_ENDPOINT, dataIndex);
}
int main(void)
{
board_init();
DDRB |= (1<<PINB4);
cli();
usart_init(MYBAUD);
sei();
USART_Receive();
receivedInit();
while (1)
{
SYS_TaskHandler();
receivedFrameData();
}
}