在线时间178 小时
UID3096266
注册时间2015-1-27
NXP金币0
TA的每日心情 | 郁闷 2021-3-10 19:44 |
---|
签到天数: 7 天 连续签到: 1 天 [LV.3]偶尔看看II
金牌会员
 
- 积分
- 2018
- 最后登录
- 2023-12-25
|
本帖最后由 MDebug 于 2015-11-8 16:21 编辑
这次我们实现的功能是开发KEA8的串口功能原理图如图所示:
KEA8只有UART0这一个通讯接口,左边和右边都是作为管脚复用出现的,左边的RX,TX分别接A2,A3,右边的RX,TX分别接B0和B1,并且同时加到了J10这个2X3端子上,此端子同时还是lin的接口。
代码部分:
PIT定时器:
PIT定时器是Freescale板载的定时器,当到达设定阈值的时候PIT会产生PIT中断。
- #include "SKEAZN84.h"
- #include "delay.h"
- #include "kea8_gpio.h"
- #include "kea8_uart.h"
- #include "stdio.h"
- #include "kea8_pit.h"
- void UART_Cfg(void)
- {
- UART_InitTypeDef UART_InitStructure;
- UART_InitStructure.UART_BaudRate=9600;
- UART_InitStructure.UART_Mode=UART_Mode_Rx|UART_Mode_Tx;
- UART_InitStructure.UART_Parity=UART_Parity_No;
- UART_InitStructure.UART_PIN= RX_PTB0_TX_PTB1;
- UART_InitStructure.UART_StopBits=UART_StopBits_1;
- UART_InitStructure.UART_WordLength=UART_WordLength_8b;
- UART_Init(&UART_InitStructure);
- UART_ITConfig(UART_IT_RXNE,ENABLE);
- NVIC_Init(UART0_IRQn,ENABLE);
- }
- void PIT_Cfg(void)
- {
- PIT_InitTypeDef PIT_InitStructure;
- PIT_InitStructure.PIT_Mode=PIT_Mode_ms;
- PIT_InitStructure.Timer=1000;
- PIT_InitStructure.CHANNELx=PIT_CHANNEL0;
- PIT_Init(&PIT_InitStructure);
- PIT_ITConfig(PIT_CHANNEL0,ENABLE);
- PIT_ClearFlag(PIT_CHANNEL0);
- PIT_Cmd(PIT_CHANNEL0,ENABLE);
- NVIC_Init(PIT_CH0_IRQn, ENABLE);
- }
- void GPIO_Cfg(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIOx=PTC;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Pin=PTA2|PTA3;
- GPIO_InitStructure.GPIO_InitState=Bit_RESET;
- GPIO_Init(&GPIO_InitStructure);
-
- }
- int main()
- {
- SystemCoreClockUpdate();//
- UART_Cfg();
- PIT_Cfg();
- GPIO_Cfg();
- delay_ms(1);//
- for(;;)
- printf("My KEA-8 UART Program by MDebug");
- }
复制代码 PIT中断处理:- void PIT_CH0_IRQHandler()
- {
- static u32 i=0;
- PIT_ClearFlag(PIT_CHANNEL0); //
- i++;
- printf("PIT Interrupt:%d\r\n",i);
- }
复制代码 库函数非常好理解,风格就是类比于STM32官方固件库。接收数据部分:
|
评分
-
查看全部评分
|