Other Parts Discussed in Thread: PGA460
Hi,
I was looking for answers for this issue but they did not seem to help, therefore will put my own question.
I am working with Tiva C series TM4C123GXL and PGA460 ultrasound sensor, firstly I am just trying to receive some initial messages in order to continue. However, I have encountered an issue that longer messages do not come in full. I tried with FIFO of different sizes and without it, all come to same issue that the message received is incomplete, although looking at oscilloscope, the message does arrive in full (see image bellow). Without FIFO I get 6 bytes of data plus one byte that should not appear when interrupt happens. The very first byte in the RX that is stored is not related to the received message as all messages start with 0x40 but first byte "received" is always 0x00 and second one is 0x40, so I am not sure how to fix this issue either. With FIFO I am not getting whole message either, the amount depends on size for FIFO. I am trying to receive in this case 45 bytes (in general message is not constant size but this one is one of the largest). The code I am using is bellow (adapted from uart_echo.c example, which works). Interrupt is set up in the startup file accordingly.
#include "Additional_libraries/all_includes.h" uint8_t test[3] = {0x55, 0x0B, 0xF4}; uint8_t t[45]; int i =0; void GPIOPinUnlockGPIO(uint32_t ui32Port, uint8_t ui8Pins) { HWREG(ui32Port + GPIO_O_LOCK) = GPIO_LOCK_KEY; // Unlock the port HWREG(ui32Port + GPIO_O_CR) |= ui8Pins; // Unlock the Pin HWREG(ui32Port + GPIO_O_LOCK) = 0; // Lock the port } void UART2IntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = UARTIntStatus(UART2_BASE, true); // // Clear the asserted interrupts. // UARTIntClear(UART2_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // if(ui32Status & UART_INT_RX) { while(UARTCharsAvail(UART2_BASE) && i!=45) { // // Read the next character from the UART and write it back to the UART. // t[i] = UARTCharGetNonBlocking(UART2_BASE); SysCtlDelay(SysCtlClockGet() / (1000 * 3)); i++; } if(i==45) { i=0; } } } //***************************************************************************** // // Send a string to the UART. // //***************************************************************************** void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // ROM_UARTCharPut(UART2_BASE, *pui8Buffer++); } } //***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the peripherals used by this example. // SysCtlPeripheralReset(SYSCTL_PERIPH_UART2); SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlDelay(10); GPIOPinUnlockGPIO(GPIO_PORTD_BASE, GPIO_PIN_7); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PD6_U2RX); GPIOPinConfigure(GPIO_PD7_U2TX); ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); SysCtlDelay(10); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_TWO | UART_CONFIG_PAR_NONE)); SysCtlDelay(10); // // Enable the UART interrupt. // UARTFIFOEnable(UART2_BASE); //UARTFIFOLevelSet(UART2_BASE,UART_FIFO_TX4_8, UART_FIFO_RX4_8); SysCtlDelay(10); UARTIntEnable(UART2_BASE, UART_INT_RX); UARTIntDisable(UART2_BASE, UART_INT_TX); UARTEnable(UART2_BASE); UARTFIFODisable(UART2_BASE); ROM_IntEnable(INT_UART2); // // Prompt for text to be entered. // // // Loop forever echoing data through the UART. // while(1) { UARTSend(test,sizeof(test)); SysCtlDelay(1000000); } }