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 ...
随机推荐
- [课程设计]Scrum团队分工及明确任务1.0 ----多鱼点餐
[课程设计]Scrum团队分工及明确任务1.0 ----多鱼点餐 一.开发背景 多鱼点餐系统是一套比较系统化的针对餐厅点餐服务的产品,从顾客进入餐厅点餐到用餐结束再到最后的结账买单,需要全面的.高效的 ...
- 【python】遍历类的所有成员
# -*- coding: utf-8 -*- #sharejs.com提供代码,转载请注明出处 class Site(object): def __init__(self): self.title ...
- MyBatis学习(二)、SQL语句映射文件(1)resultMap
二.SQL语句映射文件(1)resultMap SQL 映射XML 文件是所有sql语句放置的地方.需要定义一个workspace,一般定义为对应的接口类的路径.写好SQL语句映射文件后,需要在MyB ...
- Spring事务管理(转)
Spring是SSH中的管理员,负责管理其它框架,协调各个部分的工作.今天一起学习一下Spring的事务管理.Spring的事务管理分为声明式跟编程式.声明式就是在Spring的配置文件中进行相关配置 ...
- TinyHTTP代码核心流程
TinyHTTPd是一个超轻量型Http Server,使用C语言开发,全部代码不到600行 研究HTTP服务器,为了更好的造轮子,看了TinyHTTPd代码,对逻辑处理画个简单流程图(不含底层)
- 对c语言中malloc和free函数的理解
最近在复习c语言的时候再次用到了malloc函数和free函数,此处着讲解一下自己对这两个函数的理解和认识. 一. malloc函数和free函数的基本概念和基本的用法 对于malloc函数: 1. ...
- vue.js组件
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- ld.so.conf 和 ldconfig
1. 查看执行文件的链接库 ldd 例子: # ldd /sbin/sln not a dynamic executable “not a dynamic executable”是 ldd 说明 sl ...
- 分布式ID生成器 zz
简介 这个是根据twitter的snowflake来写的.这里有中文的介绍. 如上图所示,一个64位ID,除了最左边的符号位不用(固定为0,以保证生成的ID都是正数),还剩余63位可用. 下面的代码与 ...
- dbms_output.put_line 不显示
再写oracle sql时候,写循环语句,想知道循环对不对,使用dbms_output.put_line()没有打印出任何东西,网上查找发现少了一句. 加上 set serverouput on 就 ...