I need to have two UART connections on my board, one for the data transmission with a client program, over the USB, and the other one just for sending debugging messages.
I managed to get the UART over USB working, however, using the same code for the second UART doesn't work.
First UART, over the USB, works using LINFLexD_2 (PC8 and PC9 over the micro USB), and also works with different baud rates.
The second UART is set to use LINFlexD_4 (PA5 and PA6), and it doesn't work : I am getting gibberish on the connection. Precisely speaking, instead of ""\nMPC5748G Uart for debugging \n" I am getting this message:
.½Y•U‹»ö.ý«õÚºô› .Úô»ªÚª.Šj.Šú[.
(in hex it is 00 bd 59 95 55 8b bb f6 16 fd ab f5 da ba f4 9b 0a da f4 bb aa da aa 14 8a 6a 1a 8a fa 5b 00 )
What I tried:
- setting different baud rates (using component settings GUI from the SDK)
- using different pins (PC7 and PC6, as LINFlexD_1)
- setting the PA5 and PA6 to "pull up" and enabling PUE (using component settings GUI from the SDK)
- connection the ground of the serial adapter to GND of the board
....none of this worked so far.
I would very much appreciate any help!
I am using the "uart_pal" component.
For the serial connection on my PC, I am using FTDI UC232R USB to serial adapter. Precisely speaking, I am connecting the 2nd pin, "RXD" to the Tx Pin of the LINFex (PA5) of the board, and 3rd pin "TXD" to PA6. Please see the attached screenshot.
Below the code of the application (just for the second UART - the first UART uses almost the same code - only the buffers, references to uart instances and so one are adjusted):
#define UART2_BUFFER_SIZE 128UL
uint8_t buffer_uart2[UART2_BUFFER_SIZE];
uint8_t uart2_bufferIdx;
/* UART rx callback for continuous reception, byte by byte
* Receive and store data byte by byte until new line character is received,
* or the buffer becomes full (128 characters received)
*/
void uartRxCallback2(void *driverState, uart_event_t event, void *userData) {
/* Unused parameters */
(void)driverState;
(void)userData;
/* Check the event type */
if (event == UART_EVENT_RX_FULL)
{
/* The reception stops when newline is received or the buffer is full */
if ((buffer_uart2[uart2_bufferIdx] != '\n') && (uart2_bufferIdx != (UART2_BUFFER_SIZE)))
{
/* Update the buffer index and the rx buffer */
uart2_bufferIdx++;
UART_SetRxBuffer(&uart_pal2_instance, &buffer_uart2[uart2_bufferIdx], 1U);
}
}
}
/* UART hello world task */
void vuartTask_Test2(void* pvParamateres){
uint8_t uart2_msg[] = "\nMPC5748G Uart for debugging \n";
UART_SendDataBlocking(&uart_pal2_instance, (uint8_t *)uart2_msg, strlen(uart2_msg), UART_TIMEOUT);
status_t status;
uint32_t bytesRemaining = 0;
while(1) {
/* Receive and store data byte by byte until new line character is received,
* or the buffer becomes full (128 characters received)
*/
UART_ReceiveData(&uart_pal2_instance, buffer_uart, 1U);
/* Wait for transfer to be completed */
while(UART_GetReceiveStatus(&uart_pal2_instance, &bytesRemaining) == STATUS_BUSY);
/* Check the status */
status = UART_GetReceiveStatus(&uart_pal2_instance, &bytesRemaining);
if (status != STATUS_SUCCESS)
{
/* If an error occurred, send the error message and exit the loop */
//UART_SendDataBlocking(&uart_pal1_instance, (uint8_t *)errorMsg, strlen(errorMsg), TIMEOUT);
break;
}
/* Process end of line in Doc/Window(CRLF) or Unix(LF) */
if (buffer_uart2[uart2_bufferIdx - 1] == '\r')
{
uart2_bufferIdx = uart2_bufferIdx - 1;
/* Replace end of line character with null */
buffer_uart2[uart2_bufferIdx] = 0U;
}
else
{
/* Replace end of line character with null */
buffer_uart2[uart2_bufferIdx] = 0U;
}
/* If the received string is "Hello!", send back "Hello World!" */
if(strcmp((char *) buffer_uart2, "Hello!") == 0)
{
strcpy((char *) buffer_uart2, "Hello World!\n");
}
else
{
buffer_uart2[uart2_bufferIdx] = '\n';
uart2_bufferIdx++;
/* Append string terminator to the received data */
buffer_uart2[uart2_bufferIdx] = 0U;
}
/* Send the received data back */
UART_SendDataBlocking(&uart_pal2_instance, buffer_uart, strlen((char *) buffer_uart), UART_TIMEOUT);
/* Reset the buffer index to start a new reception */
uart2_bufferIdx = 0U;
} //while(1)
}
int main(void)
{
....
/* Initialize and configure clocks */
CLOCK_SYS_Init(g_clockManConfigsArr, (uint8_t)CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, (uint8_t)CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize pins */
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* Initialize UART */
UART_Init(&uart_pal2_instance, &uart_pal2_Config0);
xTaskCreate(vuartTask_Test2, "vuartTask_Test2", 256U, NULL, 3, NULL);
vTaskStartScheduler();
....
}
Solved! Go to Solution.
Thanks for your suggestions however, the problem seems obvious now.
The PINs of the dev board deliver 3.3 V, and my USB UART adapter expected 5V.
I got a different adapter, designed for 3.3V and UART works fine.
Notice for other FTDI chip users - even if the FTDI cable adapters are based on chips that support 3.3V it doesn't necessarily mean that the whole device does. My adapter, UC232R based on the FT232R chip is a good example.
Hi,
I can see no problem on my side. I did quick test using this example:
c:\NXP\S32DS_Power_v2.1\S32DS\software\S32_SDK_S32PA_RTM_3.0.3\examples\MPC5748G\driver_examples\communication\uart_pal_echo\
I just added second uart_pal component and configured LINFlexD_4 instance. Then I configured PA5 and PA6 in pin_mux.
And then I added these tree lines to main.c:
#define welcomeMsg_LINFlex4 "Test from LINFlex4\r\n"
UART_Init(&uart_pal2_instance, &uart_pal2_Config0);
UART_SendDataBlocking(&uart_pal2_instance, (uint8_t *)welcomeMsg_LINFlex4, strlen(welcomeMsg_LINFlex4), TIMEOUT);
No other changes. And it works as expected, I can receive the message on PC via FTDI chip FT2232D.
The project is attached. Maybe you can test the project on your side.
Regards,
Lukas
Thanks for your suggestions however, the problem seems obvious now.
The PINs of the dev board deliver 3.3 V, and my USB UART adapter expected 5V.
I got a different adapter, designed for 3.3V and UART works fine.
Notice for other FTDI chip users - even if the FTDI cable adapters are based on chips that support 3.3V it doesn't necessarily mean that the whole device does. My adapter, UC232R based on the FT232R chip is a good example.