freetech

kinetis入门之——UART

0
阅读(2942)

1、点“文件->新建->bareboard project”出现下面对话框:

image

为工程起个名字(该示例为k10_uart_pe),点“下一步”,出现:

NU)S1WL}0LB(85~9W5BJVTF

选择你所用的芯片型号即可。点“下一步”,出现:

image

“Connetion to be used”中先选我们先前建好的“USBDM K10X256”,点“下一步”,一直点“下一步”直到出现:

image

选“Processor Export”,点“下一步”,出现:

image

选实际用到的芯片(我用的是144-pins LQFP),点“完成”,出现:

image

等待上面对话框消失,一个工程就建好了。

双击窗口左边的“Communication->Serial_LDD”添加一个“Serial_LDD Bean”,如下图:

image

出现:

image

选“Distinct mode”,点“确定”,出现:

image

上述串口配置完之后还需配置一下时钟,出现乱码等情况是由时钟不准引起的,用外部4MHz晶体谐振器就不会有乱码了。方法如下:

选择“ProcessorExport.pe->Cpus”下面的CPU型号,如下图

image

配置成下面的样子:

image

按上图配置,点“项目”->“Generate Processor Export Code”如下图:

image

下面是参考代码:

ProcessorExpert.c

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "AS1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
volatile bool DataReceivedFlg = FALSE;
char OutData[] = "Hello world";
char InpData[10];
LDD_TError Error;
LDD_TDeviceData *MySerialPtr;

void main(void)
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  MySerialPtr = AS1_Init(NULL);                                     /* Initialization of AS1 component */
  for(;;)
  {
     Error = AS1_SendBlock(MySerialPtr, OutData, sizeof(OutData)); /* Send block of characters */
  }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END ProcessorExpert */