At this moment, I accomplish the interface of UART communication for PIC32MZ EC Starter Kit. This interface configures the PIC32MZ for communication with a host PC at 115200 baud. There are five functions in the interface -- Uart_Init(), Uart_Getc(), Uart_Gets(), Uart_Putc() and Uart_Puts().

  Uart_Init() configures PIC32MZ UART1 with 115200-8-None-1. It uses PPS to select RPC13, RPC14 as TX and RX.

Uart_Getc() is a reception funtion for a character. It will be blocked until a character got.

  Uart_Gets() is a reception funtion for string. It will receive multiple characters until the '\r' '\n' or the buffer is full.

  Uart_Putc() is a transmit function for a character.

Uart_Puts() is a transmit funtion for string. It will transmit multiple character until '\0'.

  Below is the code.

void Uart_Init(void)
{
LATCSET = 0x6000; /* Both RC13 and RC14 HIGH */
TRISCSET = 0x4000; /* RC14 Input */
TRISCCLR = 0x2000; /* RC13 Output */ Seq_UnLock();
RPC13Rbits.RPC13R = ; /* U1TX on RPC13 */
U1RXRbits.U1RXR = ; /* U1RX on RPC14 */
Seq_Lock(); U1BRG = ((PBCLK2_FREQUENCY / BAUDRATE) / ) - ;
U1MODE = 0x8000; // Loopback mode is enabled
U1STA = 0x1400; IFS3bits.U1RXIF = ;
IFS3bits.U1TXIF = ;
} char Uart_Getc(void)
{
if (U1STAbits.OERR)
{
U1STAbits.OERR = ;
return ;
}
while (!U1STAbits.URXDA);
char ret = U1RXREG;
IFS3bits.U1RXIF = ;
return ret;
} void Uart_Gets(char *s)
{
char c;
int size = ;
if (s == (void *)) return;
while (size < U1RX_BUFSIZE)
{
c = Uart_Getc();
if ((c == '\n')||(c == '\r'))
{
s[size] = '\0';
break;
}
s[size++] = c;
}
} void Uart_Putc(char c)
{
U1TXREG = c;
while (U1STAbits.UTXBF);
IFS3bits.U1TXIF = ;
} void Uart_Puts(char *s)
{
if (s == (void *))
{
return;
}
while (*s != '\0')
{
Uart_Putc(*s++);
}
}

  

PIC32MZ tutorial -- UART Communication的更多相关文章

  1. PIC32MZ tutorial -- OC Interrupt

    In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...

  2. PIC32MZ tutorial -- External Interrupt

    In my older blog "PIC32MZ tutorial -- Key Debounce", I shows how to acheive key debounce w ...

  3. PIC32MZ tutorial -- Watchdog Timer

    Watchdog is a very necessary module for embedded system. Someone said that embedded system operates ...

  4. PIC32MZ tutorial -- Output Compare

    Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...

  5. PIC32MZ tutorial -- Input Capture

    Today I accomplish a simple application for PIC32MZ EC Starter Kit. This application uses Input Capt ...

  6. PIC32MZ tutorial -- 32-bit Timer

    The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...

  7. PIC32MZ tutorial -- Change Notification

    In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...

  8. PIC32MZ tutorial -- Key Debounce

    Today I accomplish a application on PIC32MZ EC Starter Kit. The feature of application is to light u ...

  9. PIC32MZ tutorial -- Timer Interrupt

    An interrupt is an internal or external event that requires quick attention from the controller. The ...

随机推荐

  1. python小知识点

    问题:求列表中每个元素的元素次方之和>>> a=[1,2,3,4]>>> k=len(a)第一种解法#    s=0#    for x in a:#        ...

  2. k8s DNS 服务发现的一个坑

    按照官当文档,以及大家的实践进行k8s dns 服务发现搭建还是比较简单的,但是会有一个因为系统默认dns 配置造成的一个问题 1. linux  默认dns 配置在 /etc/resolv.conf ...

  3. 错误: 程序包com.sun.istack.internal不存在

    eclipse下maven打包是出现如下错误: [ERROR] D:\code-old\daba_user_mvn\src\main\java\com\dada\transaction\service ...

  4. 读取其他软件listview控件的内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. cPage分页源码,分享给大家,可作参考

    cPage是asp.net分页控件,也可以叫做分页组件,更确切的应该叫做分页模块,也或者叫做分页通用代码. cPage,版本3.2,源码如下: using System; namespace cPag ...

  6. webstorm(注册,激活,破解,码,一起支持正版,最新可用)(2016.9.2更新)

    webstorm(注册,激活,破解,码,一起支持正版,最新可用)(2016.9.2更新)   来源于:http://blog.csdn.net/xx1710/article/details/51725 ...

  7. animated js动画示例

    function fabtn(a){ $(a).find('i').addClass('animated wobble'); setTimeout(function(){ $(a).find('i') ...

  8. 关于delegate(代理)总结

    stackoverflow  上讲解:http://stackoverflow.com/a/12660523/4563358 delegate是将需要处理交给自己的代理. 在自己的对应的类中.h文件中 ...

  9. dubbo工作原理

    part -- 外挂1.dubbo借助spring的schema启动和初始化 1.1 spring扫描所有jar下META-INF的spring.handlers和spring.schemas. 1. ...

  10. 如何将Debug文件夹下的资源打包成一个EXE文件直接执行

    前言:前段时间写了个小程序,想分享给好友看看,可所以资源都放在Debug文件夹下,整个文件夹发给人家这也太……,为了显得稍微专业一点,想把它们打包一个EXE文件执行,因为我见到到这样的程序,直接一个E ...