S32K116串口接受

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K116串口接受

1,015 Views
DarrenZhang1
Contributor III

hi

我现在正在调试串口,使用得芯片是S32K116,平台是S32DSFor ARM 最新版本,我通过配置串口设置了串口回调函数,但是在回调函数中接收数据,接受单个数据没有问题,但是发送多个数据给串口,回调函数就再也不进了,这是怎么回事?

0 Kudos
1 Reply

1,010 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@DarrenZhang1

Hi,这是我写的一个S32K142的LPUART测试程序,我刚才看了下,接收多个字节是没有问题的,你可以改成S32K116,这个应该是几乎一样的。你看一下这个可不可以。

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "pin_mux.h"
#include "dmaController1.h"
#include "clockMan1.h"
#include "lpuart1.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
#include <string.h>
#include <stdint.h>
#include <stdbool.h>

/* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

/* Timeout in ms for blocking operations */
#define TIMEOUT     100U

/* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t txBuffer[BUFFER_SIZE];
uint8_t txBufferIdx;

uint8_t rxBuffer[BUFFER_SIZE];
uint8_t rxBufferIdx;

/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
    /* Unused parameters */
    (void)driverState;
    (void)userData;
		uint32_t bytesRemaining;

    /* Check the event type */
    if (event == UART_EVENT_RX_FULL)
    {				
		/* The reception stops when newline is received or the buffer is full */
			if ((rxBuffer[rxBufferIdx] != '\n') && (rxBufferIdx != (BUFFER_SIZE - 2U)))
		 {
				/* Update the buffer index and the rx buffer */
				rxBufferIdx++;
				LPUART_DRV_SetRxBuffer(INST_LPUART1, &rxBuffer[rxBufferIdx], 1U);
		 }
    }
}


void txCallback(void *driverState,uart_event_t event,void * userData)
{
	if(event == UART_EVENT_TX_EMPTY)
	{
		txBufferIdx++;
		LPUART_DRV_SendData(INST_LPUART1,&txBuffer[txBufferIdx],1);
		if(txBufferIdx > BUFFER_SIZE - 1)
		{
			txBufferIdx = 0;
		}
	};
	
	if(event == UART_EVENT_END_TRANSFER)
	{
		;
	};
	
	if(event == UART_EVENT_ERROR)
	{
		;
	};
}

/*!
 \brief The main function for the project.
 \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
 */
int main(void)
{
  /* Write your local variable definition here */
  status_t status;
  /* Declare a buffer used to store the received data */
  uint32_t bytesRemaining;

  CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
  CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

  PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
  
  /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
  /* Install the callback for rx events */
  LPUART_DRV_InstallRxCallback(INST_LPUART1, rxCallback, NULL);
	
	LPUART_DRV_InstallTxCallback(INST_LPUART1, txCallback,NULL);
  /* Send a welcome message */
  LPUART_DRV_SendDataBlocking(INST_LPUART1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);
	
	LPUART_DRV_ReceiveData(INST_LPUART1, rxBuffer, 1U);
	
  while (1)
  {
		OSIF_TimeDelay(100);
		uint8_t test = 12;
		LPUART_DRV_SendData(INST_LPUART1,&test,1);
  }
}

 

0 Kudos