今天分享给大家的是KL26Z的串口通讯程序,通过USB调试口与PC相连,PC发送数据,KL26Z接收后返回相同的数据。
程序不是很复杂,只要配置好串口就可以工作了。
下面是查询法的串口通讯:
- #include "includes.h"
- int main (void)
- {
- SystemCoreClockUpdate(); /* 时钟配置*/
- PORT_ENABLE_CLK(MKL_PORTA); /* GPIO时钟使能 */
- uart0Init(9600,0,0,8,1); /* UART0初始化 */
- while (1) {
- while(UART0_S1_REG(UART0_BASE_PTR) & UART0_S1_RDRF_MASK){ /* 清除中断标志 */
- uart0SendChar(UART0_D_REG(UART0_BASE_PTR)); /* 返回接收数据 */
- }
- }
- }
然后再看中断法的串口通讯:
- #include "includes.h"
- int main (void)
- {
- SystemCoreClockUpdate(); /* 时钟配置*/
- PORT_ENABLE_CLK(MKL_PORTA); /* GPIO时钟使能 */
- uart0Init(9600,0,0,8,1); /* UART0初始化 */
- while (1) {
- }
- }
- }
|