Zstack Serial Communication

Source: Internet
Author: User

Objective: To realize the serial communication between PC and CC2530, select P0-2,p0-3

Function: The PC sends arbitrary string to the microcontroller, the microcontroller then returns the data to the PC computer

First, the execution process: 1. Open the Zmain function, which is the main function of the entire zstack execution
2. Locate to Osal_init_system (); This function is the system initialization function (Zstack embedded in the Osal operating system)
3.go to define of Osal_init_system; open osal.c file, find Osalinittasks (); (Task initialization function) Start the task,
Registration tasks:
Const PTASKEVENTHANDLERFN tasksarr[] = {
Maceventloop,//mac Task Cycle
nwk_event_loop,//Network Layer Task function
hal_processevent,//Hardware layer Functions
#if defined (mt_task)
mt_processevent,//serial port support layer definition
#endif
aps_event_loop,//Application Support Layer Task event function
#if defined (zigbee_fragmentation)
Apsf_processevent,
#endif
zdapp_event_loop,//Device Object layer function
#if defined (zigbee_freq_agility) | | Defined (zigbee_panid_conflict)
Zdnwkmgr_event_loop,
#endif
genericapp_processevent//self-defined task handler function
};

Initialize the task:
void Osalinittasks (void)//Add a task ID for each process to use as a lookup task
{
Uint8 TaskID = 0;

Tasksevents = (UInt16 *) osal_mem_alloc (sizeof (uint16) * taskscnt);
Osal_memset (tasksevents, 0, (sizeof (uint16) * taskscnt));

Mactaskinit (taskid++); task ID number for//MAC layer
Nwk_init (taskid++);//Network ID Assignment
Hal_init (taskid++);//Hardware ID Assignment
#if defined (mt_task)
Mt_taskinit (taskid++);
#endif
Aps_init (taskid++);
#if defined (zigbee_fragmentation)
Apsf_init (taskid++);
#endif
Zdapp_init (taskid++);
#if defined (zigbee_freq_agility) | | Defined (zigbee_panid_conflict)
Zdnwkmgr_init (taskid++);
#endif
Genericapp_init (TaskID);//Add ID for your task
}

The red color of the word is what we need to add
4. New COORDINATOR.C (Coordinator)
Port registration, initialization, task registration, task initialization, serial port initialization
uartconfig.configured = TRUE; 2x30 don ' t care-see UART driver.
Uartconfig.baudrate = hal_uart_br_115200;
Uartconfig.flowcontrol = FALSE;
Uartconfig.flowcontrolthreshold = 64; 2x30 don ' t care-see UART driver.
uartConfig.rx.maxBufSize = 128; 2x30 don ' t care-see UART driver.
uartConfig.tx.maxBufSize = 128; 2x30 don ' t care-see UART driver.
Uartconfig.idletimeout = 6; 2x30 don ' t care-see UART driver.
uartconfig.intenable = TRUE; 2x30 don ' t care-see UART driver.
uartconfig.callbackfunc = RXCB; (Serial receipt function)
Haluartopen (0, &uartconfig);
static void Rxcb (Uint8 port,uint8 event)
{
unsigned char uartbuf[10];
unsigned char len;
Len=haluartread (0,uartbuf,10);
if (len)
{
Haluartwrite (0,uartbuf,len);
len=0;
}
}

5. Implement serial port sending:
Read the data sent by the PC via Haluartread and put it in the Uartbuf
Send data to PC via Haluartread
6. Compile the downloader into CC2530

Zstack Serial Communication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.