文章目录
功能简单描述:
功能1 :1秒钟数据包"Hello World!"(没配置阻塞读写)
功能2 :接收啥发送啥(需要特殊的配置,个人理解,有点阻塞的读写方式,但是好像又不是标准的阻塞读写)
原理:简单就是将自定义的FIFO缓存区,读/写到ASCLIN内置的16位FIFO即可。
这里借助串口的中断发送/接收依然可以理解为:和51 32一样,每一位的发送/接收,触发一个中断,(虽然中断函数是调用一个iLLd封装的一个发送/接收函数完成的,让人觉得,好像触发一次中断,调用函数直接一次发送/接收,实际不是的),另外ASCLIN内部有16位的FIFO,然后用户这边定义是64位FIFO,接收/发送中断函数的调用就是,把64位FIFO,写入ASCLIN的16位FIFO,或者读ASCLIN16位FIFO到用户64位FIFO。然后16位的FIFO自动进行收发,这俩算法实现,官方提供的iLLD库以实现,只需要串口发送/接收中断调用即可。
以及功能2发送采用标准的接口配置,否则收到后发送,就会卡死,甚至程序崩溃。
实测是每一位都要触发中断:
主要用到iLLD库里的:
#include "IfxAsclin_Asc.h"
#include "IfxCpu_Irq.h"
#include "Bsp.h" //waitTime
这里注意,
#define UART_PIN_RX IfxAsclin2_RXE_P33_8_IN /* UART receive port pin */
#define UART_PIN_TX IfxAsclin2_TX_P33_9_OUT /* UART transmit port pin */
IfxAsclin_Rx_In IfxAsclin2_RXE_P33_8_IN = {
&MODULE_ASCLIN2, {
&MODULE_P33, 8}, Ifx_RxSel_e};
IfxAsclin_Tx_Out IfxAsclin2_TX_P33_9_OUT = {
&MODULE_ASCLIN2, {
&MODULE_P33, 9}, IfxPort_OutputIdx_alt2};
这里ASCLIN外设模块,还是以&MODULE开头的,只不过是用了宏定义的方式层层包含关系,在#include "IfxAsclin_PinMap.h"里面有定义,本质用到的还是io口作为RX/TX引脚:&MODULE_P33
延时函数使用方法,回看LED章节
功能1
uart.c文件:
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "IfxAsclin_Asc.h"
#include "IfxCpu_Irq.h"
#include "Bsp.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define UART_BAUDRATE 460800 /* UART baud rate in bit/s */
#define UART_PIN_RX IfxAsclin2_RXE_P33_8_IN /* UART receive port pin */
#define UART_PIN_TX IfxAsclin2_TX_P33_9_OUT /* UART transmit port pin */
/* Definition of the interrupt priorities */
#define INTPRIO_ASCLIN2_RX 18
#define INTPRIO_ASCLIN2_TX 19
#define UART_RX_BUFFER_SIZE 64 /* Definition of the receive buffer size */
#define UART_TX_BUFFER_SIZE 64 /* Definition of the transmit buffer size */
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
/* Declaration of the ASC handle */
static IfxAsclin_Asc g_ascHandle;
/* Declaration of the FIFOs parameters */
static uint8 g_ascTxBuffer[UART_TX_BUFFER_SIZE];
static uint8 g_ascRxBuffer[UART_RX_BUFFER_SIZE];
/* Definition of txData and rxData */
uint8 g_txData[] = "Hello World!";
/* Size of the message */
Ifx_SizeT g_count = sizeof(g_txData)-1;
/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
/* Adding of the interrupt service routines */
IFX_INTERRUPT(asclin1TxISR, 0, INTPRIO_ASCLIN2_TX);
void asclin1TxISR(void)
{
IfxAsclin_Asc_isrTransmit(&g_ascHandle);
}
IFX_INTERRUPT(asclin1RxISR, 0, INTPRIO_ASCLIN2_RX);
void asclin1RxISR(void)
{
IfxAsclin_Asc_isrReceive(&g_ascHandle);
}
/* This function initializes the ASCLIN UART module */
void init_ASCLIN_UART(void)
{
/* Initialize an instance of IfxAsclin_Asc_Config with default values */
IfxAsclin_Asc_Config ascConfig;
IfxAsclin_Asc_initModuleConfig(&ascConfig, &MODULE_ASCLIN2);
/* Set the desired baud rate */
ascConfig.baudrate.baudrate = UART_BAUDRATE;
/* ISR priorities and interrupt target */
ascConfig.interrupt.txPriority = INTPRIO_ASCLIN2_TX;
ascConfig.interrupt.rxPriority = INTPRIO_ASCLIN2_RX;
ascConfig.interrupt.typeOfService