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 ...
随机推荐
- 关于flume配置加载(二)
为什么翻flume的代码,一方面是确实遇到了问题,另一方面是想翻一下flume的源码,看看有什么收获,现在收获还谈不上,因为要继续总结.不够已经够解决问题了,而且确实有好的代码,后续会继续慢慢分享,这 ...
- nginx入门篇----功能特性
1.nginx功能特性 可以作为http服务器或者反向代理服务器 能够快速响应静态页面(html)的请求 支持FastCGI.SSL.Virtual Host.URL Rewrite.HTTP.Gzi ...
- .NET 4.0运行.NET 2.0兼容方法
需要在相同目录下放一个.config文件,例如xxx.exe,就需要一个xxx.exe.config文件,内容如下: <?xml version="1.0"?> < ...
- windows2003 IIS6.0右键属性没有asp.net选项卡的解决办法
windows2003 IIS6.0右键属性没有asp.net选项卡的解决办法 1,如果是只安装了.net framework 1.1 在iis中是不显示那个选项卡的.默认就会支持asp.net1.1 ...
- fuser 命令小结
fuser 概述 fuser命令是用来显示所有正在使用着指定的file, file system 或者 sockets的进程信息. 例一: #fuser –m –u /mnt/usb1 /mnt/us ...
- spring mvc 删除返回字符串中值为null的字段
在spring的配置文件中进行一下配置: <bean class="org.springframework.web.servlet.mvc.method.annotation.Requ ...
- [ActionScript 3.0] 获取随机颜色
import flash.display.MovieClip; import flash.geom.ColorTransform; //方法一 var red:Number = Math.random ...
- d3安装异常
使用npm安装D3,发现其工程名和依赖名重复,导致安装异常 http://thisdavej.com/node-newbie-error-npm-refusing-to-install-package ...
- PSP(11.9~11.16)
14号 类别c 内容c 开始时间s 结束e 中断I 净时间T 看书 设计模式 15:20 17:10 25m 85m 看书 构建执法 19:00 20:10 0m 70m 15号 类别c 内容c 开始 ...
- <2016-1-29>
1.打电话,发短信,发邮件 //打电话 <script> function call(){ var call = new CallManage(); call.call('10086'); ...