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. Android开发中的输入合法性检验

    Why ? 合法性检查对于程序的健壮性具有重要作用.在Android开发中,良好的合法性检查设计机制可以使程序更加清晰,产生bug更少,交互更加友好. What ? 合法性检查的目的在于确定边界.对于 ...

  2. jsp静态、动态引入其他jsp

    1. <%@ include file="page.jsp"%> /*静态引入,内容必须写成固定值*/    在servlet容器转化jsp为servlet时,将引入的 ...

  3. Xcode 各个版本下载地址

    从Xcode8开始不支持uiautomation了,需要下载老版本的xcode Xcode 的各种版本的下载地址  https://developer.apple.com/download/more/

  4. Oracle10g RAC关闭及启动步骤

    情况1:需要关闭DB(所有实例),OS及Server 停RAC的顺序是: 1)数据库 -〉 2)ASM   -〉 3)CRS a.首先停止Oracle10g环境 $ lsnrctl stop (每个节 ...

  5. SpringMVC实现查询功能

    1 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  6. Windows Server 2008配置服务器证书[转载]

    备忘 http://wangchunhai.blog.51cto.com/225186/139451

  7. [原]JQuery mobile CSS 文件组织

    从 JQuery mobile 1.4 开始, CSS 由3个部分组成,分别是 Icons.Theme和Structure jquery.mobile-1.4.x.css:  包括了 <标准图标 ...

  8. (C++) System return error codes.

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385(v=vs.85).aspx

  9. C# webbrowser实现真正意义上的F5刷新

    关于webbrowser的刷新在C#中有提供方便的方法: webbrowser.refresh(); 但是有时候会发现,不给力啊 那怎么办? 还有一招: webBrowser1.Document.Ex ...

  10. Android Event

    2016-10-11 http://p.codekk.com/detail/Android/wcy10586/androidEvent https://my.oschina.net/u/191330/ ...