PIC32MZ tutorial -- UART Communication
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的更多相关文章
- PIC32MZ tutorial -- OC Interrupt
In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...
- PIC32MZ tutorial -- External Interrupt
In my older blog "PIC32MZ tutorial -- Key Debounce", I shows how to acheive key debounce w ...
- PIC32MZ tutorial -- Watchdog Timer
Watchdog is a very necessary module for embedded system. Someone said that embedded system operates ...
- PIC32MZ tutorial -- Output Compare
Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...
- PIC32MZ tutorial -- Input Capture
Today I accomplish a simple application for PIC32MZ EC Starter Kit. This application uses Input Capt ...
- PIC32MZ tutorial -- 32-bit Timer
The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...
- PIC32MZ tutorial -- Change Notification
In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...
- PIC32MZ tutorial -- Key Debounce
Today I accomplish a application on PIC32MZ EC Starter Kit. The feature of application is to light u ...
- PIC32MZ tutorial -- Timer Interrupt
An interrupt is an internal or external event that requires quick attention from the controller. The ...
随机推荐
- 如何导出和导入mysql数据(数据迁移)
. 导出数据库数据 mysqldump -uroot -p dp_db > dumpout.sql 其中 root是账户名 dp_db是需要导出的数据库名称 dumpout.sql存储导出的数据 ...
- Centos6---Fail2ban
1.安装: rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm yum -y install ...
- consul 安装
1. linux 下consul 安装 首先查看机器信息: uname -a Linux centos-linux.shared 3.10.0-327.el7.x86_64 #1 SMP Thu No ...
- 【转】关于启用 HTTPS 的一些经验分享
随着国内网络环境的持续恶化,各种篡改和劫持层出不穷,越来越多的网站选择了全站 HTTPS.HTTPS 通过 TLS 层和证书机制提供了内容加密.身份认证和数据完整性三大功能,可以有效防止数据被查看或篡 ...
- Linux入侵检查思路及其命令 转自https://yq.aliyun.com/articles/24250?spm=5176.100239.blogcont24249.12.rbBrIh
摘要: 若Linux操作系统被非法入侵,那么有哪些思路和系统命令用于检查系统当前的状态呢?主要包括对关键进程.关键服务.关键文件的检测,同时及时备份硬盘数据用于持续分析.详细的检查思路和Linux命令 ...
- 使用C#/.net语言进行ProE/Creo二次开发
随便哪个版本的Visual studio 设置系统环境变量 通常这个环境变量在安装ProE的时候如果选择安装VBAPI就会自动设置 注意32位和64位操作系统路径是不同的.我的是64位操作系统. 然后 ...
- SOAOffice和iWebOffice、NTKO的比较及其优势(转)
http://www.cnblogs.com/liping13599168/articles/1681465.html SOAOffice和iWebOffice.NTKO的比较及其优势 近年来,市场上 ...
- win 8 安装 NET framework3.5 方法
win 8 预装的 NET framework 是 4.5 的,实际上很多程序要求的是 3.5,一般要另从网上下载的才能安装. 这里提供不需要从网上安装 .Net 3.5 的方法: 1.将 win 8 ...
- storm基础系列之五---------接入数据收集系统flume
1.基本结构介绍 flume是三层架构,agent,collector,storage.每一层都可水平扩展. 其中,agent就是数据采集方:collector是数据整合方:storage是各种数据落 ...
- Tomcat启动报错 Could not reserve enough space for object heap
报错信息: Error occurred during initialization of VM Could not reserve enough space for object heap Coul ...