Hello,
I am trying to program an application for an S32K311 with continuous reception and transmission using the following functions:
As well as a callback function to receive events of type Lpuart_Uart_Ip_EventType.
I have managed to get the reception part working correctly, but the transmission part is not working as expected.
Could someone explain how the functions dedicated to transmission should be used and ideally provide an example application?
Hello @JorgeSans,
I'm afraid there is no such example.
Can you describe the issue and share you code here?
Thank you,
BR, Daniel
As I haven't been able to find the correct way to use the transmission mode with interrupts without resorting to blocking calls, I am temporarily using them. To prevent the start of a new message transmission before the previous one is finished, I create a lock. However, this is not ideal when the goal is to avoid blocking the application's execution.
What I need is to find an analogous method to the reception process, which works excellently with interrupts.
Any suggestions on how this should be implemented?
#include "SerialFacility.h"
#include <string.h>
#include "cmsis_gcc.h"
extern Queue_t commandQueue;
uint8_t rxCommandBuff[CMD_BUFF_RX] = { 0 };
volatile uint8_t cursor;
void serialFacilityInit( ){
// Initializes an UART driver with interrupt enabled
IntCtrl_Ip_EnableIrq(LPUART3_IRQn);
// Configure UART3 peripheral
Lpuart_Uart_Ip_Init(UART_CHANNEL_3, &Lpuart_Uart_Ip_xHwConfigPB_3);
// Start reception of command in interrupt mode
Lpuart_Uart_Ip_AsyncReceive(UART_CHANNEL_3, rxCommandBuff, 1);
}
void uart3EventCallBack( const uint8 HwInstance, const Lpuart_Uart_Ip_EventType Event, void *UserData ){
if (HwInstance == UART_CHANNEL_3)
{
if(Event == LPUART_UART_IP_EVENT_RX_FULL)
{
// The reception stops when newline is received or the buffer is full
if ( ( rxCommandBuff[cursor] != FRAME_DELIMITER ) && ( cursor != ( CMD_BUFF_RX - 2U ) ) )
{
// Update the buffer index and the rx buffer
cursor++;
Lpuart_Uart_Ip_SetRxBuffer(UART_CHANNEL_3, &rxCommandBuff[cursor],1U);
}
else
{
EnqueuedCommand pendingCmd;
memcpy( ( char* ) pendingCmd.commnddBuff, ( char* ) rxCommandBuff, cursor );
// Adding end of string dekimitator
pendingCmd.commnddBuff[cursor] = '\0';
pendingCmd.commandSize = cursor;
if (!q_isFull(&commandQueue)) {
q_push(&commandQueue, &pendingCmd);
}
cursor = 0;
Lpuart_Uart_Ip_SetRxBuffer(UART_CHANNEL_3,&rxCommandBuff[cursor],1U);
};
}
else if(Event == LPUART_UART_IP_EVENT_END_TRANSFER)
{
// Enable interrupt for again to be able to continue receiving data
Lpuart_Uart_Ip_AsyncReceive( UART_CHANNEL_3, rxCommandBuff, 1 );
}
else if( Event == LPUART_UART_IP_EVENT_END_TRANSFER )
{
// Implementatio here to handl continous trasnmission
}
}
}
void sendMessage( const uint8_t* message )
{
size_t length = strlen( ( char * ) message );
volatile Lpuart_Uart_Ip_StatusType lpuartStatus = LPUART_UART_IP_STATUS_ERROR;
lpuartStatus = Lpuart_Uart_Ip_AsyncSend(UART_CHANNEL_3, message, length);
// Temporaru solution to avoid trasnmitinf a new message before ending current trassmission
uint32_t remainingByte;
do
{
lpuartStatus = Lpuart_Uart_Ip_GetTransmitStatus(UART_CHANNEL_3, &remainingByte);
// Waiting for the transmit to be completed
} while ( remainingByte > 0 );
}