This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: check serial buffer size

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hello everyone,

I'm looking to read a message from the serial buffer off of EUSCIA0. For this scenario, I don't know the length of the message. I would like either to know the length of the message currently on the buffer or check if the buffer is empty before reading the buffer to save the characters. As of now, I cannot find any examples that point in the right direction and have looked in the user guide for the driver library and the closest thing I could find was UART_queryStatusFlags then possibly the flag of EUSCI_A_UART_BUSY. Any help would be appreciated.

Thanks in advance!

Thomas

  • Hi Thomas!

    The hardware buffer holds one single byte, not more. It is up to you to copy the received byte into an input buffer before the next byte is received that would overwrite the existing one.

    Dennis

  • Check this out:

    www.simplyembedded.org/.../

    I did something a little simpler:

    // RX serial stuff
    uint8_t serRxBufAvail(void);
    uint8_t serRxGet(void);
    
    #define SER_RX_BUFSIZE (64) // power of 2
    uint8_t serRxBuf[SER_RX_BUFSIZE];
    
    // ReadIdx pts to next data to be read.
    // WriteIdx pts to next empty space to write.
    volatile uint8_t serRxReadIdx, serRxWriteIdx;
    #define RX_DEFAULT "No Data!"
    #define RX_CLEAR "               " //15 spaces
    
    
    void EUSCIA0_IRQHandler(void) {
    	uint8_t rx;
    
    	uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);
    
    	MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);
    
    	if (status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) {
    		rx = MAP_UART_receiveData(EUSCI_A0_BASE);
    		// Put the data in the ring buffer
    		serRxBuf[serRxWriteIdx++] = rx;
    		serRxWriteIdx =
    				(serRxWriteIdx == SER_RX_BUFSIZE) ? (0) : (serRxWriteIdx);
    
    	} else if (status & EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG) {
    		if (serBufTxIdx == 0)
    			return;
    		if (serTxBuf[serBufTxIdx] == 0) {
    			//done
    			serBufTxIdx = 0;
    		} else {
    			MAP_UART_transmitData(EUSCI_A0_BASE, serTxBuf[serBufTxIdx++]);
    		}
    
    	}
    
    }
    // Probably need to turn off interrupts for some of this.
    
    uint8_t serRxBufAvail(void)
    {
    	if (serRxWriteIdx == serRxReadIdx) {
    		return 0;
    	} else if (serRxWriteIdx - serRxReadIdx > 0) {
    		return (serRxWriteIdx - serRxReadIdx);
    	} else {
    		return (serRxWriteIdx - serRxReadIdx + SER_RX_BUFSIZE);
    	}
    }
    
    uint8_t serRxGet(void)
    {
    	uint8_t ret;
    	if (serRxWriteIdx != serRxReadIdx) {
    		ret = serRxBuf[serRxReadIdx++];
    		serRxReadIdx = (serRxReadIdx == SER_RX_BUFSIZE) ? (0) : (serRxReadIdx);
    	} else {
    		ret = '.';
    	}
    	return ret;
    }
    
    

**Attention** This is a public forum